@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
|
@@ -199,10 +199,190 @@ export declare class OperationBase<EnrichmentType = undefined> extends ContentBa
|
|
|
199
199
|
* ```
|
|
200
200
|
*/
|
|
201
201
|
insertOperation<V extends GeneratedValue, EnrichmentType = undefined>(insertable: OperationInsertable<V, EnrichmentType>, operation: OasOperation, options?: Pick<InsertOperationOptions<'force'>, 'noExport'>): Inserted<V, 'force', EnrichmentType>;
|
|
202
|
+
/**
|
|
203
|
+
* Inserts a related model with forced generation.
|
|
204
|
+
*
|
|
205
|
+
* This method adds a model to the current generation context, typically used
|
|
206
|
+
* for request/response models or other types related to the operation. The model
|
|
207
|
+
* will be generated and can be referenced in the operation code.
|
|
208
|
+
*
|
|
209
|
+
* @template V - Type of generated value returned by the insertable
|
|
210
|
+
* @template EnrichmentType - Type of enrichment data for the insertable
|
|
211
|
+
* @param insertable - The model generator to insert
|
|
212
|
+
* @param refName - Reference name for the inserted model
|
|
213
|
+
* @param options - Insertion options
|
|
214
|
+
* @param options.noExport - Whether to skip exporting the inserted model
|
|
215
|
+
* @returns Inserted model reference with generated value
|
|
216
|
+
*
|
|
217
|
+
* @example Inserting request/response models
|
|
218
|
+
* ```typescript
|
|
219
|
+
* class ApiOperation extends OperationBase {
|
|
220
|
+
* toDefinition(): Definition {
|
|
221
|
+
* // Insert request model
|
|
222
|
+
* const requestModel = this.insertModel(
|
|
223
|
+
* new RequestModel({ ... }),
|
|
224
|
+
* 'CreateUserRequest'
|
|
225
|
+
* );
|
|
226
|
+
*
|
|
227
|
+
* // Insert response model
|
|
228
|
+
* const responseModel = this.insertModel(
|
|
229
|
+
* new ResponseModel({ ... }),
|
|
230
|
+
* 'CreateUserResponse'
|
|
231
|
+
* );
|
|
232
|
+
*
|
|
233
|
+
* return new Definition({
|
|
234
|
+
* name: this.operation.operationId,
|
|
235
|
+
* content: `async ${this.operation.operationId}(data: ${requestModel.value}): Promise<${responseModel.value}> {
|
|
236
|
+
* return this.request('${this.operation.method}', '${this.operation.path}', data);
|
|
237
|
+
* }`
|
|
238
|
+
* });
|
|
239
|
+
* }
|
|
240
|
+
* }
|
|
241
|
+
* ```
|
|
242
|
+
*/
|
|
202
243
|
insertModel<V extends GeneratedValue, EnrichmentType = undefined>(insertable: ModelInsertable<V, EnrichmentType>, refName: RefName, options?: Pick<InsertModelOptions<'force'>, 'noExport'>): Inserted<V, 'force', EnrichmentType>;
|
|
244
|
+
/**
|
|
245
|
+
* Inserts a related model with automatic schema normalization and reference resolution.
|
|
246
|
+
*
|
|
247
|
+
* This method intelligently handles schema references from operation request/response
|
|
248
|
+
* bodies, automatically resolving schema references to appropriate model names.
|
|
249
|
+
* This is particularly useful for operations with complex request/response schemas.
|
|
250
|
+
*
|
|
251
|
+
* @template V - Type of generated value returned by the insertable
|
|
252
|
+
* @template Schema - Type of OpenAPI schema (schema object, reference, or void)
|
|
253
|
+
* @template EnrichmentType - Type of enrichment data for the insertable
|
|
254
|
+
* @param insertable - The model generator to insert
|
|
255
|
+
* @param args - Schema normalization arguments
|
|
256
|
+
* @param args.schema - The OpenAPI schema to normalize (from request/response)
|
|
257
|
+
* @param args.fallbackName - Name to use if schema is not a reference
|
|
258
|
+
* @param options - Insertion options
|
|
259
|
+
* @param options.noExport - Whether to skip exporting the inserted model
|
|
260
|
+
* @returns Inserted model reference with normalized name and generated value
|
|
261
|
+
*
|
|
262
|
+
* @example Handling operation request/response schemas
|
|
263
|
+
* ```typescript
|
|
264
|
+
* class RestApiOperation extends OperationBase {
|
|
265
|
+
* toDefinition(): Definition {
|
|
266
|
+
* const operation = this.operation;
|
|
267
|
+
*
|
|
268
|
+
* // Handle request body schema
|
|
269
|
+
* let requestType = 'void';
|
|
270
|
+
* const requestSchema = operation.requestBody?.content?.['application/json']?.schema;
|
|
271
|
+
* if (requestSchema) {
|
|
272
|
+
* const requestModel = this.insertNormalizedModel(
|
|
273
|
+
* new TypeScriptInterface({ ... }),
|
|
274
|
+
* {
|
|
275
|
+
* schema: requestSchema,
|
|
276
|
+
* fallbackName: `${operation.operationId}Request`
|
|
277
|
+
* }
|
|
278
|
+
* );
|
|
279
|
+
* requestType = requestModel.value;
|
|
280
|
+
* }
|
|
281
|
+
*
|
|
282
|
+
* // Handle response schema
|
|
283
|
+
* const responseSchema = operation.responses?.['200']?.content?.['application/json']?.schema;
|
|
284
|
+
* const responseModel = this.insertNormalizedModel(
|
|
285
|
+
* new TypeScriptInterface({ ... }),
|
|
286
|
+
* {
|
|
287
|
+
* schema: responseSchema,
|
|
288
|
+
* fallbackName: `${operation.operationId}Response`
|
|
289
|
+
* }
|
|
290
|
+
* );
|
|
291
|
+
*
|
|
292
|
+
* return new Definition({
|
|
293
|
+
* name: operation.operationId,
|
|
294
|
+
* content: `async ${operation.operationId}(data: ${requestType}): Promise<${responseModel.value}>`
|
|
295
|
+
* });
|
|
296
|
+
* }
|
|
297
|
+
* }
|
|
298
|
+
* ```
|
|
299
|
+
*/
|
|
203
300
|
insertNormalizedModel<V extends GeneratedValue, Schema extends OasSchema | OasRef<'schema'> | OasVoid, EnrichmentType = undefined>(insertable: ModelInsertable<V, EnrichmentType>, { schema, fallbackName }: Omit<InsertNormalisedModelArgs<Schema>, 'destinationPath'>, options?: Pick<InsertModelOptions<'force'>, 'noExport'>): InsertNormalisedModelReturn<V, Schema>;
|
|
204
|
-
/**
|
|
301
|
+
/**
|
|
302
|
+
* Defines and registers a new definition in the generation context.
|
|
303
|
+
*
|
|
304
|
+
* This is an experimental method that allows creating and registering
|
|
305
|
+
* definitions directly without going through the standard insertion flow.
|
|
306
|
+
* Use with caution as the API may change in future versions.
|
|
307
|
+
*
|
|
308
|
+
* @experimental This method's API may change in future versions
|
|
309
|
+
* @template V - Type of generated value
|
|
310
|
+
* @param args - Definition arguments
|
|
311
|
+
* @param args.identifier - Unique identifier for the definition
|
|
312
|
+
* @param args.value - The generated value to associate with the definition
|
|
313
|
+
* @param args.noExport - Whether to skip exporting the definition
|
|
314
|
+
* @returns The created and registered definition
|
|
315
|
+
*
|
|
316
|
+
* @example Creating inline definitions
|
|
317
|
+
* ```typescript
|
|
318
|
+
* class InlineHelperOperation extends OperationBase {
|
|
319
|
+
* toDefinition(): Definition {
|
|
320
|
+
* // Create an inline helper function
|
|
321
|
+
* const helper = this.defineAndRegister({
|
|
322
|
+
* identifier: 'validateRequest',
|
|
323
|
+
* value: 'function validateRequest(data: any) { ... }',
|
|
324
|
+
* noExport: true
|
|
325
|
+
* });
|
|
326
|
+
*
|
|
327
|
+
* return new Definition({
|
|
328
|
+
* name: this.operation.operationId,
|
|
329
|
+
* content: `async ${this.operation.operationId}(data: any) {
|
|
330
|
+
* ${helper.value}(data);
|
|
331
|
+
* return this.request('${this.operation.method}', '${this.operation.path}', data);
|
|
332
|
+
* }`
|
|
333
|
+
* });
|
|
334
|
+
* }
|
|
335
|
+
* }
|
|
336
|
+
* ```
|
|
337
|
+
*/
|
|
205
338
|
defineAndRegister<V extends GeneratedValue>({ identifier, value, noExport }: Omit<DefineAndRegisterArgs<V>, 'destinationPath'>): Definition<V>;
|
|
339
|
+
/**
|
|
340
|
+
* Registers a file-level artifact with the generation context.
|
|
341
|
+
*
|
|
342
|
+
* This method allows the operation generator to register additional content
|
|
343
|
+
* (like imports, exports, or file-level definitions) that should be included
|
|
344
|
+
* in the generated file. The registration is automatically scoped to this
|
|
345
|
+
* operation's export path.
|
|
346
|
+
*
|
|
347
|
+
* @param args - Registration arguments
|
|
348
|
+
* @param args.content - The content to register (import, export, etc.)
|
|
349
|
+
* @param args.phase - When to register the content ('pre' or 'post')
|
|
350
|
+
*
|
|
351
|
+
* @example Registering API client imports
|
|
352
|
+
* ```typescript
|
|
353
|
+
* class HttpOperation extends OperationBase {
|
|
354
|
+
* toDefinition(): Definition {
|
|
355
|
+
* // Register imports needed for HTTP operations
|
|
356
|
+
* this.register({
|
|
357
|
+
* content: "import { ApiClient } from './client';",
|
|
358
|
+
* phase: 'pre'
|
|
359
|
+
* });
|
|
360
|
+
*
|
|
361
|
+
* this.register({
|
|
362
|
+
* content: "import { RequestOptions } from './types';",
|
|
363
|
+
* phase: 'pre'
|
|
364
|
+
* });
|
|
365
|
+
*
|
|
366
|
+
* return new Definition({ ... });
|
|
367
|
+
* }
|
|
368
|
+
* }
|
|
369
|
+
* ```
|
|
370
|
+
*
|
|
371
|
+
* @example Registering utility exports
|
|
372
|
+
* ```typescript
|
|
373
|
+
* class ApiOperationGroup extends OperationBase {
|
|
374
|
+
* toDefinition(): Definition {
|
|
375
|
+
* // Register a utility export after all operations
|
|
376
|
+
* this.register({
|
|
377
|
+
* content: "export const API_VERSION = '1.0';",
|
|
378
|
+
* phase: 'post'
|
|
379
|
+
* });
|
|
380
|
+
*
|
|
381
|
+
* return new Definition({ ... });
|
|
382
|
+
* }
|
|
383
|
+
* }
|
|
384
|
+
* ```
|
|
385
|
+
*/
|
|
206
386
|
register(args: BaseRegisterArgs): void;
|
|
207
387
|
}
|
|
208
388
|
//# sourceMappingURL=OperationBase.d.ts.map
|
|
@@ -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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,CAAC,QAAQ,CAAC,GAAG,OAAO,EACrD,cAAc,GAAG,SAAS,EAE1B,UAAU,EAAE,eAAe,CAAC,CAAC,EAAE,cAAc,CAAC,EAC9C,EAAE,MAAM,EAAE,YAAY,EAAE,EAAE,IAAI,CAAC,yBAAyB,CAAC,MAAM,CAAC,EAAE,iBAAiB,CAAC,EACpF,OAAO,GAAE,IAAI,CAAC,kBAAkB,CAAC,OAAO,CAAC,EAAE,UAAU,CAAM,GAC1D,2BAA2B,CAAC,CAAC,EAAE,MAAM,CAAC;IAYzC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAoCG;IACH,iBAAiB,CAAC,CAAC,SAAS,cAAc,EAAE,EAC1C,UAAU,EACV,KAAK,EACL,QAAQ,EACT,EAAE,IAAI,CAAC,qBAAqB,CAAC,CAAC,CAAC,EAAE,iBAAiB,CAAC,GAAG,UAAU,CAAC,CAAC,CAAC;IASpE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA8CG;IACM,QAAQ,CAAC,IAAI,EAAE,gBAAgB,GAAG,IAAI;CAMhD"}
|
|
@@ -197,6 +197,47 @@ export class OperationBase extends ContentBase {
|
|
|
197
197
|
noExport: options.noExport
|
|
198
198
|
});
|
|
199
199
|
}
|
|
200
|
+
/**
|
|
201
|
+
* Inserts a related model with forced generation.
|
|
202
|
+
*
|
|
203
|
+
* This method adds a model to the current generation context, typically used
|
|
204
|
+
* for request/response models or other types related to the operation. The model
|
|
205
|
+
* will be generated and can be referenced in the operation code.
|
|
206
|
+
*
|
|
207
|
+
* @template V - Type of generated value returned by the insertable
|
|
208
|
+
* @template EnrichmentType - Type of enrichment data for the insertable
|
|
209
|
+
* @param insertable - The model generator to insert
|
|
210
|
+
* @param refName - Reference name for the inserted model
|
|
211
|
+
* @param options - Insertion options
|
|
212
|
+
* @param options.noExport - Whether to skip exporting the inserted model
|
|
213
|
+
* @returns Inserted model reference with generated value
|
|
214
|
+
*
|
|
215
|
+
* @example Inserting request/response models
|
|
216
|
+
* ```typescript
|
|
217
|
+
* class ApiOperation extends OperationBase {
|
|
218
|
+
* toDefinition(): Definition {
|
|
219
|
+
* // Insert request model
|
|
220
|
+
* const requestModel = this.insertModel(
|
|
221
|
+
* new RequestModel({ ... }),
|
|
222
|
+
* 'CreateUserRequest'
|
|
223
|
+
* );
|
|
224
|
+
*
|
|
225
|
+
* // Insert response model
|
|
226
|
+
* const responseModel = this.insertModel(
|
|
227
|
+
* new ResponseModel({ ... }),
|
|
228
|
+
* 'CreateUserResponse'
|
|
229
|
+
* );
|
|
230
|
+
*
|
|
231
|
+
* return new Definition({
|
|
232
|
+
* name: this.operation.operationId,
|
|
233
|
+
* content: `async ${this.operation.operationId}(data: ${requestModel.value}): Promise<${responseModel.value}> {
|
|
234
|
+
* return this.request('${this.operation.method}', '${this.operation.path}', data);
|
|
235
|
+
* }`
|
|
236
|
+
* });
|
|
237
|
+
* }
|
|
238
|
+
* }
|
|
239
|
+
* ```
|
|
240
|
+
*/
|
|
200
241
|
insertModel(insertable, refName, options = {}) {
|
|
201
242
|
return this.context.insertModel(insertable, refName, {
|
|
202
243
|
generation: 'force',
|
|
@@ -204,6 +245,62 @@ export class OperationBase extends ContentBase {
|
|
|
204
245
|
noExport: options.noExport
|
|
205
246
|
});
|
|
206
247
|
}
|
|
248
|
+
/**
|
|
249
|
+
* Inserts a related model with automatic schema normalization and reference resolution.
|
|
250
|
+
*
|
|
251
|
+
* This method intelligently handles schema references from operation request/response
|
|
252
|
+
* bodies, automatically resolving schema references to appropriate model names.
|
|
253
|
+
* This is particularly useful for operations with complex request/response schemas.
|
|
254
|
+
*
|
|
255
|
+
* @template V - Type of generated value returned by the insertable
|
|
256
|
+
* @template Schema - Type of OpenAPI schema (schema object, reference, or void)
|
|
257
|
+
* @template EnrichmentType - Type of enrichment data for the insertable
|
|
258
|
+
* @param insertable - The model generator to insert
|
|
259
|
+
* @param args - Schema normalization arguments
|
|
260
|
+
* @param args.schema - The OpenAPI schema to normalize (from request/response)
|
|
261
|
+
* @param args.fallbackName - Name to use if schema is not a reference
|
|
262
|
+
* @param options - Insertion options
|
|
263
|
+
* @param options.noExport - Whether to skip exporting the inserted model
|
|
264
|
+
* @returns Inserted model reference with normalized name and generated value
|
|
265
|
+
*
|
|
266
|
+
* @example Handling operation request/response schemas
|
|
267
|
+
* ```typescript
|
|
268
|
+
* class RestApiOperation extends OperationBase {
|
|
269
|
+
* toDefinition(): Definition {
|
|
270
|
+
* const operation = this.operation;
|
|
271
|
+
*
|
|
272
|
+
* // Handle request body schema
|
|
273
|
+
* let requestType = 'void';
|
|
274
|
+
* const requestSchema = operation.requestBody?.content?.['application/json']?.schema;
|
|
275
|
+
* if (requestSchema) {
|
|
276
|
+
* const requestModel = this.insertNormalizedModel(
|
|
277
|
+
* new TypeScriptInterface({ ... }),
|
|
278
|
+
* {
|
|
279
|
+
* schema: requestSchema,
|
|
280
|
+
* fallbackName: `${operation.operationId}Request`
|
|
281
|
+
* }
|
|
282
|
+
* );
|
|
283
|
+
* requestType = requestModel.value;
|
|
284
|
+
* }
|
|
285
|
+
*
|
|
286
|
+
* // Handle response schema
|
|
287
|
+
* const responseSchema = operation.responses?.['200']?.content?.['application/json']?.schema;
|
|
288
|
+
* const responseModel = this.insertNormalizedModel(
|
|
289
|
+
* new TypeScriptInterface({ ... }),
|
|
290
|
+
* {
|
|
291
|
+
* schema: responseSchema,
|
|
292
|
+
* fallbackName: `${operation.operationId}Response`
|
|
293
|
+
* }
|
|
294
|
+
* );
|
|
295
|
+
*
|
|
296
|
+
* return new Definition({
|
|
297
|
+
* name: operation.operationId,
|
|
298
|
+
* content: `async ${operation.operationId}(data: ${requestType}): Promise<${responseModel.value}>`
|
|
299
|
+
* });
|
|
300
|
+
* }
|
|
301
|
+
* }
|
|
302
|
+
* ```
|
|
303
|
+
*/
|
|
207
304
|
insertNormalizedModel(insertable, { schema, fallbackName }, options = {}) {
|
|
208
305
|
return this.context.insertNormalisedModel(insertable, {
|
|
209
306
|
schema,
|
|
@@ -211,7 +308,43 @@ export class OperationBase extends ContentBase {
|
|
|
211
308
|
destinationPath: this.settings.exportPath
|
|
212
309
|
}, options);
|
|
213
310
|
}
|
|
214
|
-
/**
|
|
311
|
+
/**
|
|
312
|
+
* Defines and registers a new definition in the generation context.
|
|
313
|
+
*
|
|
314
|
+
* This is an experimental method that allows creating and registering
|
|
315
|
+
* definitions directly without going through the standard insertion flow.
|
|
316
|
+
* Use with caution as the API may change in future versions.
|
|
317
|
+
*
|
|
318
|
+
* @experimental This method's API may change in future versions
|
|
319
|
+
* @template V - Type of generated value
|
|
320
|
+
* @param args - Definition arguments
|
|
321
|
+
* @param args.identifier - Unique identifier for the definition
|
|
322
|
+
* @param args.value - The generated value to associate with the definition
|
|
323
|
+
* @param args.noExport - Whether to skip exporting the definition
|
|
324
|
+
* @returns The created and registered definition
|
|
325
|
+
*
|
|
326
|
+
* @example Creating inline definitions
|
|
327
|
+
* ```typescript
|
|
328
|
+
* class InlineHelperOperation extends OperationBase {
|
|
329
|
+
* toDefinition(): Definition {
|
|
330
|
+
* // Create an inline helper function
|
|
331
|
+
* const helper = this.defineAndRegister({
|
|
332
|
+
* identifier: 'validateRequest',
|
|
333
|
+
* value: 'function validateRequest(data: any) { ... }',
|
|
334
|
+
* noExport: true
|
|
335
|
+
* });
|
|
336
|
+
*
|
|
337
|
+
* return new Definition({
|
|
338
|
+
* name: this.operation.operationId,
|
|
339
|
+
* content: `async ${this.operation.operationId}(data: any) {
|
|
340
|
+
* ${helper.value}(data);
|
|
341
|
+
* return this.request('${this.operation.method}', '${this.operation.path}', data);
|
|
342
|
+
* }`
|
|
343
|
+
* });
|
|
344
|
+
* }
|
|
345
|
+
* }
|
|
346
|
+
* ```
|
|
347
|
+
*/
|
|
215
348
|
defineAndRegister({ identifier, value, noExport }) {
|
|
216
349
|
return this.context.defineAndRegister({
|
|
217
350
|
identifier,
|
|
@@ -220,6 +353,53 @@ export class OperationBase extends ContentBase {
|
|
|
220
353
|
noExport
|
|
221
354
|
});
|
|
222
355
|
}
|
|
356
|
+
/**
|
|
357
|
+
* Registers a file-level artifact with the generation context.
|
|
358
|
+
*
|
|
359
|
+
* This method allows the operation generator to register additional content
|
|
360
|
+
* (like imports, exports, or file-level definitions) that should be included
|
|
361
|
+
* in the generated file. The registration is automatically scoped to this
|
|
362
|
+
* operation's export path.
|
|
363
|
+
*
|
|
364
|
+
* @param args - Registration arguments
|
|
365
|
+
* @param args.content - The content to register (import, export, etc.)
|
|
366
|
+
* @param args.phase - When to register the content ('pre' or 'post')
|
|
367
|
+
*
|
|
368
|
+
* @example Registering API client imports
|
|
369
|
+
* ```typescript
|
|
370
|
+
* class HttpOperation extends OperationBase {
|
|
371
|
+
* toDefinition(): Definition {
|
|
372
|
+
* // Register imports needed for HTTP operations
|
|
373
|
+
* this.register({
|
|
374
|
+
* content: "import { ApiClient } from './client';",
|
|
375
|
+
* phase: 'pre'
|
|
376
|
+
* });
|
|
377
|
+
*
|
|
378
|
+
* this.register({
|
|
379
|
+
* content: "import { RequestOptions } from './types';",
|
|
380
|
+
* phase: 'pre'
|
|
381
|
+
* });
|
|
382
|
+
*
|
|
383
|
+
* return new Definition({ ... });
|
|
384
|
+
* }
|
|
385
|
+
* }
|
|
386
|
+
* ```
|
|
387
|
+
*
|
|
388
|
+
* @example Registering utility exports
|
|
389
|
+
* ```typescript
|
|
390
|
+
* class ApiOperationGroup extends OperationBase {
|
|
391
|
+
* toDefinition(): Definition {
|
|
392
|
+
* // Register a utility export after all operations
|
|
393
|
+
* this.register({
|
|
394
|
+
* content: "export const API_VERSION = '1.0';",
|
|
395
|
+
* phase: 'post'
|
|
396
|
+
* });
|
|
397
|
+
*
|
|
398
|
+
* return new Definition({ ... });
|
|
399
|
+
* }
|
|
400
|
+
* }
|
|
401
|
+
* ```
|
|
402
|
+
*/
|
|
223
403
|
register(args) {
|
|
224
404
|
this.context.register({
|
|
225
405
|
...args,
|
package/esm/oas/array/Array.d.ts
CHANGED
|
@@ -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,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mB,GAAG,SAAS,CAAC,iBAAiB;CAexE"}
|
package/esm/oas/array/Array.js
CHANGED
|
@@ -1,6 +1,98 @@
|
|
|
1
1
|
import "../../_dnt.polyfills.js";
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
3
|
+
* Represents an array schema in the OpenAPI Specification.
|
|
4
|
+
*
|
|
5
|
+
* `OasArray` handles array type definitions with comprehensive validation
|
|
6
|
+
* constraints including item count limits, uniqueness requirements, and
|
|
7
|
+
* item type specifications. It supports nested schemas and references
|
|
8
|
+
* for complex array structures.
|
|
9
|
+
*
|
|
10
|
+
* This class is used throughout the OAS processing pipeline to represent
|
|
11
|
+
* array fields in API schemas, including lists of objects, primitive arrays,
|
|
12
|
+
* and complex nested array structures.
|
|
13
|
+
*
|
|
14
|
+
* ## Key Features
|
|
15
|
+
*
|
|
16
|
+
* - **Item Type Definition**: Support for any schema type as array items
|
|
17
|
+
* - **Size Constraints**: Minimum and maximum item count validation
|
|
18
|
+
* - **Uniqueness Validation**: Ensure array items are unique (like Set behavior)
|
|
19
|
+
* - **Nested Schemas**: Support for complex nested array structures
|
|
20
|
+
* - **Reference Handling**: Seamless integration with schema references
|
|
21
|
+
* - **Nullable Support**: Type-safe nullable array handling
|
|
22
|
+
* - **JSON Schema**: Conversion to standard JSON Schema format
|
|
23
|
+
*
|
|
24
|
+
* @template Nullable - Whether the array value can be null
|
|
25
|
+
*
|
|
26
|
+
* @example String array
|
|
27
|
+
* ```typescript
|
|
28
|
+
* import { OasArray, OasString } from '@skmtc/core';
|
|
29
|
+
*
|
|
30
|
+
* const tagsArray = new OasArray({
|
|
31
|
+
* title: 'Tags',
|
|
32
|
+
* description: 'List of tags associated with the item',
|
|
33
|
+
* items: new OasString({ minLength: 1 }),
|
|
34
|
+
* minItems: 1,
|
|
35
|
+
* uniqueItems: true,
|
|
36
|
+
* example: ['javascript', 'typescript', 'react']
|
|
37
|
+
* });
|
|
38
|
+
* ```
|
|
39
|
+
*
|
|
40
|
+
* @example Object array with references
|
|
41
|
+
* ```typescript
|
|
42
|
+
* import { OasArray, OasRef } from '@skmtc/core';
|
|
43
|
+
*
|
|
44
|
+
* const usersArray = new OasArray({
|
|
45
|
+
* title: 'Users',
|
|
46
|
+
* description: 'List of user objects',
|
|
47
|
+
* items: new OasRef({ refName: 'User' }),
|
|
48
|
+
* maxItems: 100,
|
|
49
|
+
* example: [
|
|
50
|
+
* { id: 1, name: 'John' },
|
|
51
|
+
* { id: 2, name: 'Jane' }
|
|
52
|
+
* ]
|
|
53
|
+
* });
|
|
54
|
+
* ```
|
|
55
|
+
*
|
|
56
|
+
* @example Nested array (array of arrays)
|
|
57
|
+
* ```typescript
|
|
58
|
+
* const matrixArray = new OasArray({
|
|
59
|
+
* title: 'Matrix',
|
|
60
|
+
* description: '2D array of numbers',
|
|
61
|
+
* items: new OasArray({
|
|
62
|
+
* items: new OasInteger({ minimum: 0 })
|
|
63
|
+
* }),
|
|
64
|
+
* example: [
|
|
65
|
+
* [1, 2, 3],
|
|
66
|
+
* [4, 5, 6],
|
|
67
|
+
* [7, 8, 9]
|
|
68
|
+
* ]
|
|
69
|
+
* });
|
|
70
|
+
* ```
|
|
71
|
+
*
|
|
72
|
+
* @example Nullable array with constraints
|
|
73
|
+
* ```typescript
|
|
74
|
+
* const optionalIdsArray = new OasArray<true>({
|
|
75
|
+
* title: 'Optional IDs',
|
|
76
|
+
* description: 'Optional list of IDs',
|
|
77
|
+
* items: new OasInteger({ format: 'int64', minimum: 1 }),
|
|
78
|
+
* nullable: true,
|
|
79
|
+
* minItems: 0,
|
|
80
|
+
* maxItems: 10,
|
|
81
|
+
* defaultValue: null
|
|
82
|
+
* });
|
|
83
|
+
* ```
|
|
84
|
+
*
|
|
85
|
+
* @example Unique items validation
|
|
86
|
+
* ```typescript
|
|
87
|
+
* const uniqueEmailsArray = new OasArray({
|
|
88
|
+
* title: 'Email Recipients',
|
|
89
|
+
* description: 'List of unique email addresses',
|
|
90
|
+
* items: new OasString({ format: 'email' }),
|
|
91
|
+
* uniqueItems: true, // Ensures no duplicate emails
|
|
92
|
+
* minItems: 1,
|
|
93
|
+
* example: ['user1@example.com', 'user2@example.com']
|
|
94
|
+
* });
|
|
95
|
+
* ```
|
|
4
96
|
*/
|
|
5
97
|
export class OasArray {
|
|
6
98
|
constructor(fields) {
|