@skmtc/core 0.0.783 → 0.0.786

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. package/esm/dsl/File.d.ts +208 -0
  2. package/esm/dsl/File.d.ts.map +1 -1
  3. package/esm/dsl/File.js +197 -0
  4. package/esm/dsl/Identifier.d.ts +152 -0
  5. package/esm/dsl/Identifier.d.ts.map +1 -1
  6. package/esm/dsl/Identifier.js +152 -0
  7. package/esm/dsl/Import.d.ts +221 -0
  8. package/esm/dsl/Import.d.ts.map +1 -1
  9. package/esm/dsl/Import.js +202 -0
  10. package/esm/dsl/model/ModelBase.d.ts +257 -0
  11. package/esm/dsl/model/ModelBase.d.ts.map +1 -1
  12. package/esm/dsl/model/ModelBase.js +248 -0
  13. package/esm/dsl/operation/OperationBase.d.ts +356 -1
  14. package/esm/dsl/operation/OperationBase.d.ts.map +1 -1
  15. package/esm/dsl/operation/OperationBase.js +347 -1
  16. package/esm/oas/document/Document.d.ts +155 -1
  17. package/esm/oas/document/Document.d.ts.map +1 -1
  18. package/esm/oas/document/Document.js +141 -2
  19. package/esm/oas/object/Object.d.ts +255 -10
  20. package/esm/oas/object/Object.d.ts.map +1 -1
  21. package/esm/oas/object/Object.js +229 -10
  22. package/esm/types/GeneratorKeys.d.ts +336 -0
  23. package/esm/types/GeneratorKeys.d.ts.map +1 -1
  24. package/esm/types/GeneratorKeys.js +243 -0
  25. package/esm/types/GeneratorType.d.ts +119 -0
  26. package/esm/types/GeneratorType.d.ts.map +1 -1
  27. package/esm/types/Method.d.ts +109 -0
  28. package/esm/types/Method.d.ts.map +1 -1
  29. package/esm/types/Method.js +84 -0
  30. package/package.json +5 -1
  31. package/script/dsl/File.d.ts +208 -0
  32. package/script/dsl/File.d.ts.map +1 -1
  33. package/script/dsl/File.js +197 -0
  34. package/script/dsl/Identifier.d.ts +152 -0
  35. package/script/dsl/Identifier.d.ts.map +1 -1
  36. package/script/dsl/Identifier.js +152 -0
  37. package/script/dsl/Import.d.ts +221 -0
  38. package/script/dsl/Import.d.ts.map +1 -1
  39. package/script/dsl/Import.js +202 -0
  40. package/script/dsl/model/ModelBase.d.ts +257 -0
  41. package/script/dsl/model/ModelBase.d.ts.map +1 -1
  42. package/script/dsl/model/ModelBase.js +248 -0
  43. package/script/dsl/operation/OperationBase.d.ts +356 -1
  44. package/script/dsl/operation/OperationBase.d.ts.map +1 -1
  45. package/script/dsl/operation/OperationBase.js +347 -1
  46. package/script/oas/document/Document.d.ts +155 -1
  47. package/script/oas/document/Document.d.ts.map +1 -1
  48. package/script/oas/document/Document.js +141 -2
  49. package/script/oas/object/Object.d.ts +255 -10
  50. package/script/oas/object/Object.d.ts.map +1 -1
  51. package/script/oas/object/Object.js +229 -10
  52. package/script/types/GeneratorKeys.d.ts +336 -0
  53. package/script/types/GeneratorKeys.d.ts.map +1 -1
  54. package/script/types/GeneratorKeys.js +243 -0
  55. package/script/types/GeneratorType.d.ts +119 -0
  56. package/script/types/GeneratorType.d.ts.map +1 -1
  57. package/script/types/Method.d.ts +109 -0
  58. package/script/types/Method.d.ts.map +1 -1
  59. package/script/types/Method.js +84 -0
@@ -2,21 +2,150 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.OperationBase = void 0;
4
4
  const ContentBase_js_1 = require("../ContentBase.js");
5
+ /**
6
+ * Base class for operation generators in the SKMTC DSL system.
7
+ *
8
+ * `OperationBase` extends {@link ContentBase} to provide specialized functionality for
9
+ * generating code from OpenAPI operations. It offers type-safe methods for inserting
10
+ * related operations and models, managing complex operation dependencies, and handling
11
+ * enrichments specific to API operations.
12
+ *
13
+ * This class serves as the foundation for creating custom operation generators that
14
+ * transform OpenAPI operations into various code artifacts like API clients, server
15
+ * handlers, validation middleware, or documentation.
16
+ *
17
+ * ## Key Features
18
+ *
19
+ * - **Operation Insertion**: Insert related operations with automatic dependency tracking
20
+ * - **Model Integration**: Seamlessly insert related models from operation schemas
21
+ * - **Schema Normalization**: Handle complex request/response schema references
22
+ * - **Export Management**: Control which operations are exported from generated files
23
+ * - **Enrichment Support**: Extend functionality with operation-specific enrichment data
24
+ * - **Type Safety**: Full TypeScript support with generic enrichment types
25
+ *
26
+ * @template EnrichmentType - Optional type for custom enrichment data
27
+ *
28
+ * @example Basic API client generator
29
+ * ```typescript
30
+ * import { OperationBase, Definition } from '@skmtc/core';
31
+ *
32
+ * class ApiClientMethod extends OperationBase {
33
+ * toDefinition(): Definition {
34
+ * const { method, path, operationId } = this.operation;
35
+ *
36
+ * return new Definition({
37
+ * name: operationId || `${method}${this.pascalCasePath()}`,
38
+ * content: `async ${operationId}(${this.generateParameters()}) {
39
+ * return this.request('${method}', '${path}', ${this.generateRequestBody()});
40
+ * }`
41
+ * });
42
+ * }
43
+ * }
44
+ * ```
45
+ *
46
+ * @example With request/response models
47
+ * ```typescript
48
+ * class TypedApiMethod extends OperationBase {
49
+ * toDefinition(): Definition {
50
+ * const operation = this.operation;
51
+ *
52
+ * // Generate request model if needed
53
+ * let requestType = 'void';
54
+ * if (operation.requestBody?.content?.['application/json']?.schema) {
55
+ * const requestModel = this.insertNormalizedModel(
56
+ * new RequestModel({ ... }),
57
+ * {
58
+ * schema: operation.requestBody.content['application/json'].schema,
59
+ * fallbackName: `${operation.operationId}Request`
60
+ * }
61
+ * );
62
+ * requestType = requestModel.value;
63
+ * }
64
+ *
65
+ * // Generate response model
66
+ * const responseSchema = operation.responses?.['200']?.content?.['application/json']?.schema;
67
+ * const responseModel = this.insertNormalizedModel(
68
+ * new ResponseModel({ ... }),
69
+ * { schema: responseSchema, fallbackName: `${operation.operationId}Response` }
70
+ * );
71
+ *
72
+ * return new Definition({
73
+ * name: operation.operationId,
74
+ * content: `async ${operation.operationId}(data: ${requestType}): Promise<${responseModel.value}> {
75
+ * return this.request('${operation.method}', '${operation.path}', data);
76
+ * }`
77
+ * });
78
+ * }
79
+ * }
80
+ * ```
81
+ *
82
+ * @example With enrichments
83
+ * ```typescript
84
+ * type AuthEnrichment = {
85
+ * requiresAuth: boolean;
86
+ * permissions: string[];
87
+ * };
88
+ *
89
+ * class SecuredApiMethod extends OperationBase<AuthEnrichment> {
90
+ * toDefinition(): Definition {
91
+ * const enrichment = this.settings.enrichment;
92
+ * const requiresAuth = enrichment?.requiresAuth ?? false;
93
+ *
94
+ * const authCheck = requiresAuth
95
+ * ? 'this.checkAuth();'
96
+ * : '';
97
+ *
98
+ * return new Definition({
99
+ * name: this.operation.operationId,
100
+ * content: `async ${this.operation.operationId}() {
101
+ * ${authCheck}
102
+ * return this.request('${this.operation.method}', '${this.operation.path}');
103
+ * }`
104
+ * });
105
+ * }
106
+ * }
107
+ * ```
108
+ */
5
109
  class OperationBase extends ContentBase_js_1.ContentBase {
110
+ /**
111
+ * Creates a new OperationBase instance.
112
+ *
113
+ * @param args - Operation generator configuration
114
+ * @param args.context - The generation context providing pipeline access
115
+ * @param args.settings - Content settings with export path and enrichments
116
+ * @param args.generatorKey - Unique identifier for this generator type
117
+ * @param args.operation - The OpenAPI operation being processed
118
+ *
119
+ * @example
120
+ * ```typescript
121
+ * const operation = new OperationBase({
122
+ * context: generateContext,
123
+ * settings: {
124
+ * exportPath: './src/api.ts',
125
+ * enrichment: customEnrichments
126
+ * },
127
+ * generatorKey: 'api-client',
128
+ * operation: oasOperation
129
+ * });
130
+ * ```
131
+ */
6
132
  constructor({ context, generatorKey, settings, operation }) {
7
133
  super({ context });
134
+ /** Content settings including export path and enrichment configuration */
8
135
  Object.defineProperty(this, "settings", {
9
136
  enumerable: true,
10
137
  configurable: true,
11
138
  writable: true,
12
139
  value: void 0
13
140
  });
141
+ /** The OpenAPI operation being processed */
14
142
  Object.defineProperty(this, "operation", {
15
143
  enumerable: true,
16
144
  configurable: true,
17
145
  writable: true,
18
146
  value: void 0
19
147
  });
148
+ /** Generator key identifying this generator type */
20
149
  Object.defineProperty(this, "generatorKey", {
21
150
  enumerable: true,
22
151
  configurable: true,
@@ -27,6 +156,43 @@ class OperationBase extends ContentBase_js_1.ContentBase {
27
156
  this.operation = operation;
28
157
  this.settings = settings;
29
158
  }
159
+ /**
160
+ * Inserts a related operation with forced generation.
161
+ *
162
+ * This method adds a related operation to the current generation context, ensuring
163
+ * it will be generated regardless of whether it already exists. This is useful for
164
+ * operations that depend on other operations or need to generate helper operations.
165
+ *
166
+ * @template V - Type of generated value returned by the insertable
167
+ * @template EnrichmentType - Type of enrichment data for the insertable
168
+ * @param insertable - The operation generator to insert
169
+ * @param operation - The OpenAPI operation to process
170
+ * @param options - Insertion options
171
+ * @param options.noExport - Whether to skip exporting the inserted operation
172
+ * @returns Inserted operation reference with generated value
173
+ *
174
+ * @example Inserting helper operations
175
+ * ```typescript
176
+ * class CrudApiClient extends OperationBase {
177
+ * toDefinition(): Definition {
178
+ * // Insert a related validation operation
179
+ * const validator = this.insertOperation(
180
+ * new ValidationOperation({ ... }),
181
+ * this.operation,
182
+ * { noExport: true }
183
+ * );
184
+ *
185
+ * return new Definition({
186
+ * name: this.operation.operationId,
187
+ * content: `async ${this.operation.operationId}(data: any) {
188
+ * ${validator.value}(data);
189
+ * return this.request('${this.operation.method}', '${this.operation.path}', data);
190
+ * }`
191
+ * });
192
+ * }
193
+ * }
194
+ * ```
195
+ */
30
196
  insertOperation(insertable, operation, options = {}) {
31
197
  return this.context.insertOperation(insertable, operation, {
32
198
  generation: 'force',
@@ -34,6 +200,47 @@ class OperationBase extends ContentBase_js_1.ContentBase {
34
200
  noExport: options.noExport
35
201
  });
36
202
  }
203
+ /**
204
+ * Inserts a related model with forced generation.
205
+ *
206
+ * This method adds a model to the current generation context, typically used
207
+ * for request/response models or other types related to the operation. The model
208
+ * will be generated and can be referenced in the operation code.
209
+ *
210
+ * @template V - Type of generated value returned by the insertable
211
+ * @template EnrichmentType - Type of enrichment data for the insertable
212
+ * @param insertable - The model generator to insert
213
+ * @param refName - Reference name for the inserted model
214
+ * @param options - Insertion options
215
+ * @param options.noExport - Whether to skip exporting the inserted model
216
+ * @returns Inserted model reference with generated value
217
+ *
218
+ * @example Inserting request/response models
219
+ * ```typescript
220
+ * class ApiOperation extends OperationBase {
221
+ * toDefinition(): Definition {
222
+ * // Insert request model
223
+ * const requestModel = this.insertModel(
224
+ * new RequestModel({ ... }),
225
+ * 'CreateUserRequest'
226
+ * );
227
+ *
228
+ * // Insert response model
229
+ * const responseModel = this.insertModel(
230
+ * new ResponseModel({ ... }),
231
+ * 'CreateUserResponse'
232
+ * );
233
+ *
234
+ * return new Definition({
235
+ * name: this.operation.operationId,
236
+ * content: `async ${this.operation.operationId}(data: ${requestModel.value}): Promise<${responseModel.value}> {
237
+ * return this.request('${this.operation.method}', '${this.operation.path}', data);
238
+ * }`
239
+ * });
240
+ * }
241
+ * }
242
+ * ```
243
+ */
37
244
  insertModel(insertable, refName, options = {}) {
38
245
  return this.context.insertModel(insertable, refName, {
39
246
  generation: 'force',
@@ -41,6 +248,62 @@ class OperationBase extends ContentBase_js_1.ContentBase {
41
248
  noExport: options.noExport
42
249
  });
43
250
  }
251
+ /**
252
+ * Inserts a related model with automatic schema normalization and reference resolution.
253
+ *
254
+ * This method intelligently handles schema references from operation request/response
255
+ * bodies, automatically resolving schema references to appropriate model names.
256
+ * This is particularly useful for operations with complex request/response schemas.
257
+ *
258
+ * @template V - Type of generated value returned by the insertable
259
+ * @template Schema - Type of OpenAPI schema (schema object, reference, or void)
260
+ * @template EnrichmentType - Type of enrichment data for the insertable
261
+ * @param insertable - The model generator to insert
262
+ * @param args - Schema normalization arguments
263
+ * @param args.schema - The OpenAPI schema to normalize (from request/response)
264
+ * @param args.fallbackName - Name to use if schema is not a reference
265
+ * @param options - Insertion options
266
+ * @param options.noExport - Whether to skip exporting the inserted model
267
+ * @returns Inserted model reference with normalized name and generated value
268
+ *
269
+ * @example Handling operation request/response schemas
270
+ * ```typescript
271
+ * class RestApiOperation extends OperationBase {
272
+ * toDefinition(): Definition {
273
+ * const operation = this.operation;
274
+ *
275
+ * // Handle request body schema
276
+ * let requestType = 'void';
277
+ * const requestSchema = operation.requestBody?.content?.['application/json']?.schema;
278
+ * if (requestSchema) {
279
+ * const requestModel = this.insertNormalizedModel(
280
+ * new TypeScriptInterface({ ... }),
281
+ * {
282
+ * schema: requestSchema,
283
+ * fallbackName: `${operation.operationId}Request`
284
+ * }
285
+ * );
286
+ * requestType = requestModel.value;
287
+ * }
288
+ *
289
+ * // Handle response schema
290
+ * const responseSchema = operation.responses?.['200']?.content?.['application/json']?.schema;
291
+ * const responseModel = this.insertNormalizedModel(
292
+ * new TypeScriptInterface({ ... }),
293
+ * {
294
+ * schema: responseSchema,
295
+ * fallbackName: `${operation.operationId}Response`
296
+ * }
297
+ * );
298
+ *
299
+ * return new Definition({
300
+ * name: operation.operationId,
301
+ * content: `async ${operation.operationId}(data: ${requestType}): Promise<${responseModel.value}>`
302
+ * });
303
+ * }
304
+ * }
305
+ * ```
306
+ */
44
307
  insertNormalizedModel(insertable, { schema, fallbackName }, options = {}) {
45
308
  return this.context.insertNormalisedModel(insertable, {
46
309
  schema,
@@ -48,7 +311,43 @@ class OperationBase extends ContentBase_js_1.ContentBase {
48
311
  destinationPath: this.settings.exportPath
49
312
  }, options);
50
313
  }
51
- /** @experimental */
314
+ /**
315
+ * Defines and registers a new definition in the generation context.
316
+ *
317
+ * This is an experimental method that allows creating and registering
318
+ * definitions directly without going through the standard insertion flow.
319
+ * Use with caution as the API may change in future versions.
320
+ *
321
+ * @experimental This method's API may change in future versions
322
+ * @template V - Type of generated value
323
+ * @param args - Definition arguments
324
+ * @param args.identifier - Unique identifier for the definition
325
+ * @param args.value - The generated value to associate with the definition
326
+ * @param args.noExport - Whether to skip exporting the definition
327
+ * @returns The created and registered definition
328
+ *
329
+ * @example Creating inline definitions
330
+ * ```typescript
331
+ * class InlineHelperOperation extends OperationBase {
332
+ * toDefinition(): Definition {
333
+ * // Create an inline helper function
334
+ * const helper = this.defineAndRegister({
335
+ * identifier: 'validateRequest',
336
+ * value: 'function validateRequest(data: any) { ... }',
337
+ * noExport: true
338
+ * });
339
+ *
340
+ * return new Definition({
341
+ * name: this.operation.operationId,
342
+ * content: `async ${this.operation.operationId}(data: any) {
343
+ * ${helper.value}(data);
344
+ * return this.request('${this.operation.method}', '${this.operation.path}', data);
345
+ * }`
346
+ * });
347
+ * }
348
+ * }
349
+ * ```
350
+ */
52
351
  defineAndRegister({ identifier, value, noExport }) {
53
352
  return this.context.defineAndRegister({
54
353
  identifier,
@@ -57,6 +356,53 @@ class OperationBase extends ContentBase_js_1.ContentBase {
57
356
  noExport
58
357
  });
59
358
  }
359
+ /**
360
+ * Registers a file-level artifact with the generation context.
361
+ *
362
+ * This method allows the operation generator to register additional content
363
+ * (like imports, exports, or file-level definitions) that should be included
364
+ * in the generated file. The registration is automatically scoped to this
365
+ * operation's export path.
366
+ *
367
+ * @param args - Registration arguments
368
+ * @param args.content - The content to register (import, export, etc.)
369
+ * @param args.phase - When to register the content ('pre' or 'post')
370
+ *
371
+ * @example Registering API client imports
372
+ * ```typescript
373
+ * class HttpOperation extends OperationBase {
374
+ * toDefinition(): Definition {
375
+ * // Register imports needed for HTTP operations
376
+ * this.register({
377
+ * content: "import { ApiClient } from './client';",
378
+ * phase: 'pre'
379
+ * });
380
+ *
381
+ * this.register({
382
+ * content: "import { RequestOptions } from './types';",
383
+ * phase: 'pre'
384
+ * });
385
+ *
386
+ * return new Definition({ ... });
387
+ * }
388
+ * }
389
+ * ```
390
+ *
391
+ * @example Registering utility exports
392
+ * ```typescript
393
+ * class ApiOperationGroup extends OperationBase {
394
+ * toDefinition(): Definition {
395
+ * // Register a utility export after all operations
396
+ * this.register({
397
+ * content: "export const API_VERSION = '1.0';",
398
+ * phase: 'post'
399
+ * });
400
+ *
401
+ * return new Definition({ ... });
402
+ * }
403
+ * }
404
+ * ```
405
+ */
60
406
  register(args) {
61
407
  this.context.register({
62
408
  ...args,
@@ -8,23 +8,156 @@ import type { OasSecurityRequirement } from '../securityRequirement/SecurityRequ
8
8
  import type { StackTrail } from '../../context/StackTrail.js';
9
9
  import type { OasSchema } from '../schema/Schema.js';
10
10
  import type { OasRef } from '../ref/Ref.js';
11
+ /**
12
+ * Fields that define the structure of an OpenAPI v3 document.
13
+ *
14
+ * This type represents the normalized structure of an OpenAPI document after
15
+ * parsing, with operations flattened from the nested paths structure into
16
+ * a simple array for easier processing.
17
+ */
11
18
  export type DocumentFields = {
19
+ /** OpenAPI specification version (e.g., '3.0.0', '3.1.0') */
12
20
  openapi: string;
21
+ /** API metadata including title, version, description */
13
22
  info: OasInfo;
23
+ /** Array of server objects providing connectivity information */
14
24
  servers?: OasServer[] | undefined;
25
+ /** Flattened array of all operations from all paths */
15
26
  operations: OasOperation[];
27
+ /** Container for reusable components (schemas, responses, etc.) */
16
28
  components?: OasComponents | undefined;
29
+ /** List of tags used by operations with additional metadata */
17
30
  tags?: OasTag[] | undefined;
31
+ /** Default security requirements that apply to all operations */
18
32
  security?: OasSecurityRequirement[] | undefined;
33
+ /** Custom extension fields (x-* properties) */
19
34
  extensionFields?: Record<string, unknown>;
20
35
  };
21
- /** Top level document object describing the API */
36
+ /**
37
+ * Represents a complete OpenAPI v3 document in the SKMTC OAS processing system.
38
+ *
39
+ * The `OasDocument` class is the root object in the OAS hierarchy, containing all
40
+ * the information needed to describe a complete REST API. It provides normalized
41
+ * access to document properties with built-in validation and error handling.
42
+ *
43
+ * ## Key Features
44
+ *
45
+ * - **Normalized Structure**: Operations are flattened from nested paths for easier processing
46
+ * - **Lazy Initialization**: Fields are set after construction during parsing
47
+ * - **Type Safety**: All properties are typed and validated on access
48
+ * - **Extensibility**: Supports OpenAPI extension fields (x-* properties)
49
+ * - **JSON Serialization**: Can be converted back to standard OpenAPI JSON format
50
+ *
51
+ * @example Basic document access
52
+ * ```typescript
53
+ * import { OasDocument } from '@skmtc/core';
54
+ *
55
+ * // Document is typically created during parsing
56
+ * const document = new OasDocument();
57
+ * document.fields = {
58
+ * openapi: '3.0.0',
59
+ * info: { title: 'My API', version: '1.0.0' },
60
+ * operations: [
61
+ * // ... parsed operations
62
+ * ],
63
+ * components: {
64
+ * schemas: {
65
+ * User: { type: 'object', properties: { id: { type: 'string' } } }
66
+ * }
67
+ * }
68
+ * };
69
+ *
70
+ * console.log(document.info.title); // 'My API'
71
+ * console.log(document.operations.length); // Number of operations
72
+ * ```
73
+ *
74
+ * @example Iterating over operations
75
+ * ```typescript
76
+ * // Process all operations in the document
77
+ * for (const operation of document.operations) {
78
+ * console.log(`${operation.method.toUpperCase()} ${operation.path}`);
79
+ *
80
+ * if (operation.operationId) {
81
+ * console.log(`Operation ID: ${operation.operationId}`);
82
+ * }
83
+ * }
84
+ * ```
85
+ *
86
+ * @example Working with components
87
+ * ```typescript
88
+ * if (document.components?.schemas) {
89
+ * const userSchema = document.components.schemas.get('User');
90
+ * if (userSchema) {
91
+ * console.log('User schema found:', userSchema);
92
+ * }
93
+ * }
94
+ * ```
95
+ */
22
96
  export declare class OasDocument {
23
97
  #private;
24
98
  /** Static identifier property for OasDocument */
25
99
  oasType: 'openapi';
100
+ /**
101
+ * Creates a new OasDocument instance.
102
+ *
103
+ * The document is typically created with undefined fields and populated
104
+ * later during the parsing process. This allows for lazy initialization
105
+ * and proper error handling during document processing.
106
+ *
107
+ * @param fields - Optional document fields (usually set later during parsing)
108
+ *
109
+ * @example
110
+ * ```typescript
111
+ * // Usually created without fields during parsing
112
+ * const document = new OasDocument();
113
+ *
114
+ * // Fields are set later by the parser
115
+ * document.fields = parsedDocumentFields;
116
+ * ```
117
+ */
26
118
  constructor(fields?: DocumentFields);
119
+ /**
120
+ * Removes an item from the document based on a stack trail path.
121
+ *
122
+ * This method is used internally during document processing to remove
123
+ * specific operations or schema components. The stack trail indicates
124
+ * the path to the item within the document structure.
125
+ *
126
+ * @param stackTrail - Path to the item to remove
127
+ * @returns The removed item, or undefined if not found
128
+ *
129
+ * @internal This method is primarily used by the processing pipeline
130
+ *
131
+ * @example
132
+ * ```typescript
133
+ * // Remove an operation at /users POST
134
+ * const removed = document.removeItem(new StackTrail(['paths', '/users', 'post']));
135
+ *
136
+ * // Remove a schema component
137
+ * const removedSchema = document.removeItem(new StackTrail(['components', 'schemas', 'User']));
138
+ * ```
139
+ */
27
140
  removeItem(stackTrail: StackTrail): OasOperation | OasSchema | OasRef<'schema'> | undefined;
141
+ /**
142
+ * Sets the document fields after parsing.
143
+ *
144
+ * This setter is called by the parsing pipeline to populate the document
145
+ * with parsed OpenAPI data. It enables lazy initialization and proper
146
+ * error handling during document processing.
147
+ *
148
+ * @param fields - The parsed document fields
149
+ *
150
+ * @example
151
+ * ```typescript
152
+ * const document = new OasDocument();
153
+ * document.fields = {
154
+ * openapi: '3.0.0',
155
+ * info: { title: 'API', version: '1.0' },
156
+ * operations: [],
157
+ * // ... other fields
158
+ * };
159
+ * ```
160
+ */
28
161
  set fields(fields: DocumentFields);
29
162
  /** OpenAPI specification version */
30
163
  get openapi(): string;
@@ -41,6 +174,27 @@ export declare class OasDocument {
41
174
  get security(): OasSecurityRequirement[] | undefined;
42
175
  /** Specification Extension fields */
43
176
  get extensionFields(): Record<string, unknown> | undefined;
177
+ /**
178
+ * Converts the document back to a JSON-serializable OpenAPI object.
179
+ *
180
+ * This method serializes the document to a standard OpenAPI v3 format,
181
+ * which can be used for output, validation, or further processing. The
182
+ * resulting object follows the OpenAPI specification structure.
183
+ *
184
+ * @returns A JSON-serializable object representing the OpenAPI document
185
+ *
186
+ * @example
187
+ * ```typescript
188
+ * // Convert document back to standard OpenAPI format
189
+ * const openApiJson = document.toJSON();
190
+ *
191
+ * // Can be stringified for output
192
+ * const yamlString = JSON.stringify(openApiJson, null, 2);
193
+ *
194
+ * // Or used with OpenAPI tools
195
+ * await validateOpenApiDocument(openApiJson);
196
+ * ```
197
+ */
44
198
  toJSON(): object;
45
199
  }
46
200
  //# sourceMappingURL=Document.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Document.d.ts","sourceRoot":"","sources":["../../../src/oas/document/Document.ts"],"names":[],"mappings":"AAAA,OAAO,yBAAyB,CAAC;AACjC,OAA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