@skmtc/core 0.0.785 → 0.0.787
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.
- package/esm/dsl/ContentSettings.d.ts +164 -0
- package/esm/dsl/ContentSettings.d.ts.map +1 -1
- package/esm/dsl/ContentSettings.js +151 -0
- package/esm/dsl/Definition.d.ts +199 -0
- package/esm/dsl/Definition.d.ts.map +1 -1
- package/esm/dsl/Definition.js +189 -0
- package/esm/dsl/EntityType.d.ts +83 -0
- package/esm/dsl/EntityType.d.ts.map +1 -1
- package/esm/dsl/EntityType.js +83 -0
- package/esm/dsl/Identifier.d.ts +152 -0
- package/esm/dsl/Identifier.d.ts.map +1 -1
- package/esm/dsl/Identifier.js +152 -0
- package/esm/dsl/Import.d.ts +221 -0
- package/esm/dsl/Import.d.ts.map +1 -1
- package/esm/dsl/Import.js +202 -0
- package/esm/dsl/operation/OperationBase.d.ts +181 -1
- package/esm/dsl/operation/OperationBase.d.ts.map +1 -1
- package/esm/dsl/operation/OperationBase.js +181 -1
- package/esm/oas/array/Array.d.ts +109 -1
- package/esm/oas/array/Array.d.ts.map +1 -1
- package/esm/oas/array/Array.js +93 -1
- package/esm/oas/document/Document.d.ts +155 -1
- package/esm/oas/document/Document.d.ts.map +1 -1
- package/esm/oas/document/Document.js +141 -2
- package/esm/oas/integer/Integer.d.ts +98 -0
- package/esm/oas/integer/Integer.d.ts.map +1 -1
- package/esm/oas/integer/Integer.js +80 -0
- package/esm/oas/object/Object.d.ts +255 -10
- package/esm/oas/object/Object.d.ts.map +1 -1
- package/esm/oas/object/Object.js +229 -10
- package/esm/oas/string/String.d.ts +103 -1
- package/esm/oas/string/String.d.ts.map +1 -1
- package/esm/oas/string/String.js +87 -1
- package/esm/types/Brand.d.ts +74 -0
- package/esm/types/Brand.d.ts.map +1 -1
- package/esm/types/Brand.js +9 -0
- package/esm/types/GeneratorKeys.d.ts +336 -0
- package/esm/types/GeneratorKeys.d.ts.map +1 -1
- package/esm/types/GeneratorKeys.js +243 -0
- package/esm/types/GeneratorType.d.ts +119 -0
- package/esm/types/GeneratorType.d.ts.map +1 -1
- package/esm/types/Method.d.ts +109 -0
- package/esm/types/Method.d.ts.map +1 -1
- package/esm/types/Method.js +84 -0
- package/esm/types/RefName.d.ts +61 -0
- package/esm/types/RefName.d.ts.map +1 -1
- package/package.json +1 -1
- package/script/dsl/ContentSettings.d.ts +164 -0
- package/script/dsl/ContentSettings.d.ts.map +1 -1
- package/script/dsl/ContentSettings.js +151 -0
- package/script/dsl/Definition.d.ts +199 -0
- package/script/dsl/Definition.d.ts.map +1 -1
- package/script/dsl/Definition.js +189 -0
- package/script/dsl/EntityType.d.ts +83 -0
- package/script/dsl/EntityType.d.ts.map +1 -1
- package/script/dsl/EntityType.js +83 -0
- package/script/dsl/Identifier.d.ts +152 -0
- package/script/dsl/Identifier.d.ts.map +1 -1
- package/script/dsl/Identifier.js +152 -0
- package/script/dsl/Import.d.ts +221 -0
- package/script/dsl/Import.d.ts.map +1 -1
- package/script/dsl/Import.js +202 -0
- package/script/dsl/operation/OperationBase.d.ts +181 -1
- package/script/dsl/operation/OperationBase.d.ts.map +1 -1
- package/script/dsl/operation/OperationBase.js +181 -1
- package/script/oas/array/Array.d.ts +109 -1
- package/script/oas/array/Array.d.ts.map +1 -1
- package/script/oas/array/Array.js +93 -1
- package/script/oas/document/Document.d.ts +155 -1
- package/script/oas/document/Document.d.ts.map +1 -1
- package/script/oas/document/Document.js +141 -2
- package/script/oas/integer/Integer.d.ts +98 -0
- package/script/oas/integer/Integer.d.ts.map +1 -1
- package/script/oas/integer/Integer.js +80 -0
- package/script/oas/object/Object.d.ts +255 -10
- package/script/oas/object/Object.d.ts.map +1 -1
- package/script/oas/object/Object.js +229 -10
- package/script/oas/string/String.d.ts +103 -1
- package/script/oas/string/String.d.ts.map +1 -1
- package/script/oas/string/String.js +87 -1
- package/script/types/Brand.d.ts +74 -0
- package/script/types/Brand.d.ts.map +1 -1
- package/script/types/Brand.js +9 -0
- package/script/types/GeneratorKeys.d.ts +336 -0
- package/script/types/GeneratorKeys.d.ts.map +1 -1
- package/script/types/GeneratorKeys.js +243 -0
- package/script/types/GeneratorType.d.ts +119 -0
- package/script/types/GeneratorType.d.ts.map +1 -1
- package/script/types/Method.d.ts +109 -0
- package/script/types/Method.d.ts.map +1 -1
- package/script/types/Method.js +84 -0
- package/script/types/RefName.d.ts +61 -0
- package/script/types/RefName.d.ts.map +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OperationBase.d.ts","sourceRoot":"","sources":["../../../src/dsl/operation/OperationBase.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAA;AACrD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kCAAkC,CAAA;AACpE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAA;AAC5D,OAAO,KAAK,EACV,gBAAgB,EAChB,eAAe,EAEf,qBAAqB,EACrB,sBAAsB,EACtB,kBAAkB,EAClB,yBAAyB,EACzB,2BAA2B,EAC5B,MAAM,kCAAkC,CAAA;AACzC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAA;AACnE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAA;AAChE,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAC/C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAElD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AAC9C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AACxD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAA;AACrD,OAAO,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAA;AACtD,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAA;AAC7C,OAAO,EAAE,OA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C;IASpE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA8CG;IACM,QAAQ,CAAC,IAAI,EAAE,gBAAgB,GAAG,IAAI;CAMhD"}
|
|
@@ -200,6 +200,47 @@ class OperationBase extends ContentBase_js_1.ContentBase {
|
|
|
200
200
|
noExport: options.noExport
|
|
201
201
|
});
|
|
202
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
|
+
*/
|
|
203
244
|
insertModel(insertable, refName, options = {}) {
|
|
204
245
|
return this.context.insertModel(insertable, refName, {
|
|
205
246
|
generation: 'force',
|
|
@@ -207,6 +248,62 @@ class OperationBase extends ContentBase_js_1.ContentBase {
|
|
|
207
248
|
noExport: options.noExport
|
|
208
249
|
});
|
|
209
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
|
+
*/
|
|
210
307
|
insertNormalizedModel(insertable, { schema, fallbackName }, options = {}) {
|
|
211
308
|
return this.context.insertNormalisedModel(insertable, {
|
|
212
309
|
schema,
|
|
@@ -214,7 +311,43 @@ class OperationBase extends ContentBase_js_1.ContentBase {
|
|
|
214
311
|
destinationPath: this.settings.exportPath
|
|
215
312
|
}, options);
|
|
216
313
|
}
|
|
217
|
-
/**
|
|
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
|
+
*/
|
|
218
351
|
defineAndRegister({ identifier, value, noExport }) {
|
|
219
352
|
return this.context.defineAndRegister({
|
|
220
353
|
identifier,
|
|
@@ -223,6 +356,53 @@ class OperationBase extends ContentBase_js_1.ContentBase {
|
|
|
223
356
|
noExport
|
|
224
357
|
});
|
|
225
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
|
+
*/
|
|
226
406
|
register(args) {
|
|
227
407
|
this.context.register({
|
|
228
408
|
...args,
|
|
@@ -2,21 +2,129 @@ import "../../_dnt.polyfills.js";
|
|
|
2
2
|
import type { OasSchema, ToJsonSchemaOptions } from '../schema/Schema.js';
|
|
3
3
|
import type { OasRef } from '../ref/Ref.js';
|
|
4
4
|
import type { OpenAPIV3 } from 'openapi-types';
|
|
5
|
+
/**
|
|
6
|
+
* Constructor fields for {@link OasArray}.
|
|
7
|
+
*
|
|
8
|
+
* @template Nullable - Whether the array value can be null
|
|
9
|
+
*/
|
|
5
10
|
export type ArrayFields<Nullable extends boolean | undefined> = {
|
|
11
|
+
/** Schema definition for array items */
|
|
6
12
|
items: OasSchema | OasRef<'schema'>;
|
|
13
|
+
/** A short summary of the array schema */
|
|
7
14
|
title?: string;
|
|
15
|
+
/** A description of the array schema */
|
|
8
16
|
description?: string;
|
|
17
|
+
/** Whether the array value can be null */
|
|
9
18
|
nullable?: Nullable;
|
|
19
|
+
/** Whether array items must be unique */
|
|
10
20
|
uniqueItems?: boolean;
|
|
21
|
+
/** Custom extension fields (x-* properties) */
|
|
11
22
|
extensionFields?: Record<string, unknown>;
|
|
23
|
+
/** Example array value */
|
|
12
24
|
example?: Nullable extends true ? unknown[] | null | undefined : unknown[] | undefined;
|
|
25
|
+
/** Maximum number of items allowed */
|
|
13
26
|
maxItems?: number;
|
|
27
|
+
/** Minimum number of items required */
|
|
14
28
|
minItems?: number;
|
|
29
|
+
/** Array of allowed enum values for the entire array */
|
|
15
30
|
enums?: Nullable extends true ? (unknown | null)[] | undefined : unknown[] | undefined;
|
|
31
|
+
/** Default value for the array */
|
|
16
32
|
defaultValue?: Nullable extends true ? unknown[] | null | undefined : unknown[] | undefined;
|
|
17
33
|
};
|
|
18
34
|
/**
|
|
19
|
-
*
|
|
35
|
+
* Represents an array schema in the OpenAPI Specification.
|
|
36
|
+
*
|
|
37
|
+
* `OasArray` handles array type definitions with comprehensive validation
|
|
38
|
+
* constraints including item count limits, uniqueness requirements, and
|
|
39
|
+
* item type specifications. It supports nested schemas and references
|
|
40
|
+
* for complex array structures.
|
|
41
|
+
*
|
|
42
|
+
* This class is used throughout the OAS processing pipeline to represent
|
|
43
|
+
* array fields in API schemas, including lists of objects, primitive arrays,
|
|
44
|
+
* and complex nested array structures.
|
|
45
|
+
*
|
|
46
|
+
* ## Key Features
|
|
47
|
+
*
|
|
48
|
+
* - **Item Type Definition**: Support for any schema type as array items
|
|
49
|
+
* - **Size Constraints**: Minimum and maximum item count validation
|
|
50
|
+
* - **Uniqueness Validation**: Ensure array items are unique (like Set behavior)
|
|
51
|
+
* - **Nested Schemas**: Support for complex nested array structures
|
|
52
|
+
* - **Reference Handling**: Seamless integration with schema references
|
|
53
|
+
* - **Nullable Support**: Type-safe nullable array handling
|
|
54
|
+
* - **JSON Schema**: Conversion to standard JSON Schema format
|
|
55
|
+
*
|
|
56
|
+
* @template Nullable - Whether the array value can be null
|
|
57
|
+
*
|
|
58
|
+
* @example String array
|
|
59
|
+
* ```typescript
|
|
60
|
+
* import { OasArray, OasString } from '@skmtc/core';
|
|
61
|
+
*
|
|
62
|
+
* const tagsArray = new OasArray({
|
|
63
|
+
* title: 'Tags',
|
|
64
|
+
* description: 'List of tags associated with the item',
|
|
65
|
+
* items: new OasString({ minLength: 1 }),
|
|
66
|
+
* minItems: 1,
|
|
67
|
+
* uniqueItems: true,
|
|
68
|
+
* example: ['javascript', 'typescript', 'react']
|
|
69
|
+
* });
|
|
70
|
+
* ```
|
|
71
|
+
*
|
|
72
|
+
* @example Object array with references
|
|
73
|
+
* ```typescript
|
|
74
|
+
* import { OasArray, OasRef } from '@skmtc/core';
|
|
75
|
+
*
|
|
76
|
+
* const usersArray = new OasArray({
|
|
77
|
+
* title: 'Users',
|
|
78
|
+
* description: 'List of user objects',
|
|
79
|
+
* items: new OasRef({ refName: 'User' }),
|
|
80
|
+
* maxItems: 100,
|
|
81
|
+
* example: [
|
|
82
|
+
* { id: 1, name: 'John' },
|
|
83
|
+
* { id: 2, name: 'Jane' }
|
|
84
|
+
* ]
|
|
85
|
+
* });
|
|
86
|
+
* ```
|
|
87
|
+
*
|
|
88
|
+
* @example Nested array (array of arrays)
|
|
89
|
+
* ```typescript
|
|
90
|
+
* const matrixArray = new OasArray({
|
|
91
|
+
* title: 'Matrix',
|
|
92
|
+
* description: '2D array of numbers',
|
|
93
|
+
* items: new OasArray({
|
|
94
|
+
* items: new OasInteger({ minimum: 0 })
|
|
95
|
+
* }),
|
|
96
|
+
* example: [
|
|
97
|
+
* [1, 2, 3],
|
|
98
|
+
* [4, 5, 6],
|
|
99
|
+
* [7, 8, 9]
|
|
100
|
+
* ]
|
|
101
|
+
* });
|
|
102
|
+
* ```
|
|
103
|
+
*
|
|
104
|
+
* @example Nullable array with constraints
|
|
105
|
+
* ```typescript
|
|
106
|
+
* const optionalIdsArray = new OasArray<true>({
|
|
107
|
+
* title: 'Optional IDs',
|
|
108
|
+
* description: 'Optional list of IDs',
|
|
109
|
+
* items: new OasInteger({ format: 'int64', minimum: 1 }),
|
|
110
|
+
* nullable: true,
|
|
111
|
+
* minItems: 0,
|
|
112
|
+
* maxItems: 10,
|
|
113
|
+
* defaultValue: null
|
|
114
|
+
* });
|
|
115
|
+
* ```
|
|
116
|
+
*
|
|
117
|
+
* @example Unique items validation
|
|
118
|
+
* ```typescript
|
|
119
|
+
* const uniqueEmailsArray = new OasArray({
|
|
120
|
+
* title: 'Email Recipients',
|
|
121
|
+
* description: 'List of unique email addresses',
|
|
122
|
+
* items: new OasString({ format: 'email' }),
|
|
123
|
+
* uniqueItems: true, // Ensures no duplicate emails
|
|
124
|
+
* minItems: 1,
|
|
125
|
+
* example: ['user1@example.com', 'user2@example.com']
|
|
126
|
+
* });
|
|
127
|
+
* ```
|
|
20
128
|
*/
|
|
21
129
|
export declare class OasArray<Nullable extends boolean | undefined = boolean | undefined> {
|
|
22
130
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Array.d.ts","sourceRoot":"","sources":["../../../src/oas/array/Array.ts"],"names":[],"mappings":"AAAA,OAAO,yBAAyB,CAAC;AACjC,OAAO,KAAK,EAAE,SAAS,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAA;AACzE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,eAAe,CAAA;AAC3C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAA;AAE9C,MAAM,MAAM,WAAW,CAAC,QAAQ,SAAS,OAAO,GAAG,SAAS,IAAI;IAC9D,KAAK,EAAE,SAAS,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAA;IACnC,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,QAAQ,CAAC,EAAE,QAAQ,CAAA;IACnB,WAAW,CAAC,EAAE,OAAO,CAAA;IACrB,eAAe,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IACzC,OAAO,CAA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AO,EAAE,GAAG,IAAI,GAAG,SAAS,GAAG,OAAO,EAAE,GAAG,SAAS,CAAA;IACrF;;OAEG;IACH,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAA;IAC5B;;OAEG;IACH,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAA;IAE5B;;OAEG;IACH,KAAK,EAAE,QAAQ,SAAS,IAAI,GAAG,CAAC,OAAO,GAAG,IAAI,CAAC,EAAE,GAAG,SAAS,GAAG,OAAO,EAAE,GAAG,SAAS,CAAA;IAErF;;OAEG;IACH,YAAY,EAAE,QAAQ,SAAS,IAAI,GAAG,OAAO,EAAE,GAAG,IAAI,GAAG,SAAS,GAAG,OAAO,EAAE,GAAG,SAAS,CAAA;gBAE9E,MAAM,EAAE,WAAW,CAAC,QAAQ,CAAC;IAczC,KAAK,IAAI,IAAI,IAAI,MAAM,CAAC,QAAQ,CAAC;IAIjC,OAAO,IAAI,QAAQ,CAAC,QAAQ,CAAC;IAI7B,WAAW,IAAI,QAAQ,CAAC,QAAQ,CAAC;IAIjC,YAAY,CAAC,OAAO,EAAE,mBAAmB,GAAG,SAAS,CAAC,iBAAiB;CAexE"}
|
|
@@ -3,7 +3,99 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.OasArray = void 0;
|
|
4
4
|
require("../../_dnt.polyfills.js");
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
6
|
+
* Represents an array schema in the OpenAPI Specification.
|
|
7
|
+
*
|
|
8
|
+
* `OasArray` handles array type definitions with comprehensive validation
|
|
9
|
+
* constraints including item count limits, uniqueness requirements, and
|
|
10
|
+
* item type specifications. It supports nested schemas and references
|
|
11
|
+
* for complex array structures.
|
|
12
|
+
*
|
|
13
|
+
* This class is used throughout the OAS processing pipeline to represent
|
|
14
|
+
* array fields in API schemas, including lists of objects, primitive arrays,
|
|
15
|
+
* and complex nested array structures.
|
|
16
|
+
*
|
|
17
|
+
* ## Key Features
|
|
18
|
+
*
|
|
19
|
+
* - **Item Type Definition**: Support for any schema type as array items
|
|
20
|
+
* - **Size Constraints**: Minimum and maximum item count validation
|
|
21
|
+
* - **Uniqueness Validation**: Ensure array items are unique (like Set behavior)
|
|
22
|
+
* - **Nested Schemas**: Support for complex nested array structures
|
|
23
|
+
* - **Reference Handling**: Seamless integration with schema references
|
|
24
|
+
* - **Nullable Support**: Type-safe nullable array handling
|
|
25
|
+
* - **JSON Schema**: Conversion to standard JSON Schema format
|
|
26
|
+
*
|
|
27
|
+
* @template Nullable - Whether the array value can be null
|
|
28
|
+
*
|
|
29
|
+
* @example String array
|
|
30
|
+
* ```typescript
|
|
31
|
+
* import { OasArray, OasString } from '@skmtc/core';
|
|
32
|
+
*
|
|
33
|
+
* const tagsArray = new OasArray({
|
|
34
|
+
* title: 'Tags',
|
|
35
|
+
* description: 'List of tags associated with the item',
|
|
36
|
+
* items: new OasString({ minLength: 1 }),
|
|
37
|
+
* minItems: 1,
|
|
38
|
+
* uniqueItems: true,
|
|
39
|
+
* example: ['javascript', 'typescript', 'react']
|
|
40
|
+
* });
|
|
41
|
+
* ```
|
|
42
|
+
*
|
|
43
|
+
* @example Object array with references
|
|
44
|
+
* ```typescript
|
|
45
|
+
* import { OasArray, OasRef } from '@skmtc/core';
|
|
46
|
+
*
|
|
47
|
+
* const usersArray = new OasArray({
|
|
48
|
+
* title: 'Users',
|
|
49
|
+
* description: 'List of user objects',
|
|
50
|
+
* items: new OasRef({ refName: 'User' }),
|
|
51
|
+
* maxItems: 100,
|
|
52
|
+
* example: [
|
|
53
|
+
* { id: 1, name: 'John' },
|
|
54
|
+
* { id: 2, name: 'Jane' }
|
|
55
|
+
* ]
|
|
56
|
+
* });
|
|
57
|
+
* ```
|
|
58
|
+
*
|
|
59
|
+
* @example Nested array (array of arrays)
|
|
60
|
+
* ```typescript
|
|
61
|
+
* const matrixArray = new OasArray({
|
|
62
|
+
* title: 'Matrix',
|
|
63
|
+
* description: '2D array of numbers',
|
|
64
|
+
* items: new OasArray({
|
|
65
|
+
* items: new OasInteger({ minimum: 0 })
|
|
66
|
+
* }),
|
|
67
|
+
* example: [
|
|
68
|
+
* [1, 2, 3],
|
|
69
|
+
* [4, 5, 6],
|
|
70
|
+
* [7, 8, 9]
|
|
71
|
+
* ]
|
|
72
|
+
* });
|
|
73
|
+
* ```
|
|
74
|
+
*
|
|
75
|
+
* @example Nullable array with constraints
|
|
76
|
+
* ```typescript
|
|
77
|
+
* const optionalIdsArray = new OasArray<true>({
|
|
78
|
+
* title: 'Optional IDs',
|
|
79
|
+
* description: 'Optional list of IDs',
|
|
80
|
+
* items: new OasInteger({ format: 'int64', minimum: 1 }),
|
|
81
|
+
* nullable: true,
|
|
82
|
+
* minItems: 0,
|
|
83
|
+
* maxItems: 10,
|
|
84
|
+
* defaultValue: null
|
|
85
|
+
* });
|
|
86
|
+
* ```
|
|
87
|
+
*
|
|
88
|
+
* @example Unique items validation
|
|
89
|
+
* ```typescript
|
|
90
|
+
* const uniqueEmailsArray = new OasArray({
|
|
91
|
+
* title: 'Email Recipients',
|
|
92
|
+
* description: 'List of unique email addresses',
|
|
93
|
+
* items: new OasString({ format: 'email' }),
|
|
94
|
+
* uniqueItems: true, // Ensures no duplicate emails
|
|
95
|
+
* minItems: 1,
|
|
96
|
+
* example: ['user1@example.com', 'user2@example.com']
|
|
97
|
+
* });
|
|
98
|
+
* ```
|
|
7
99
|
*/
|
|
8
100
|
class OasArray {
|
|
9
101
|
constructor(fields) {
|
|
@@ -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
|
-
/**
|
|
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,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,eAAe,CAAA;AAC3C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAA;AAChE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,2BA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