@skmtc/core 0.0.782 → 0.0.785

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 (61) hide show
  1. package/esm/context/CoreContext.d.ts +175 -0
  2. package/esm/context/CoreContext.d.ts.map +1 -1
  3. package/esm/context/CoreContext.js +178 -0
  4. package/esm/dsl/ContentBase.d.ts +115 -0
  5. package/esm/dsl/ContentBase.d.ts.map +1 -1
  6. package/esm/dsl/ContentBase.js +110 -0
  7. package/esm/dsl/File.d.ts +208 -0
  8. package/esm/dsl/File.d.ts.map +1 -1
  9. package/esm/dsl/File.js +197 -0
  10. package/esm/dsl/model/ModelBase.d.ts +257 -0
  11. package/esm/dsl/model/ModelBase.d.ts.map +1 -1
  12. package/esm/dsl/model/ModelBase.js +248 -0
  13. package/esm/dsl/operation/OperationBase.d.ts +175 -0
  14. package/esm/dsl/operation/OperationBase.d.ts.map +1 -1
  15. package/esm/dsl/operation/OperationBase.js +166 -0
  16. package/esm/helpers/strings.d.ts +63 -0
  17. package/esm/helpers/strings.d.ts.map +1 -1
  18. package/esm/helpers/strings.js +59 -0
  19. package/esm/mod.d.ts +66 -0
  20. package/esm/mod.d.ts.map +1 -1
  21. package/esm/mod.js +66 -0
  22. package/esm/run/toArtifacts.d.ts +114 -0
  23. package/esm/run/toArtifacts.d.ts.map +1 -1
  24. package/esm/run/toArtifacts.js +86 -0
  25. package/esm/types/Settings.d.ts +129 -0
  26. package/esm/types/Settings.d.ts.map +1 -1
  27. package/esm/types/Settings.js +3 -0
  28. package/esm/typescript/List.d.ts +111 -0
  29. package/esm/typescript/List.d.ts.map +1 -1
  30. package/esm/typescript/List.js +106 -0
  31. package/package.json +5 -1
  32. package/script/context/CoreContext.d.ts +175 -0
  33. package/script/context/CoreContext.d.ts.map +1 -1
  34. package/script/context/CoreContext.js +178 -0
  35. package/script/dsl/ContentBase.d.ts +115 -0
  36. package/script/dsl/ContentBase.d.ts.map +1 -1
  37. package/script/dsl/ContentBase.js +110 -0
  38. package/script/dsl/File.d.ts +208 -0
  39. package/script/dsl/File.d.ts.map +1 -1
  40. package/script/dsl/File.js +197 -0
  41. package/script/dsl/model/ModelBase.d.ts +257 -0
  42. package/script/dsl/model/ModelBase.d.ts.map +1 -1
  43. package/script/dsl/model/ModelBase.js +248 -0
  44. package/script/dsl/operation/OperationBase.d.ts +175 -0
  45. package/script/dsl/operation/OperationBase.d.ts.map +1 -1
  46. package/script/dsl/operation/OperationBase.js +166 -0
  47. package/script/helpers/strings.d.ts +63 -0
  48. package/script/helpers/strings.d.ts.map +1 -1
  49. package/script/helpers/strings.js +59 -0
  50. package/script/mod.d.ts +66 -0
  51. package/script/mod.d.ts.map +1 -1
  52. package/script/mod.js +66 -0
  53. package/script/run/toArtifacts.d.ts +114 -0
  54. package/script/run/toArtifacts.d.ts.map +1 -1
  55. package/script/run/toArtifacts.js +86 -0
  56. package/script/types/Settings.d.ts +129 -0
  57. package/script/types/Settings.d.ts.map +1 -1
  58. package/script/types/Settings.js +3 -0
  59. package/script/typescript/List.d.ts +111 -0
  60. package/script/typescript/List.d.ts.map +1 -1
  61. package/script/typescript/List.js +106 -0
@@ -9,19 +9,276 @@ import type { Inserted } from '../Inserted.js';
9
9
  import type { OasSchema } from '../../oas/schema/Schema.js';
10
10
  import type { OasRef } from '../../oas/ref/Ref.js';
11
11
  import { OasVoid } from '../../oas/void/Void.js';
12
+ /**
13
+ * Constructor arguments for {@link ModelBase}.
14
+ *
15
+ * @template EnrichmentType - Optional type for custom enrichment data
16
+ */
12
17
  export type ModelBaseArgs<EnrichmentType = undefined> = {
18
+ /** The generation context providing access to the processing pipeline */
13
19
  context: GenerateContext;
20
+ /** Content settings including export path and enrichment configuration */
14
21
  settings: ContentSettings<EnrichmentType>;
22
+ /** Unique identifier for this generator type */
15
23
  generatorKey: GeneratorKey;
24
+ /** Reference name for the model being generated */
16
25
  refName: RefName;
17
26
  };
27
+ /**
28
+ * Base class for model generators in the SKMTC DSL system.
29
+ *
30
+ * `ModelBase` extends {@link ContentBase} to provide specialized functionality for
31
+ * generating code from OpenAPI schema models. It offers type-safe methods for
32
+ * inserting related models, managing schema references, and handling enrichments.
33
+ *
34
+ * This class serves as the foundation for creating custom model generators that
35
+ * transform OpenAPI schemas into various code artifacts like TypeScript interfaces,
36
+ * validation schemas, or database models.
37
+ *
38
+ * ## Key Features
39
+ *
40
+ * - **Model Insertion**: Insert related models with automatic reference resolution
41
+ * - **Schema Normalization**: Handle complex schema references and fallbacks
42
+ * - **Export Management**: Control which models are exported from generated files
43
+ * - **Enrichment Support**: Extend functionality with custom enrichment data
44
+ * - **Type Safety**: Full TypeScript support with generic enrichment types
45
+ *
46
+ * @template EnrichmentType - Optional type for custom enrichment data
47
+ *
48
+ * @example Basic model generator
49
+ * ```typescript
50
+ * import { ModelBase, Definition } from '@skmtc/core';
51
+ *
52
+ * class TypeScriptInterface extends ModelBase {
53
+ * toDefinition(): Definition {
54
+ * const schema = this.context.getSchema(this.refName);
55
+ *
56
+ * return new Definition({
57
+ * name: this.refName,
58
+ * content: `export interface ${this.refName} {
59
+ * ${this.generateProperties(schema)}
60
+ * }`
61
+ * });
62
+ * }
63
+ *
64
+ * private generateProperties(schema: OasSchema): string {
65
+ * // Generate interface properties from schema
66
+ * return Object.entries(schema.properties || {})
67
+ * .map(([key, prop]) => `${key}: ${this.getPropertyType(prop)}`)
68
+ * .join(';\n ');
69
+ * }
70
+ * }
71
+ * ```
72
+ *
73
+ * @example With enrichments
74
+ * ```typescript
75
+ * type ValidationEnrichment = {
76
+ * validators: string[];
77
+ * customRules: Record<string, string>;
78
+ * };
79
+ *
80
+ * class ValidationModel extends ModelBase<ValidationEnrichment> {
81
+ * toDefinition(): Definition {
82
+ * const enrichment = this.settings.enrichment;
83
+ * const validators = enrichment?.validators || [];
84
+ *
85
+ * return new Definition({
86
+ * name: `${this.refName}Validator`,
87
+ * content: this.generateValidator(validators)
88
+ * });
89
+ * }
90
+ * }
91
+ * ```
92
+ *
93
+ * @example Inserting related models
94
+ * ```typescript
95
+ * class ApiModel extends ModelBase {
96
+ * toDefinition(): Definition {
97
+ * const schema = this.context.getSchema(this.refName);
98
+ *
99
+ * // Insert related models automatically
100
+ * if (schema.properties?.user) {
101
+ * this.insertNormalizedModel(
102
+ * new TypeScriptInterface({ ... }),
103
+ * { schema: schema.properties.user, fallbackName: 'User' }
104
+ * );
105
+ * }
106
+ *
107
+ * return new Definition({
108
+ * name: this.refName,
109
+ * content: this.generateInterface(schema)
110
+ * });
111
+ * }
112
+ * }
113
+ * ```
114
+ */
18
115
  export declare class ModelBase<EnrichmentType = undefined> extends ContentBase {
116
+ /** Content settings including export path and enrichment configuration */
19
117
  settings: ContentSettings<EnrichmentType>;
118
+ /** Reference name for the model being generated */
20
119
  refName: RefName;
120
+ /** Generator key identifying this generator type */
21
121
  generatorKey: GeneratorKey;
122
+ /**
123
+ * Creates a new ModelBase instance.
124
+ *
125
+ * @param args - Model generator configuration
126
+ * @param args.context - The generation context providing pipeline access
127
+ * @param args.settings - Content settings with export path and enrichments
128
+ * @param args.generatorKey - Unique identifier for this generator type
129
+ * @param args.refName - Reference name for the model being generated
130
+ *
131
+ * @example
132
+ * ```typescript
133
+ * const model = new ModelBase({
134
+ * context: generateContext,
135
+ * settings: {
136
+ * exportPath: './src/models.ts',
137
+ * enrichment: customEnrichments
138
+ * },
139
+ * generatorKey: 'typescript-models',
140
+ * refName: 'UserModel'
141
+ * });
142
+ * ```
143
+ */
22
144
  constructor({ context, settings, generatorKey, refName }: ModelBaseArgs<EnrichmentType>);
145
+ /**
146
+ * Inserts a related model with forced generation.
147
+ *
148
+ * This method adds a related model to the current generation context, ensuring
149
+ * it will be generated regardless of whether it already exists. The inserted
150
+ * model will be exported to the same destination path as this model unless
151
+ * `noExport` is specified.
152
+ *
153
+ * @template V - Type of generated value returned by the insertable
154
+ * @template EnrichmentType - Type of enrichment data for the insertable
155
+ * @param insertable - The model generator to insert
156
+ * @param refName - Reference name for the inserted model
157
+ * @param options - Insertion options
158
+ * @param options.noExport - Whether to skip exporting the inserted model
159
+ * @returns Inserted model reference with generated value
160
+ *
161
+ * @example
162
+ * ```typescript
163
+ * class UserModel extends ModelBase {
164
+ * toDefinition(): Definition {
165
+ * // Insert an address model that's always generated
166
+ * const address = this.insertModel(
167
+ * new AddressModel({ ... }),
168
+ * 'Address',
169
+ * { noExport: false }
170
+ * );
171
+ *
172
+ * return new Definition({
173
+ * name: this.refName,
174
+ * content: `export interface ${this.refName} {
175
+ * address: ${address.value}
176
+ * }`
177
+ * });
178
+ * }
179
+ * }
180
+ * ```
181
+ */
23
182
  insertModel<V extends GeneratedValue, EnrichmentType = undefined>(insertable: ModelInsertable<V, EnrichmentType>, refName: RefName, options?: Pick<InsertModelOptions<'force'>, 'noExport'>): Inserted<V, 'force', EnrichmentType>;
183
+ /**
184
+ * Inserts a related model with automatic schema normalization and reference resolution.
185
+ *
186
+ * This method intelligently handles schema references by automatically resolving
187
+ * them to appropriate model names. If the schema is a reference, it uses the
188
+ * referenced name; otherwise it falls back to the provided fallback name.
189
+ *
190
+ * This is particularly useful when working with complex nested schemas where
191
+ * you want to automatically generate models for referenced types.
192
+ *
193
+ * @template V - Type of generated value returned by the insertable
194
+ * @template Schema - Type of OpenAPI schema (schema object, reference, or void)
195
+ * @template EnrichmentType - Type of enrichment data for the insertable
196
+ * @param insertable - The model generator to insert
197
+ * @param args - Schema normalization arguments
198
+ * @param args.schema - The OpenAPI schema to normalize (can be reference or actual schema)
199
+ * @param args.fallbackName - Name to use if schema is not a reference
200
+ * @param options - Insertion options
201
+ * @param options.noExport - Whether to skip exporting the inserted model
202
+ * @returns Inserted model reference with normalized name and generated value
203
+ *
204
+ * @example Handling schema references
205
+ * ```typescript
206
+ * class OrderModel extends ModelBase {
207
+ * toDefinition(): Definition {
208
+ * const schema = this.context.getSchema(this.refName);
209
+ *
210
+ * // Handle customer property - could be reference or inline schema
211
+ * if (schema.properties?.customer) {
212
+ * const customer = this.insertNormalizedModel(
213
+ * new CustomerModel({ ... }),
214
+ * {
215
+ * schema: schema.properties.customer,
216
+ * fallbackName: 'Customer'
217
+ * }
218
+ * );
219
+ * // customer.refName will be 'Customer' or the referenced schema name
220
+ * }
221
+ *
222
+ * return new Definition({ ... });
223
+ * }
224
+ * }
225
+ * ```
226
+ *
227
+ * @example With complex nested schemas
228
+ * ```typescript
229
+ * // If schema.properties.items is { $ref: '#/components/schemas/Product' }
230
+ * // Then the inserted model will use refName 'Product'
231
+ * const items = this.insertNormalizedModel(
232
+ * new ProductModel({ ... }),
233
+ * {
234
+ * schema: schema.properties.items,
235
+ * fallbackName: 'Item' // Won't be used since schema has $ref
236
+ * }
237
+ * );
238
+ * ```
239
+ */
24
240
  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>;
241
+ /**
242
+ * Registers a file-level artifact with the generation context.
243
+ *
244
+ * This method allows the model generator to register additional content
245
+ * (like imports, exports, or file-level definitions) that should be included
246
+ * in the generated file. The registration is automatically scoped to this
247
+ * model's export path.
248
+ *
249
+ * @param args - Registration arguments
250
+ * @param args.content - The content to register (import, export, etc.)
251
+ * @param args.phase - When to register the content ('pre' or 'post')
252
+ *
253
+ * @example Registering imports
254
+ * ```typescript
255
+ * class ApiModel extends ModelBase {
256
+ * toDefinition(): Definition {
257
+ * // Register an import that all generated models need
258
+ * this.register({
259
+ * content: "import { BaseModel } from './base';",
260
+ * phase: 'pre'
261
+ * });
262
+ *
263
+ * return new Definition({ ... });
264
+ * }
265
+ * }
266
+ * ```
267
+ *
268
+ * @example Registering type exports
269
+ * ```typescript
270
+ * class TypeModel extends ModelBase {
271
+ * toDefinition(): Definition {
272
+ * this.register({
273
+ * content: "export type * from './types';",
274
+ * phase: 'post'
275
+ * });
276
+ *
277
+ * return new Definition({ ... });
278
+ * }
279
+ * }
280
+ * ```
281
+ */
25
282
  register(args: BaseRegisterArgs): void;
26
283
  }
27
284
  //# sourceMappingURL=ModelBase.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ModelBase.d.ts","sourceRoot":"","sources":["../../../src/dsl/model/ModelBase.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,gBAAgB,EAChB,eAAe,EACf,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,KAAK,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAA;AACrD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAA;AAC5D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AACjD,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAC/C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AAC9C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAA;AAC3D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAA;AAGlD,OAAO,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAA;AAEhD,MAAM,MAAM,aAAa,CAAC,cAAc,GAAG,SAAS,IAAI;IACtD,OAAO,EAAE,eAAe,CAAA;IACxB,QAAQ,EAAE,eAAe,CAAC,cAAc,CAAC,CAAA;IACzC,YAAY,EAAE,YAAY,CAAA;IAC1B,OAAO,EAAE,OAAO,CAAA;CACjB,CAAA;AAED,qBAAa,SAAS,CAAC,cAAc,GAAG,SAAS,CAAE,SAAQ,WAAW;IACpE,QAAQ,EAAE,eAAe,CAAC,cAAc,CAAC,CAAA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AW,CAAC,CAAC,SAAS,cAAc,EAAE,cAAc,GAAG,SAAS,EAC9D,UAAU,EAAE,eAAe,CAAC,CAAC,EAAE,cAAc,CAAC,EAC9C,OAAO,EAAE,OAAO,EAChB,OAAO,GAAE,IAAI,CAAC,kBAAkB,CAAC,OAAO,CAAC,EAAE,UAAU,CAAM,GAC1D,QAAQ,CAAC,CAAC,EAAE,OAAO,EAAE,cAAc,CAAC;IAQvC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAwDG;IACH,qBAAqB,CACnB,CAAC,SAAS,cAAc,EACxB,MAAM,SAAS,SAAS,GAAG,MAAM,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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAwCG;IACM,QAAQ,CAAC,IAAI,EAAE,gBAAgB,GAAG,IAAI;CAMhD"}
@@ -2,21 +2,134 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ModelBase = void 0;
4
4
  const ContentBase_js_1 = require("../ContentBase.js");
5
+ /**
6
+ * Base class for model generators in the SKMTC DSL system.
7
+ *
8
+ * `ModelBase` extends {@link ContentBase} to provide specialized functionality for
9
+ * generating code from OpenAPI schema models. It offers type-safe methods for
10
+ * inserting related models, managing schema references, and handling enrichments.
11
+ *
12
+ * This class serves as the foundation for creating custom model generators that
13
+ * transform OpenAPI schemas into various code artifacts like TypeScript interfaces,
14
+ * validation schemas, or database models.
15
+ *
16
+ * ## Key Features
17
+ *
18
+ * - **Model Insertion**: Insert related models with automatic reference resolution
19
+ * - **Schema Normalization**: Handle complex schema references and fallbacks
20
+ * - **Export Management**: Control which models are exported from generated files
21
+ * - **Enrichment Support**: Extend functionality with custom enrichment data
22
+ * - **Type Safety**: Full TypeScript support with generic enrichment types
23
+ *
24
+ * @template EnrichmentType - Optional type for custom enrichment data
25
+ *
26
+ * @example Basic model generator
27
+ * ```typescript
28
+ * import { ModelBase, Definition } from '@skmtc/core';
29
+ *
30
+ * class TypeScriptInterface extends ModelBase {
31
+ * toDefinition(): Definition {
32
+ * const schema = this.context.getSchema(this.refName);
33
+ *
34
+ * return new Definition({
35
+ * name: this.refName,
36
+ * content: `export interface ${this.refName} {
37
+ * ${this.generateProperties(schema)}
38
+ * }`
39
+ * });
40
+ * }
41
+ *
42
+ * private generateProperties(schema: OasSchema): string {
43
+ * // Generate interface properties from schema
44
+ * return Object.entries(schema.properties || {})
45
+ * .map(([key, prop]) => `${key}: ${this.getPropertyType(prop)}`)
46
+ * .join(';\n ');
47
+ * }
48
+ * }
49
+ * ```
50
+ *
51
+ * @example With enrichments
52
+ * ```typescript
53
+ * type ValidationEnrichment = {
54
+ * validators: string[];
55
+ * customRules: Record<string, string>;
56
+ * };
57
+ *
58
+ * class ValidationModel extends ModelBase<ValidationEnrichment> {
59
+ * toDefinition(): Definition {
60
+ * const enrichment = this.settings.enrichment;
61
+ * const validators = enrichment?.validators || [];
62
+ *
63
+ * return new Definition({
64
+ * name: `${this.refName}Validator`,
65
+ * content: this.generateValidator(validators)
66
+ * });
67
+ * }
68
+ * }
69
+ * ```
70
+ *
71
+ * @example Inserting related models
72
+ * ```typescript
73
+ * class ApiModel extends ModelBase {
74
+ * toDefinition(): Definition {
75
+ * const schema = this.context.getSchema(this.refName);
76
+ *
77
+ * // Insert related models automatically
78
+ * if (schema.properties?.user) {
79
+ * this.insertNormalizedModel(
80
+ * new TypeScriptInterface({ ... }),
81
+ * { schema: schema.properties.user, fallbackName: 'User' }
82
+ * );
83
+ * }
84
+ *
85
+ * return new Definition({
86
+ * name: this.refName,
87
+ * content: this.generateInterface(schema)
88
+ * });
89
+ * }
90
+ * }
91
+ * ```
92
+ */
5
93
  class ModelBase extends ContentBase_js_1.ContentBase {
94
+ /**
95
+ * Creates a new ModelBase instance.
96
+ *
97
+ * @param args - Model generator configuration
98
+ * @param args.context - The generation context providing pipeline access
99
+ * @param args.settings - Content settings with export path and enrichments
100
+ * @param args.generatorKey - Unique identifier for this generator type
101
+ * @param args.refName - Reference name for the model being generated
102
+ *
103
+ * @example
104
+ * ```typescript
105
+ * const model = new ModelBase({
106
+ * context: generateContext,
107
+ * settings: {
108
+ * exportPath: './src/models.ts',
109
+ * enrichment: customEnrichments
110
+ * },
111
+ * generatorKey: 'typescript-models',
112
+ * refName: 'UserModel'
113
+ * });
114
+ * ```
115
+ */
6
116
  constructor({ context, settings, generatorKey, refName }) {
7
117
  super({ context });
118
+ /** Content settings including export path and enrichment configuration */
8
119
  Object.defineProperty(this, "settings", {
9
120
  enumerable: true,
10
121
  configurable: true,
11
122
  writable: true,
12
123
  value: void 0
13
124
  });
125
+ /** Reference name for the model being generated */
14
126
  Object.defineProperty(this, "refName", {
15
127
  enumerable: true,
16
128
  configurable: true,
17
129
  writable: true,
18
130
  value: void 0
19
131
  });
132
+ /** Generator key identifying this generator type */
20
133
  Object.defineProperty(this, "generatorKey", {
21
134
  enumerable: true,
22
135
  configurable: true,
@@ -27,6 +140,43 @@ class ModelBase extends ContentBase_js_1.ContentBase {
27
140
  this.refName = refName;
28
141
  this.settings = settings;
29
142
  }
143
+ /**
144
+ * Inserts a related model with forced generation.
145
+ *
146
+ * This method adds a related model to the current generation context, ensuring
147
+ * it will be generated regardless of whether it already exists. The inserted
148
+ * model will be exported to the same destination path as this model unless
149
+ * `noExport` is specified.
150
+ *
151
+ * @template V - Type of generated value returned by the insertable
152
+ * @template EnrichmentType - Type of enrichment data for the insertable
153
+ * @param insertable - The model generator to insert
154
+ * @param refName - Reference name for the inserted model
155
+ * @param options - Insertion options
156
+ * @param options.noExport - Whether to skip exporting the inserted model
157
+ * @returns Inserted model reference with generated value
158
+ *
159
+ * @example
160
+ * ```typescript
161
+ * class UserModel extends ModelBase {
162
+ * toDefinition(): Definition {
163
+ * // Insert an address model that's always generated
164
+ * const address = this.insertModel(
165
+ * new AddressModel({ ... }),
166
+ * 'Address',
167
+ * { noExport: false }
168
+ * );
169
+ *
170
+ * return new Definition({
171
+ * name: this.refName,
172
+ * content: `export interface ${this.refName} {
173
+ * address: ${address.value}
174
+ * }`
175
+ * });
176
+ * }
177
+ * }
178
+ * ```
179
+ */
30
180
  insertModel(insertable, refName, options = {}) {
31
181
  return this.context.insertModel(insertable, refName, {
32
182
  generation: 'force',
@@ -34,6 +184,63 @@ class ModelBase extends ContentBase_js_1.ContentBase {
34
184
  noExport: options.noExport
35
185
  });
36
186
  }
187
+ /**
188
+ * Inserts a related model with automatic schema normalization and reference resolution.
189
+ *
190
+ * This method intelligently handles schema references by automatically resolving
191
+ * them to appropriate model names. If the schema is a reference, it uses the
192
+ * referenced name; otherwise it falls back to the provided fallback name.
193
+ *
194
+ * This is particularly useful when working with complex nested schemas where
195
+ * you want to automatically generate models for referenced types.
196
+ *
197
+ * @template V - Type of generated value returned by the insertable
198
+ * @template Schema - Type of OpenAPI schema (schema object, reference, or void)
199
+ * @template EnrichmentType - Type of enrichment data for the insertable
200
+ * @param insertable - The model generator to insert
201
+ * @param args - Schema normalization arguments
202
+ * @param args.schema - The OpenAPI schema to normalize (can be reference or actual schema)
203
+ * @param args.fallbackName - Name to use if schema is not a reference
204
+ * @param options - Insertion options
205
+ * @param options.noExport - Whether to skip exporting the inserted model
206
+ * @returns Inserted model reference with normalized name and generated value
207
+ *
208
+ * @example Handling schema references
209
+ * ```typescript
210
+ * class OrderModel extends ModelBase {
211
+ * toDefinition(): Definition {
212
+ * const schema = this.context.getSchema(this.refName);
213
+ *
214
+ * // Handle customer property - could be reference or inline schema
215
+ * if (schema.properties?.customer) {
216
+ * const customer = this.insertNormalizedModel(
217
+ * new CustomerModel({ ... }),
218
+ * {
219
+ * schema: schema.properties.customer,
220
+ * fallbackName: 'Customer'
221
+ * }
222
+ * );
223
+ * // customer.refName will be 'Customer' or the referenced schema name
224
+ * }
225
+ *
226
+ * return new Definition({ ... });
227
+ * }
228
+ * }
229
+ * ```
230
+ *
231
+ * @example With complex nested schemas
232
+ * ```typescript
233
+ * // If schema.properties.items is { $ref: '#/components/schemas/Product' }
234
+ * // Then the inserted model will use refName 'Product'
235
+ * const items = this.insertNormalizedModel(
236
+ * new ProductModel({ ... }),
237
+ * {
238
+ * schema: schema.properties.items,
239
+ * fallbackName: 'Item' // Won't be used since schema has $ref
240
+ * }
241
+ * );
242
+ * ```
243
+ */
37
244
  insertNormalizedModel(insertable, { schema, fallbackName }, options = {}) {
38
245
  return this.context.insertNormalisedModel(insertable, {
39
246
  schema,
@@ -41,6 +248,47 @@ class ModelBase extends ContentBase_js_1.ContentBase {
41
248
  destinationPath: this.settings.exportPath
42
249
  }, options);
43
250
  }
251
+ /**
252
+ * Registers a file-level artifact with the generation context.
253
+ *
254
+ * This method allows the model generator to register additional content
255
+ * (like imports, exports, or file-level definitions) that should be included
256
+ * in the generated file. The registration is automatically scoped to this
257
+ * model's export path.
258
+ *
259
+ * @param args - Registration arguments
260
+ * @param args.content - The content to register (import, export, etc.)
261
+ * @param args.phase - When to register the content ('pre' or 'post')
262
+ *
263
+ * @example Registering imports
264
+ * ```typescript
265
+ * class ApiModel extends ModelBase {
266
+ * toDefinition(): Definition {
267
+ * // Register an import that all generated models need
268
+ * this.register({
269
+ * content: "import { BaseModel } from './base';",
270
+ * phase: 'pre'
271
+ * });
272
+ *
273
+ * return new Definition({ ... });
274
+ * }
275
+ * }
276
+ * ```
277
+ *
278
+ * @example Registering type exports
279
+ * ```typescript
280
+ * class TypeModel extends ModelBase {
281
+ * toDefinition(): Definition {
282
+ * this.register({
283
+ * content: "export type * from './types';",
284
+ * phase: 'post'
285
+ * });
286
+ *
287
+ * return new Definition({ ... });
288
+ * }
289
+ * }
290
+ * ```
291
+ */
44
292
  register(args) {
45
293
  this.context.register({
46
294
  ...args,