@skmtc/core 0.0.783 → 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.
- package/esm/dsl/File.d.ts +208 -0
- package/esm/dsl/File.d.ts.map +1 -1
- package/esm/dsl/File.js +197 -0
- package/esm/dsl/model/ModelBase.d.ts +257 -0
- package/esm/dsl/model/ModelBase.d.ts.map +1 -1
- package/esm/dsl/model/ModelBase.js +248 -0
- package/esm/dsl/operation/OperationBase.d.ts +175 -0
- package/esm/dsl/operation/OperationBase.d.ts.map +1 -1
- package/esm/dsl/operation/OperationBase.js +166 -0
- package/package.json +5 -1
- package/script/dsl/File.d.ts +208 -0
- package/script/dsl/File.d.ts.map +1 -1
- package/script/dsl/File.js +197 -0
- package/script/dsl/model/ModelBase.d.ts +257 -0
- package/script/dsl/model/ModelBase.d.ts.map +1 -1
- package/script/dsl/model/ModelBase.js +248 -0
- package/script/dsl/operation/OperationBase.d.ts +175 -0
- package/script/dsl/operation/OperationBase.d.ts.map +1 -1
- package/script/dsl/operation/OperationBase.js +166 -0
package/script/dsl/File.js
CHANGED
|
@@ -2,38 +2,142 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.normaliseModuleName = exports.File = void 0;
|
|
4
4
|
const Import_js_1 = require("./Import.js");
|
|
5
|
+
/**
|
|
6
|
+
* Represents a TypeScript file in the SKMTC DSL system.
|
|
7
|
+
*
|
|
8
|
+
* The `File` class is a core component for generating TypeScript files with proper
|
|
9
|
+
* import management, re-exports, and content organization. It automatically handles
|
|
10
|
+
* module resolution, import optimization, and package-aware path normalization.
|
|
11
|
+
*
|
|
12
|
+
* ## Key Features
|
|
13
|
+
*
|
|
14
|
+
* - **Import Management**: Automatically tracks and organizes imports from other modules
|
|
15
|
+
* - **Re-export Handling**: Supports re-exporting symbols from other modules
|
|
16
|
+
* - **Package Awareness**: Handles module packages for complex project structures
|
|
17
|
+
* - **Definition Tracking**: Manages code definitions and their relationships
|
|
18
|
+
* - **Path Normalization**: Automatically resolves paths based on package configuration
|
|
19
|
+
*
|
|
20
|
+
* @example Basic file creation
|
|
21
|
+
* ```typescript
|
|
22
|
+
* import { File } from '@skmtc/core';
|
|
23
|
+
*
|
|
24
|
+
* const file = new File({
|
|
25
|
+
* path: './src/models/User.ts',
|
|
26
|
+
* settings: clientSettings
|
|
27
|
+
* });
|
|
28
|
+
*
|
|
29
|
+
* // Add imports
|
|
30
|
+
* file.imports.set('./types', new Set(['BaseModel', 'Validator']));
|
|
31
|
+
*
|
|
32
|
+
* // Add definitions
|
|
33
|
+
* file.definitions.set('User', userInterface);
|
|
34
|
+
*
|
|
35
|
+
* // Generate file content
|
|
36
|
+
* const content = file.toString();
|
|
37
|
+
* console.log(content);
|
|
38
|
+
* // import { BaseModel, Validator } from './types'
|
|
39
|
+
* //
|
|
40
|
+
* // export interface User extends BaseModel {
|
|
41
|
+
* // id: string;
|
|
42
|
+
* // name: string;
|
|
43
|
+
* // }
|
|
44
|
+
* ```
|
|
45
|
+
*
|
|
46
|
+
* @example With package configuration
|
|
47
|
+
* ```typescript
|
|
48
|
+
* const file = new File({
|
|
49
|
+
* path: './packages/client/src/api.ts',
|
|
50
|
+
* settings: {
|
|
51
|
+
* packages: [
|
|
52
|
+
* {
|
|
53
|
+
* rootPath: './packages/types',
|
|
54
|
+
* moduleName: '@myorg/types'
|
|
55
|
+
* }
|
|
56
|
+
* ]
|
|
57
|
+
* }
|
|
58
|
+
* });
|
|
59
|
+
*
|
|
60
|
+
* // Import from another package
|
|
61
|
+
* file.imports.set('./packages/types/models', new Set(['User']));
|
|
62
|
+
*
|
|
63
|
+
* // Will generate: import { User } from '@myorg/types/models'
|
|
64
|
+
* ```
|
|
65
|
+
*
|
|
66
|
+
* @example Re-exports
|
|
67
|
+
* ```typescript
|
|
68
|
+
* const file = new File({
|
|
69
|
+
* path: './src/index.ts',
|
|
70
|
+
* settings: clientSettings
|
|
71
|
+
* });
|
|
72
|
+
*
|
|
73
|
+
* // Add re-exports
|
|
74
|
+
* file.reExports.set('./models', {
|
|
75
|
+
* 'type': new Set(['User', 'Product']),
|
|
76
|
+
* 'const': new Set(['DEFAULT_CONFIG'])
|
|
77
|
+
* });
|
|
78
|
+
*
|
|
79
|
+
* // Will generate:
|
|
80
|
+
* // export type { User, Product } from './models'
|
|
81
|
+
* // export { DEFAULT_CONFIG } from './models'
|
|
82
|
+
* ```
|
|
83
|
+
*/
|
|
5
84
|
class File {
|
|
85
|
+
/**
|
|
86
|
+
* Creates a new File instance.
|
|
87
|
+
*
|
|
88
|
+
* @param args - File configuration
|
|
89
|
+
* @param args.path - The output path for this file
|
|
90
|
+
* @param args.settings - Client settings containing package configuration
|
|
91
|
+
*
|
|
92
|
+
* @example
|
|
93
|
+
* ```typescript
|
|
94
|
+
* const file = new File({
|
|
95
|
+
* path: './src/generated/models.ts',
|
|
96
|
+
* settings: {
|
|
97
|
+
* packages: [
|
|
98
|
+
* { rootPath: './packages/shared', moduleName: '@company/shared' }
|
|
99
|
+
* ]
|
|
100
|
+
* }
|
|
101
|
+
* });
|
|
102
|
+
* ```
|
|
103
|
+
*/
|
|
6
104
|
constructor({ path, settings }) {
|
|
105
|
+
/** The file type, always 'ts' for TypeScript files */
|
|
7
106
|
Object.defineProperty(this, "fileType", {
|
|
8
107
|
enumerable: true,
|
|
9
108
|
configurable: true,
|
|
10
109
|
writable: true,
|
|
11
110
|
value: 'ts'
|
|
12
111
|
});
|
|
112
|
+
/** The file path for this generated file */
|
|
13
113
|
Object.defineProperty(this, "path", {
|
|
14
114
|
enumerable: true,
|
|
15
115
|
configurable: true,
|
|
16
116
|
writable: true,
|
|
17
117
|
value: void 0
|
|
18
118
|
});
|
|
119
|
+
/** Map of module paths to re-exported symbols organized by export type */
|
|
19
120
|
Object.defineProperty(this, "reExports", {
|
|
20
121
|
enumerable: true,
|
|
21
122
|
configurable: true,
|
|
22
123
|
writable: true,
|
|
23
124
|
value: void 0
|
|
24
125
|
});
|
|
126
|
+
/** Map of module paths to imported symbols */
|
|
25
127
|
Object.defineProperty(this, "imports", {
|
|
26
128
|
enumerable: true,
|
|
27
129
|
configurable: true,
|
|
28
130
|
writable: true,
|
|
29
131
|
value: void 0
|
|
30
132
|
});
|
|
133
|
+
/** Map of definition names to their Definition objects */
|
|
31
134
|
Object.defineProperty(this, "definitions", {
|
|
32
135
|
enumerable: true,
|
|
33
136
|
configurable: true,
|
|
34
137
|
writable: true,
|
|
35
138
|
value: void 0
|
|
36
139
|
});
|
|
140
|
+
/** Package configuration for path resolution */
|
|
37
141
|
Object.defineProperty(this, "packages", {
|
|
38
142
|
enumerable: true,
|
|
39
143
|
configurable: true,
|
|
@@ -46,6 +150,47 @@ class File {
|
|
|
46
150
|
this.definitions = new Map();
|
|
47
151
|
this.packages = settings?.packages;
|
|
48
152
|
}
|
|
153
|
+
/**
|
|
154
|
+
* Generates the complete TypeScript file content.
|
|
155
|
+
*
|
|
156
|
+
* This method orchestrates the rendering of all file components in the correct order:
|
|
157
|
+
* re-exports first, then imports, and finally definitions. It automatically handles
|
|
158
|
+
* module path normalization based on package configuration and filters out empty sections.
|
|
159
|
+
*
|
|
160
|
+
* @returns The complete TypeScript file content as a string
|
|
161
|
+
*
|
|
162
|
+
* @example Basic file generation
|
|
163
|
+
* ```typescript
|
|
164
|
+
* const file = new File({ path: './api.ts', settings: undefined });
|
|
165
|
+
*
|
|
166
|
+
* // Add some imports and definitions
|
|
167
|
+
* file.imports.set('./types', new Set(['User', 'Product']));
|
|
168
|
+
* file.definitions.set('ApiClient', someDefinition);
|
|
169
|
+
*
|
|
170
|
+
* const content = file.toString();
|
|
171
|
+
* console.log(content);
|
|
172
|
+
* // import { User, Product } from './types'
|
|
173
|
+
* //
|
|
174
|
+
* // export class ApiClient {
|
|
175
|
+
* // // ... definition content
|
|
176
|
+
* // }
|
|
177
|
+
* ```
|
|
178
|
+
*
|
|
179
|
+
* @example With re-exports
|
|
180
|
+
* ```typescript
|
|
181
|
+
* const file = new File({ path: './index.ts', settings: undefined });
|
|
182
|
+
*
|
|
183
|
+
* file.reExports.set('./models', {
|
|
184
|
+
* 'type': new Set(['User', 'Product']),
|
|
185
|
+
* 'const': new Set(['DEFAULT_CONFIG'])
|
|
186
|
+
* });
|
|
187
|
+
*
|
|
188
|
+
* const content = file.toString();
|
|
189
|
+
* console.log(content);
|
|
190
|
+
* // export type { User, Product } from './models'
|
|
191
|
+
* // export { DEFAULT_CONFIG } from './models'
|
|
192
|
+
* ```
|
|
193
|
+
*/
|
|
49
194
|
toString() {
|
|
50
195
|
const reExports = Array.from(this.reExports.entries()).flatMap(([module, entityTypes]) => {
|
|
51
196
|
const updatedModuleName = (0, exports.normaliseModuleName)({
|
|
@@ -76,6 +221,58 @@ class File {
|
|
|
76
221
|
}
|
|
77
222
|
}
|
|
78
223
|
exports.File = File;
|
|
224
|
+
/**
|
|
225
|
+
* Normalizes module import/export paths based on package configuration.
|
|
226
|
+
*
|
|
227
|
+
* This function handles path resolution for complex project structures with multiple
|
|
228
|
+
* packages. It converts file system paths to appropriate module names based on:
|
|
229
|
+
* - Whether the destination and export paths are in the same package
|
|
230
|
+
* - Package-specific module naming conventions
|
|
231
|
+
* - Root path truncation for intra-package imports
|
|
232
|
+
*
|
|
233
|
+
* @param args - Path normalization arguments
|
|
234
|
+
* @param args.destinationPath - The path of the file that will contain the import/export
|
|
235
|
+
* @param args.exportPath - The original path being imported/exported from
|
|
236
|
+
* @param args.packages - Package configuration for path resolution (defaults to empty array)
|
|
237
|
+
* @returns The normalized module name to use in import/export statements
|
|
238
|
+
*
|
|
239
|
+
* @throws {Error} When a matching package is found but has no moduleName configured
|
|
240
|
+
*
|
|
241
|
+
* @example Cross-package import
|
|
242
|
+
* ```typescript
|
|
243
|
+
* const normalized = normaliseModuleName({
|
|
244
|
+
* destinationPath: './packages/client/src/api.ts',
|
|
245
|
+
* exportPath: './packages/types/models/User.ts',
|
|
246
|
+
* packages: [
|
|
247
|
+
* { rootPath: './packages/types', moduleName: '@company/types' },
|
|
248
|
+
* { rootPath: './packages/client', moduleName: '@company/client' }
|
|
249
|
+
* ]
|
|
250
|
+
* });
|
|
251
|
+
* console.log(normalized); // '@company/types'
|
|
252
|
+
* ```
|
|
253
|
+
*
|
|
254
|
+
* @example Intra-package import (same package)
|
|
255
|
+
* ```typescript
|
|
256
|
+
* const normalized = normaliseModuleName({
|
|
257
|
+
* destinationPath: './packages/types/src/index.ts',
|
|
258
|
+
* exportPath: './packages/types/models/User.ts',
|
|
259
|
+
* packages: [
|
|
260
|
+
* { rootPath: './packages/types', moduleName: '@company/types' }
|
|
261
|
+
* ]
|
|
262
|
+
* });
|
|
263
|
+
* console.log(normalized); // '@/models/User.ts' (truncates root path)
|
|
264
|
+
* ```
|
|
265
|
+
*
|
|
266
|
+
* @example No package match (returns original path)
|
|
267
|
+
* ```typescript
|
|
268
|
+
* const normalized = normaliseModuleName({
|
|
269
|
+
* destinationPath: './src/index.ts',
|
|
270
|
+
* exportPath: './src/utils.ts',
|
|
271
|
+
* packages: []
|
|
272
|
+
* });
|
|
273
|
+
* console.log(normalized); // './src/utils.ts'
|
|
274
|
+
* ```
|
|
275
|
+
*/
|
|
79
276
|
const normaliseModuleName = ({ destinationPath, exportPath, packages = [] }) => {
|
|
80
277
|
const matchingModule = packages.find(packageModule => {
|
|
81
278
|
return exportPath.startsWith(packageModule.rootPath);
|
|
@@ -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,M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