@skmtc/core 0.0.785 → 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 (47) hide show
  1. package/esm/dsl/Identifier.d.ts +152 -0
  2. package/esm/dsl/Identifier.d.ts.map +1 -1
  3. package/esm/dsl/Identifier.js +152 -0
  4. package/esm/dsl/Import.d.ts +221 -0
  5. package/esm/dsl/Import.d.ts.map +1 -1
  6. package/esm/dsl/Import.js +202 -0
  7. package/esm/dsl/operation/OperationBase.d.ts +181 -1
  8. package/esm/dsl/operation/OperationBase.d.ts.map +1 -1
  9. package/esm/dsl/operation/OperationBase.js +181 -1
  10. package/esm/oas/document/Document.d.ts +155 -1
  11. package/esm/oas/document/Document.d.ts.map +1 -1
  12. package/esm/oas/document/Document.js +141 -2
  13. package/esm/oas/object/Object.d.ts +255 -10
  14. package/esm/oas/object/Object.d.ts.map +1 -1
  15. package/esm/oas/object/Object.js +229 -10
  16. package/esm/types/GeneratorKeys.d.ts +336 -0
  17. package/esm/types/GeneratorKeys.d.ts.map +1 -1
  18. package/esm/types/GeneratorKeys.js +243 -0
  19. package/esm/types/GeneratorType.d.ts +119 -0
  20. package/esm/types/GeneratorType.d.ts.map +1 -1
  21. package/esm/types/Method.d.ts +109 -0
  22. package/esm/types/Method.d.ts.map +1 -1
  23. package/esm/types/Method.js +84 -0
  24. package/package.json +1 -1
  25. package/script/dsl/Identifier.d.ts +152 -0
  26. package/script/dsl/Identifier.d.ts.map +1 -1
  27. package/script/dsl/Identifier.js +152 -0
  28. package/script/dsl/Import.d.ts +221 -0
  29. package/script/dsl/Import.d.ts.map +1 -1
  30. package/script/dsl/Import.js +202 -0
  31. package/script/dsl/operation/OperationBase.d.ts +181 -1
  32. package/script/dsl/operation/OperationBase.d.ts.map +1 -1
  33. package/script/dsl/operation/OperationBase.js +181 -1
  34. package/script/oas/document/Document.d.ts +155 -1
  35. package/script/oas/document/Document.d.ts.map +1 -1
  36. package/script/oas/document/Document.js +141 -2
  37. package/script/oas/object/Object.d.ts +255 -10
  38. package/script/oas/object/Object.d.ts.map +1 -1
  39. package/script/oas/object/Object.js +229 -10
  40. package/script/types/GeneratorKeys.d.ts +336 -0
  41. package/script/types/GeneratorKeys.d.ts.map +1 -1
  42. package/script/types/GeneratorKeys.js +243 -0
  43. package/script/types/GeneratorType.d.ts +119 -0
  44. package/script/types/GeneratorType.d.ts.map +1 -1
  45. package/script/types/Method.d.ts +109 -0
  46. package/script/types/Method.d.ts.map +1 -1
  47. package/script/types/Method.js +84 -0
@@ -1,14 +1,104 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ImportName = exports.Import = void 0;
4
+ /**
5
+ * Represents a TypeScript import statement in the SKMTC DSL system.
6
+ *
7
+ * The `Import` class generates properly formatted import statements for TypeScript
8
+ * files, handling named imports with optional aliases. It's used throughout the
9
+ * code generation pipeline to manage module dependencies.
10
+ *
11
+ * This class supports both simple string imports and aliased imports, making it
12
+ * easy to avoid naming conflicts and provide cleaner import statements.
13
+ *
14
+ * @example Basic named imports
15
+ * ```typescript
16
+ * import { Import } from '@skmtc/core';
17
+ *
18
+ * const basicImport = new Import({
19
+ * module: './types',
20
+ * importNames: ['User', 'Product', 'Order']
21
+ * });
22
+ *
23
+ * console.log(basicImport.toString());
24
+ * // import { User, Product, Order } from './types'
25
+ * ```
26
+ *
27
+ * @example Imports with aliases
28
+ * ```typescript
29
+ * const aliasedImport = new Import({
30
+ * module: 'react',
31
+ * importNames: [
32
+ * 'useState',
33
+ * 'useEffect',
34
+ * { 'default': 'React' } // Import default as React
35
+ * ]
36
+ * });
37
+ *
38
+ * console.log(aliasedImport.toString());
39
+ * // import { useState, useEffect, default as React } from 'react'
40
+ * ```
41
+ *
42
+ * @example Mixed imports
43
+ * ```typescript
44
+ * const mixedImport = new Import({
45
+ * module: './api/client',
46
+ * importNames: [
47
+ * 'ApiClient',
48
+ * { 'RequestOptions': 'Options' }, // Alias to avoid conflicts
49
+ * 'ResponseType'
50
+ * ]
51
+ * });
52
+ *
53
+ * console.log(mixedImport.toString());
54
+ * // import { ApiClient, RequestOptions as Options, ResponseType } from './api/client'
55
+ * ```
56
+ *
57
+ * @example Using in File generation
58
+ * ```typescript
59
+ * import { File, Import } from '@skmtc/core';
60
+ *
61
+ * const file = new File({ path: './generated.ts', settings: undefined });
62
+ *
63
+ * // Add import to file
64
+ * file.imports.set('./types', new Set(['User', 'Product']));
65
+ *
66
+ * // Or create Import directly for more control
67
+ * const customImport = new Import({
68
+ * module: './helpers',
69
+ * importNames: [{ 'validateEmail': 'emailValidator' }]
70
+ * });
71
+ * ```
72
+ */
4
73
  class Import {
74
+ /**
75
+ * Creates a new Import instance.
76
+ *
77
+ * @param args - Import configuration
78
+ * @param args.module - The module path to import from (e.g., './types', 'react')
79
+ * @param args.importNames - Array of import names, can be strings or alias objects
80
+ *
81
+ * @example
82
+ * ```typescript
83
+ * const importStatement = new Import({
84
+ * module: './models/User',
85
+ * importNames: [
86
+ * 'User', // Simple import
87
+ * { 'UserType': 'IUser' }, // Aliased import
88
+ * 'createUser' // Another simple import
89
+ * ]
90
+ * });
91
+ * ```
92
+ */
5
93
  constructor({ module, importNames }) {
94
+ /** The module path to import from */
6
95
  Object.defineProperty(this, "module", {
7
96
  enumerable: true,
8
97
  configurable: true,
9
98
  writable: true,
10
99
  value: void 0
11
100
  });
101
+ /** Array of parsed import names with potential aliases */
12
102
  Object.defineProperty(this, "importNames", {
13
103
  enumerable: true,
14
104
  configurable: true,
@@ -18,11 +108,64 @@ class Import {
18
108
  this.module = module;
19
109
  this.importNames = importNames.map(importName => new ImportName(importName));
20
110
  }
111
+ /**
112
+ * Converts the import to a record format.
113
+ *
114
+ * This method creates a record representation where the module path is the key
115
+ * and the import names are the value. Useful for serialization or when working
116
+ * with import maps.
117
+ *
118
+ * @returns A record with module as key and import names as value
119
+ *
120
+ * @example
121
+ * ```typescript
122
+ * const importStatement = new Import({
123
+ * module: './types',
124
+ * importNames: ['User', { 'Product': 'IProduct' }]
125
+ * });
126
+ *
127
+ * const record = importStatement.toRecord();
128
+ * console.log(record);
129
+ * // {
130
+ * // './types': ['User', { 'Product': 'IProduct' }]
131
+ * // }
132
+ * ```
133
+ */
21
134
  toRecord() {
22
135
  return {
23
136
  [this.module]: this.importNames.map(({ name, alias }) => alias ? { [name]: alias } : name)
24
137
  };
25
138
  }
139
+ /**
140
+ * Generates the TypeScript import statement string.
141
+ *
142
+ * This method produces a properly formatted ES6 import statement that can be
143
+ * written directly to a TypeScript file. It handles both simple and aliased
144
+ * imports correctly.
145
+ *
146
+ * @returns The formatted import statement string
147
+ *
148
+ * @example
149
+ * ```typescript
150
+ * const basicImport = new Import({
151
+ * module: './utils',
152
+ * importNames: ['formatDate', 'parseJson']
153
+ * });
154
+ *
155
+ * console.log(basicImport.toString());
156
+ * // import { formatDate, parseJson } from './utils'
157
+ *
158
+ * const aliasedImport = new Import({
159
+ * module: 'lodash',
160
+ * importNames: [{ 'isEqual': 'deepEqual' }, 'cloneDeep']
161
+ * });
162
+ *
163
+ * console.log(aliasedImport.toString());
164
+ * // import { isEqual as deepEqual, cloneDeep } from 'lodash'
165
+ * ```
166
+ *
167
+ * @todo Move syntax to typescript package to enable language-agnostic use
168
+ */
26
169
  toString() {
27
170
  // @TODO move syntax to typescript package to enable
28
171
  // language agnostic use
@@ -30,14 +173,52 @@ class Import {
30
173
  }
31
174
  }
32
175
  exports.Import = Import;
176
+ /**
177
+ * Represents a single import name with optional aliasing.
178
+ *
179
+ * This class handles the parsing and formatting of individual import specifiers,
180
+ * supporting both simple imports and aliased imports. It's used internally by
181
+ * the {@link Import} class to manage import statement components.
182
+ *
183
+ * @example Simple import name
184
+ * ```typescript
185
+ * const simple = new ImportName('useState');
186
+ * console.log(simple.toString()); // 'useState'
187
+ * ```
188
+ *
189
+ * @example Aliased import name
190
+ * ```typescript
191
+ * const aliased = new ImportName({ 'React': 'ReactLib' });
192
+ * console.log(aliased.toString()); // 'React as ReactLib'
193
+ * ```
194
+ */
33
195
  class ImportName {
196
+ /**
197
+ * Creates a new ImportName instance.
198
+ *
199
+ * @param name - Either a string for simple imports or an object for aliased imports
200
+ *
201
+ * @example Simple import
202
+ * ```typescript
203
+ * const importName = new ImportName('User');
204
+ * // Results in: User
205
+ * ```
206
+ *
207
+ * @example Aliased import
208
+ * ```typescript
209
+ * const importName = new ImportName({ 'UserInterface': 'IUser' });
210
+ * // Results in: UserInterface as IUser
211
+ * ```
212
+ */
34
213
  constructor(name) {
214
+ /** The original name being imported */
35
215
  Object.defineProperty(this, "name", {
36
216
  enumerable: true,
37
217
  configurable: true,
38
218
  writable: true,
39
219
  value: void 0
40
220
  });
221
+ /** The alias to use (if any) */
41
222
  Object.defineProperty(this, "alias", {
42
223
  enumerable: true,
43
224
  configurable: true,
@@ -53,6 +234,27 @@ class ImportName {
53
234
  this.alias = alias;
54
235
  }
55
236
  }
237
+ /**
238
+ * Generates the string representation of the import name.
239
+ *
240
+ * This method creates the appropriate import specifier syntax,
241
+ * either a simple name or an aliased import using TypeScript's
242
+ * 'as' keyword.
243
+ *
244
+ * @returns The formatted import specifier string
245
+ *
246
+ * @example Simple import
247
+ * ```typescript
248
+ * const simple = new ImportName('useState');
249
+ * console.log(simple.toString()); // 'useState'
250
+ * ```
251
+ *
252
+ * @example Aliased import
253
+ * ```typescript
254
+ * const aliased = new ImportName({ 'Component': 'ReactComponent' });
255
+ * console.log(aliased.toString()); // 'Component as ReactComponent'
256
+ * ```
257
+ */
56
258
  toString() {
57
259
  return this.alias ? `${this.name} as ${this.alias}` : this.name;
58
260
  }
@@ -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
- /** @experimental */
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,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,OAAO,EAAE,MAAM,wBAAwB,CAAA;AAEhD;;;;GAIG;AACH,MAAM,MAAM,iBAAiB,CAAC,cAAc,GAAG,SAAS,IAAI;IAC1D,yEAA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V,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"}
@@ -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
- /** @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
+ */
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,