schemantic 0.1.0
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/CHANGELOG.md +92 -0
- package/LICENSE +21 -0
- package/README.md +827 -0
- package/dist/__tests__/setup.d.ts +6 -0
- package/dist/__tests__/setup.d.ts.map +1 -0
- package/dist/__tests__/setup.js +30 -0
- package/dist/__tests__/setup.js.map +1 -0
- package/dist/__tests__/test-config.d.ts +36 -0
- package/dist/__tests__/test-config.d.ts.map +1 -0
- package/dist/__tests__/test-config.js +563 -0
- package/dist/__tests__/test-config.js.map +1 -0
- package/dist/cli/index.d.ts +118 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +657 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/core/index.d.ts +5 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/index.js +21 -0
- package/dist/core/index.js.map +1 -0
- package/dist/core/schemantic.d.ts +95 -0
- package/dist/core/schemantic.d.ts.map +1 -0
- package/dist/core/schemantic.js +543 -0
- package/dist/core/schemantic.js.map +1 -0
- package/dist/generators/api-client-generator.d.ts +145 -0
- package/dist/generators/api-client-generator.d.ts.map +1 -0
- package/dist/generators/api-client-generator.js +856 -0
- package/dist/generators/api-client-generator.js.map +1 -0
- package/dist/generators/base.d.ts +117 -0
- package/dist/generators/base.d.ts.map +1 -0
- package/dist/generators/base.js +232 -0
- package/dist/generators/base.js.map +1 -0
- package/dist/generators/enum-generator.d.ts +52 -0
- package/dist/generators/enum-generator.d.ts.map +1 -0
- package/dist/generators/enum-generator.js +178 -0
- package/dist/generators/enum-generator.js.map +1 -0
- package/dist/generators/factory.d.ts +59 -0
- package/dist/generators/factory.d.ts.map +1 -0
- package/dist/generators/factory.js +127 -0
- package/dist/generators/factory.js.map +1 -0
- package/dist/generators/hook-generator.d.ts +36 -0
- package/dist/generators/hook-generator.d.ts.map +1 -0
- package/dist/generators/hook-generator.js +495 -0
- package/dist/generators/hook-generator.js.map +1 -0
- package/dist/generators/index.d.ts +10 -0
- package/dist/generators/index.d.ts.map +1 -0
- package/dist/generators/index.js +26 -0
- package/dist/generators/index.js.map +1 -0
- package/dist/generators/object-generator.d.ts +48 -0
- package/dist/generators/object-generator.d.ts.map +1 -0
- package/dist/generators/object-generator.js +280 -0
- package/dist/generators/object-generator.js.map +1 -0
- package/dist/generators/primitive-generator.d.ts +40 -0
- package/dist/generators/primitive-generator.d.ts.map +1 -0
- package/dist/generators/primitive-generator.js +150 -0
- package/dist/generators/primitive-generator.js.map +1 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +42 -0
- package/dist/index.js.map +1 -0
- package/dist/parsers/base.d.ts +101 -0
- package/dist/parsers/base.d.ts.map +1 -0
- package/dist/parsers/base.js +77 -0
- package/dist/parsers/base.js.map +1 -0
- package/dist/parsers/factory.d.ts +64 -0
- package/dist/parsers/factory.d.ts.map +1 -0
- package/dist/parsers/factory.js +116 -0
- package/dist/parsers/factory.js.map +1 -0
- package/dist/parsers/index.d.ts +7 -0
- package/dist/parsers/index.d.ts.map +1 -0
- package/dist/parsers/index.js +23 -0
- package/dist/parsers/index.js.map +1 -0
- package/dist/parsers/openapi.d.ts +52 -0
- package/dist/parsers/openapi.d.ts.map +1 -0
- package/dist/parsers/openapi.js +396 -0
- package/dist/parsers/openapi.js.map +1 -0
- package/dist/plugins/branded-types.d.ts +28 -0
- package/dist/plugins/branded-types.d.ts.map +1 -0
- package/dist/plugins/branded-types.js +568 -0
- package/dist/plugins/branded-types.js.map +1 -0
- package/dist/plugins/builtin.d.ts +38 -0
- package/dist/plugins/builtin.d.ts.map +1 -0
- package/dist/plugins/builtin.js +283 -0
- package/dist/plugins/builtin.js.map +1 -0
- package/dist/plugins/index.d.ts +7 -0
- package/dist/plugins/index.d.ts.map +1 -0
- package/dist/plugins/index.js +23 -0
- package/dist/plugins/index.js.map +1 -0
- package/dist/plugins/loader.d.ts +92 -0
- package/dist/plugins/loader.d.ts.map +1 -0
- package/dist/plugins/loader.js +245 -0
- package/dist/plugins/loader.js.map +1 -0
- package/dist/plugins/manager.d.ts +99 -0
- package/dist/plugins/manager.d.ts.map +1 -0
- package/dist/plugins/manager.js +233 -0
- package/dist/plugins/manager.js.map +1 -0
- package/dist/plugins/performance-monitoring.d.ts +98 -0
- package/dist/plugins/performance-monitoring.d.ts.map +1 -0
- package/dist/plugins/performance-monitoring.js +596 -0
- package/dist/plugins/performance-monitoring.js.map +1 -0
- package/dist/plugins/request-deduplication.d.ts +27 -0
- package/dist/plugins/request-deduplication.d.ts.map +1 -0
- package/dist/plugins/request-deduplication.js +650 -0
- package/dist/plugins/request-deduplication.js.map +1 -0
- package/dist/plugins/zod-validation.d.ts +63 -0
- package/dist/plugins/zod-validation.d.ts.map +1 -0
- package/dist/plugins/zod-validation.js +743 -0
- package/dist/plugins/zod-validation.js.map +1 -0
- package/dist/types/core.d.ts +203 -0
- package/dist/types/core.d.ts.map +1 -0
- package/dist/types/core.js +24 -0
- package/dist/types/core.js.map +1 -0
- package/dist/types/index.d.ts +7 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +23 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/openapi.d.ts +250 -0
- package/dist/types/openapi.d.ts.map +1 -0
- package/dist/types/openapi.js +8 -0
- package/dist/types/openapi.js.map +1 -0
- package/dist/types/schema.d.ts +68 -0
- package/dist/types/schema.d.ts.map +1 -0
- package/dist/types/schema.js +22 -0
- package/dist/types/schema.js.map +1 -0
- package/docs/ADVANCED_PLUGINS_IMPLEMENTATION.md +355 -0
- package/docs/ADVANCED_PLUGIN_DEVELOPMENT.md +309 -0
- package/docs/API.md +600 -0
- package/docs/CONFIGURATION.md +722 -0
- package/docs/FASTAPI_TUTORIAL.md +1497 -0
- package/docs/PLUGINS.md +683 -0
- package/docs/PLUGIN_DEVELOPMENT.md +720 -0
- package/package.json +90 -0
package/docs/API.md
ADDED
|
@@ -0,0 +1,600 @@
|
|
|
1
|
+
# API Reference
|
|
2
|
+
|
|
3
|
+
## Core Classes
|
|
4
|
+
|
|
5
|
+
### Schemantic
|
|
6
|
+
|
|
7
|
+
The main class for generating TypeScript types and API clients from OpenAPI schemas.
|
|
8
|
+
|
|
9
|
+
```typescript
|
|
10
|
+
import { Schemantic, SchemanticConfig } from "schemantic";
|
|
11
|
+
|
|
12
|
+
const config: SchemanticConfig = {
|
|
13
|
+
schemaUrl: "http://localhost:8000/openapi.json",
|
|
14
|
+
outputDir: "./src/generated",
|
|
15
|
+
generateTypes: true,
|
|
16
|
+
generateApiClient: true,
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
const Schemantic = new Schemantic(config);
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
#### Methods
|
|
23
|
+
|
|
24
|
+
##### `generate(): Promise<GenerationResult>`
|
|
25
|
+
|
|
26
|
+
Generates TypeScript types and API clients from the configured OpenAPI schema.
|
|
27
|
+
|
|
28
|
+
**Returns:** `Promise<GenerationResult>`
|
|
29
|
+
|
|
30
|
+
```typescript
|
|
31
|
+
const result = await Schemantic.generate();
|
|
32
|
+
|
|
33
|
+
if (result.success) {
|
|
34
|
+
console.log(`Generated ${result.generatedFiles.length} files`);
|
|
35
|
+
console.log(`Types: ${result.statistics.totalTypes}`);
|
|
36
|
+
console.log(`Endpoints: ${result.statistics.totalEndpoints}`);
|
|
37
|
+
}
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
##### `validate(): Promise<ValidationResult>`
|
|
41
|
+
|
|
42
|
+
Validates the OpenAPI schema without generating any files.
|
|
43
|
+
|
|
44
|
+
**Returns:** `Promise<ValidationResult>`
|
|
45
|
+
|
|
46
|
+
```typescript
|
|
47
|
+
const validation = await Schemantic.validate();
|
|
48
|
+
|
|
49
|
+
if (validation.isValid) {
|
|
50
|
+
console.log("Schema is valid");
|
|
51
|
+
} else {
|
|
52
|
+
console.log("Validation errors:", validation.errors);
|
|
53
|
+
}
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
##### `getPluginManager(): PluginManager`
|
|
57
|
+
|
|
58
|
+
Returns the plugin manager instance for registering and managing plugins.
|
|
59
|
+
|
|
60
|
+
**Returns:** `PluginManager`
|
|
61
|
+
|
|
62
|
+
```typescript
|
|
63
|
+
const pluginManager = Schemantic.getPluginManager();
|
|
64
|
+
pluginManager.registerPlugin(customPlugin);
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
##### `getConfig(): SchemanticConfig`
|
|
68
|
+
|
|
69
|
+
Returns the current configuration.
|
|
70
|
+
|
|
71
|
+
**Returns:** `SchemanticConfig`
|
|
72
|
+
|
|
73
|
+
### SchemanticConfig
|
|
74
|
+
|
|
75
|
+
Configuration interface for the Schemantic class.
|
|
76
|
+
|
|
77
|
+
```typescript
|
|
78
|
+
interface SchemanticConfig {
|
|
79
|
+
// Input configuration
|
|
80
|
+
schemaUrl?: string;
|
|
81
|
+
schemaFile?: string;
|
|
82
|
+
schemaData?: OpenAPISchema;
|
|
83
|
+
|
|
84
|
+
// Output configuration
|
|
85
|
+
outputDir: string;
|
|
86
|
+
outputFileName?: string;
|
|
87
|
+
|
|
88
|
+
// Generation options
|
|
89
|
+
generateTypes: boolean;
|
|
90
|
+
generateApiClient: boolean;
|
|
91
|
+
generateHooks?: boolean;
|
|
92
|
+
generateQueries?: boolean;
|
|
93
|
+
|
|
94
|
+
// TypeScript configuration
|
|
95
|
+
useStrictTypes: boolean;
|
|
96
|
+
useOptionalChaining: boolean;
|
|
97
|
+
useNullishCoalescing: boolean;
|
|
98
|
+
|
|
99
|
+
// Naming conventions
|
|
100
|
+
namingConvention: "camelCase" | "snake_case" | "PascalCase";
|
|
101
|
+
typePrefix?: string;
|
|
102
|
+
typeSuffix?: string;
|
|
103
|
+
|
|
104
|
+
// Customization
|
|
105
|
+
customTypeMappings?: Record<string, string>;
|
|
106
|
+
excludePaths?: string[];
|
|
107
|
+
includePaths?: string[];
|
|
108
|
+
excludeSchemas?: string[];
|
|
109
|
+
includeSchemas?: string[];
|
|
110
|
+
|
|
111
|
+
// Plugin configuration
|
|
112
|
+
plugins?: PluginConfig[];
|
|
113
|
+
|
|
114
|
+
// Advanced options
|
|
115
|
+
preserveComments: boolean;
|
|
116
|
+
generateIndexFile: boolean;
|
|
117
|
+
generateBarrelExports: boolean;
|
|
118
|
+
}
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
## Parser Classes
|
|
122
|
+
|
|
123
|
+
### ParserFactory
|
|
124
|
+
|
|
125
|
+
Factory class for creating schema parsers.
|
|
126
|
+
|
|
127
|
+
```typescript
|
|
128
|
+
import { ParserFactory } from "schemantic";
|
|
129
|
+
|
|
130
|
+
// Create parser by type
|
|
131
|
+
const parser = ParserFactory.createParser("openapi", config);
|
|
132
|
+
|
|
133
|
+
// Auto-detect parser type
|
|
134
|
+
const autoParser = ParserFactory.autoCreateParser(input, config);
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
#### Methods
|
|
138
|
+
|
|
139
|
+
##### `createParser(type: ParserType, config: SchemanticConfig): SchemaParser`
|
|
140
|
+
|
|
141
|
+
Creates a parser instance of the specified type.
|
|
142
|
+
|
|
143
|
+
**Parameters:**
|
|
144
|
+
|
|
145
|
+
- `type` - The parser type ('openapi', 'swagger', 'json-schema')
|
|
146
|
+
- `config` - Schemantic configuration
|
|
147
|
+
|
|
148
|
+
**Returns:** `SchemaParser`
|
|
149
|
+
|
|
150
|
+
##### `autoCreateParser(input: SchemaInput, config: SchemanticConfig): SchemaParser`
|
|
151
|
+
|
|
152
|
+
Automatically detects the parser type and creates an appropriate instance.
|
|
153
|
+
|
|
154
|
+
**Parameters:**
|
|
155
|
+
|
|
156
|
+
- `input` - Schema input source
|
|
157
|
+
- `config` - Schemantic configuration
|
|
158
|
+
|
|
159
|
+
**Returns:** `SchemaParser`
|
|
160
|
+
|
|
161
|
+
##### `detectParserType(input: SchemaInput): ParserType`
|
|
162
|
+
|
|
163
|
+
Detects the appropriate parser type from the input.
|
|
164
|
+
|
|
165
|
+
**Parameters:**
|
|
166
|
+
|
|
167
|
+
- `input` - Schema input source
|
|
168
|
+
|
|
169
|
+
**Returns:** `ParserType`
|
|
170
|
+
|
|
171
|
+
### OpenAPIParser
|
|
172
|
+
|
|
173
|
+
Parser implementation for OpenAPI 3.0+ specifications.
|
|
174
|
+
|
|
175
|
+
```typescript
|
|
176
|
+
import { OpenAPIParser } from "schemantic";
|
|
177
|
+
|
|
178
|
+
const parser = new OpenAPIParser(config);
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
#### Methods
|
|
182
|
+
|
|
183
|
+
##### `parse(input: SchemaInput): Promise<OpenAPISchema>`
|
|
184
|
+
|
|
185
|
+
Parses schema from various input sources.
|
|
186
|
+
|
|
187
|
+
**Parameters:**
|
|
188
|
+
|
|
189
|
+
- `input` - Schema input source
|
|
190
|
+
|
|
191
|
+
**Returns:** `Promise<OpenAPISchema>`
|
|
192
|
+
|
|
193
|
+
##### `validate(schema: OpenAPISchema): Promise<ValidationResult>`
|
|
194
|
+
|
|
195
|
+
Validates the parsed schema.
|
|
196
|
+
|
|
197
|
+
**Parameters:**
|
|
198
|
+
|
|
199
|
+
- `schema` - OpenAPI schema to validate
|
|
200
|
+
|
|
201
|
+
**Returns:** `Promise<ValidationResult>`
|
|
202
|
+
|
|
203
|
+
##### `createResolver(schema: OpenAPISchema): SchemaResolver`
|
|
204
|
+
|
|
205
|
+
Creates a schema resolver for the parsed schema.
|
|
206
|
+
|
|
207
|
+
**Parameters:**
|
|
208
|
+
|
|
209
|
+
- `schema` - OpenAPI schema
|
|
210
|
+
|
|
211
|
+
**Returns:** `SchemaResolver`
|
|
212
|
+
|
|
213
|
+
## Generator Classes
|
|
214
|
+
|
|
215
|
+
### TypeGeneratorFactory
|
|
216
|
+
|
|
217
|
+
Factory class for creating type generators.
|
|
218
|
+
|
|
219
|
+
```typescript
|
|
220
|
+
import { TypeGeneratorFactory } from "schemantic";
|
|
221
|
+
|
|
222
|
+
// Create generators from config
|
|
223
|
+
const generators = TypeGeneratorFactory.createFromConfig(config);
|
|
224
|
+
|
|
225
|
+
// Generate type from schema
|
|
226
|
+
const generatedType = TypeGeneratorFactory.generateType(
|
|
227
|
+
schema,
|
|
228
|
+
context,
|
|
229
|
+
generators
|
|
230
|
+
);
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
#### Methods
|
|
234
|
+
|
|
235
|
+
##### `createFromConfig(config: SchemanticConfig): TypeGenerator[]`
|
|
236
|
+
|
|
237
|
+
Creates type generators based on configuration.
|
|
238
|
+
|
|
239
|
+
**Parameters:**
|
|
240
|
+
|
|
241
|
+
- `config` - Schemantic configuration
|
|
242
|
+
|
|
243
|
+
**Returns:** `TypeGenerator[]`
|
|
244
|
+
|
|
245
|
+
##### `generateType(schema: ResolvedSchema, context: GenerationContext, generators: TypeGenerator[]): GeneratedType | undefined`
|
|
246
|
+
|
|
247
|
+
Generates a TypeScript type from a schema using available generators.
|
|
248
|
+
|
|
249
|
+
**Parameters:**
|
|
250
|
+
|
|
251
|
+
- `schema` - Resolved schema
|
|
252
|
+
- `context` - Generation context
|
|
253
|
+
- `generators` - Available generators
|
|
254
|
+
|
|
255
|
+
**Returns:** `GeneratedType | undefined`
|
|
256
|
+
|
|
257
|
+
##### `getBestGenerator(schema: ResolvedSchema, generators: TypeGenerator[]): TypeGenerator | undefined`
|
|
258
|
+
|
|
259
|
+
Finds the best generator for a given schema.
|
|
260
|
+
|
|
261
|
+
**Parameters:**
|
|
262
|
+
|
|
263
|
+
- `schema` - Resolved schema
|
|
264
|
+
- `generators` - Available generators
|
|
265
|
+
|
|
266
|
+
**Returns:** `TypeGenerator | undefined`
|
|
267
|
+
|
|
268
|
+
### ObjectTypeGenerator
|
|
269
|
+
|
|
270
|
+
Generator for creating TypeScript interfaces from OpenAPI schema objects.
|
|
271
|
+
|
|
272
|
+
```typescript
|
|
273
|
+
import { ObjectTypeGenerator } from "schemantic";
|
|
274
|
+
|
|
275
|
+
const generator = new ObjectTypeGenerator(options);
|
|
276
|
+
```
|
|
277
|
+
|
|
278
|
+
### EnumTypeGenerator
|
|
279
|
+
|
|
280
|
+
Generator for creating TypeScript enums from OpenAPI schema enums.
|
|
281
|
+
|
|
282
|
+
```typescript
|
|
283
|
+
import { EnumTypeGenerator } from "schemantic";
|
|
284
|
+
|
|
285
|
+
const generator = new EnumTypeGenerator(options);
|
|
286
|
+
```
|
|
287
|
+
|
|
288
|
+
### ApiClientGenerator
|
|
289
|
+
|
|
290
|
+
Generator for creating TypeScript API client classes.
|
|
291
|
+
|
|
292
|
+
```typescript
|
|
293
|
+
import { ApiClientGenerator } from "schemantic";
|
|
294
|
+
|
|
295
|
+
const generator = new ApiClientGenerator(context);
|
|
296
|
+
const client = generator.generate(context);
|
|
297
|
+
// The client is exported via the generated index file and can be imported from './generated'
|
|
298
|
+
```
|
|
299
|
+
|
|
300
|
+
## Plugin System
|
|
301
|
+
|
|
302
|
+
### PluginManager
|
|
303
|
+
|
|
304
|
+
Manages plugin registration and execution.
|
|
305
|
+
|
|
306
|
+
```typescript
|
|
307
|
+
import { PluginManager } from "schemantic";
|
|
308
|
+
|
|
309
|
+
const pluginManager = new PluginManager();
|
|
310
|
+
```
|
|
311
|
+
|
|
312
|
+
#### Methods
|
|
313
|
+
|
|
314
|
+
##### `registerPlugin(plugin: SchemanticPlugin): void`
|
|
315
|
+
|
|
316
|
+
Registers a plugin with the manager.
|
|
317
|
+
|
|
318
|
+
**Parameters:**
|
|
319
|
+
|
|
320
|
+
- `plugin` - Plugin to register
|
|
321
|
+
|
|
322
|
+
##### `enablePlugin(name: string): void`
|
|
323
|
+
|
|
324
|
+
Enables a registered plugin.
|
|
325
|
+
|
|
326
|
+
**Parameters:**
|
|
327
|
+
|
|
328
|
+
- `name` - Plugin name
|
|
329
|
+
|
|
330
|
+
##### `disablePlugin(name: string): void`
|
|
331
|
+
|
|
332
|
+
Disables a registered plugin.
|
|
333
|
+
|
|
334
|
+
**Parameters:**
|
|
335
|
+
|
|
336
|
+
- `name` - Plugin name
|
|
337
|
+
|
|
338
|
+
##### `executeBeforeGeneration(context: GenerationContext): Promise<void>`
|
|
339
|
+
|
|
340
|
+
Executes before generation hooks for all enabled plugins.
|
|
341
|
+
|
|
342
|
+
**Parameters:**
|
|
343
|
+
|
|
344
|
+
- `context` - Generation context
|
|
345
|
+
|
|
346
|
+
**Returns:** `Promise<void>`
|
|
347
|
+
|
|
348
|
+
##### `executeAfterGeneration(context: GenerationContext, result: GenerationResult): Promise<void>`
|
|
349
|
+
|
|
350
|
+
Executes after generation hooks for all enabled plugins.
|
|
351
|
+
|
|
352
|
+
**Parameters:**
|
|
353
|
+
|
|
354
|
+
- `context` - Generation context
|
|
355
|
+
- `result` - Generation result
|
|
356
|
+
|
|
357
|
+
**Returns:** `Promise<void>`
|
|
358
|
+
|
|
359
|
+
### PluginLoader
|
|
360
|
+
|
|
361
|
+
Loads plugins from various sources.
|
|
362
|
+
|
|
363
|
+
```typescript
|
|
364
|
+
import { PluginLoader } from "schemantic";
|
|
365
|
+
|
|
366
|
+
const loader = new PluginLoader();
|
|
367
|
+
```
|
|
368
|
+
|
|
369
|
+
#### Methods
|
|
370
|
+
|
|
371
|
+
##### `loadPluginFromFile(filePath: string): Promise<SchemanticPlugin>`
|
|
372
|
+
|
|
373
|
+
Loads a plugin from a file.
|
|
374
|
+
|
|
375
|
+
**Parameters:**
|
|
376
|
+
|
|
377
|
+
- `filePath` - Path to plugin file
|
|
378
|
+
|
|
379
|
+
**Returns:** `Promise<SchemanticPlugin>`
|
|
380
|
+
|
|
381
|
+
##### `loadPluginFromPackage(packageName: string): Promise<SchemanticPlugin>`
|
|
382
|
+
|
|
383
|
+
Loads a plugin from an npm package.
|
|
384
|
+
|
|
385
|
+
**Parameters:**
|
|
386
|
+
|
|
387
|
+
- `packageName` - Package name
|
|
388
|
+
|
|
389
|
+
**Returns:** `Promise<SchemanticPlugin>`
|
|
390
|
+
|
|
391
|
+
##### `loadPluginsFromDirectory(directoryPath: string): Promise<SchemanticPlugin[]>`
|
|
392
|
+
|
|
393
|
+
Loads all plugins from a directory.
|
|
394
|
+
|
|
395
|
+
**Parameters:**
|
|
396
|
+
|
|
397
|
+
- `directoryPath` - Directory path
|
|
398
|
+
|
|
399
|
+
**Returns:** `Promise<SchemanticPlugin[]>`
|
|
400
|
+
|
|
401
|
+
### SchemanticPlugin
|
|
402
|
+
|
|
403
|
+
Plugin interface for extending Schemantic functionality.
|
|
404
|
+
|
|
405
|
+
```typescript
|
|
406
|
+
interface SchemanticPlugin {
|
|
407
|
+
name: string;
|
|
408
|
+
version: string;
|
|
409
|
+
description: string;
|
|
410
|
+
|
|
411
|
+
// Lifecycle hooks
|
|
412
|
+
beforeGeneration?(context: GenerationContext): Promise<void> | void;
|
|
413
|
+
afterGeneration?(
|
|
414
|
+
context: GenerationContext,
|
|
415
|
+
result: GenerationResult
|
|
416
|
+
): Promise<void> | void;
|
|
417
|
+
|
|
418
|
+
// Type generation hooks
|
|
419
|
+
beforeTypeGeneration?(
|
|
420
|
+
typeName: string,
|
|
421
|
+
schema: ResolvedSchema,
|
|
422
|
+
context: GenerationContext
|
|
423
|
+
): Promise<void> | void;
|
|
424
|
+
afterTypeGeneration?(
|
|
425
|
+
typeName: string,
|
|
426
|
+
generatedType: GeneratedType,
|
|
427
|
+
context: GenerationContext
|
|
428
|
+
): Promise<void> | void;
|
|
429
|
+
|
|
430
|
+
// Client generation hooks
|
|
431
|
+
beforeClientGeneration?(context: GenerationContext): Promise<void> | void;
|
|
432
|
+
afterClientGeneration?(
|
|
433
|
+
generatedClient: GeneratedApiClient,
|
|
434
|
+
context: GenerationContext
|
|
435
|
+
): Promise<void> | void;
|
|
436
|
+
|
|
437
|
+
// Schema transformation hooks
|
|
438
|
+
transformSchema?(
|
|
439
|
+
schema: ResolvedSchema,
|
|
440
|
+
context: GenerationContext
|
|
441
|
+
): ResolvedSchema;
|
|
442
|
+
|
|
443
|
+
// Custom generators
|
|
444
|
+
customTypeGenerators?: Record<
|
|
445
|
+
string,
|
|
446
|
+
(schema: ResolvedSchema, context: GenerationContext) => GeneratedType
|
|
447
|
+
>;
|
|
448
|
+
customClientGenerators?: Record<
|
|
449
|
+
string,
|
|
450
|
+
(context: GenerationContext) => GeneratedApiClient
|
|
451
|
+
>;
|
|
452
|
+
}
|
|
453
|
+
```
|
|
454
|
+
|
|
455
|
+
## Type Definitions
|
|
456
|
+
|
|
457
|
+
### GeneratedType
|
|
458
|
+
|
|
459
|
+
Represents a generated TypeScript type.
|
|
460
|
+
|
|
461
|
+
```typescript
|
|
462
|
+
interface GeneratedType {
|
|
463
|
+
name: string;
|
|
464
|
+
content: string;
|
|
465
|
+
dependencies: string[];
|
|
466
|
+
exports: string[];
|
|
467
|
+
isInterface: boolean;
|
|
468
|
+
isEnum: boolean;
|
|
469
|
+
isUnion: boolean;
|
|
470
|
+
sourceSchema: ResolvedSchema;
|
|
471
|
+
}
|
|
472
|
+
```
|
|
473
|
+
|
|
474
|
+
### GeneratedApiClient
|
|
475
|
+
|
|
476
|
+
Represents a generated API client.
|
|
477
|
+
|
|
478
|
+
```typescript
|
|
479
|
+
interface GeneratedApiClient {
|
|
480
|
+
name: string;
|
|
481
|
+
content: string;
|
|
482
|
+
dependencies: string[];
|
|
483
|
+
exports: string[];
|
|
484
|
+
endpoints: GeneratedEndpoint[];
|
|
485
|
+
}
|
|
486
|
+
```
|
|
487
|
+
|
|
488
|
+
### GeneratedEndpoint
|
|
489
|
+
|
|
490
|
+
Represents a generated API endpoint.
|
|
491
|
+
|
|
492
|
+
```typescript
|
|
493
|
+
interface GeneratedEndpoint {
|
|
494
|
+
operationId: string;
|
|
495
|
+
method: string;
|
|
496
|
+
path: string;
|
|
497
|
+
parameters: GeneratedParameter[];
|
|
498
|
+
requestBody?: GeneratedRequestBody;
|
|
499
|
+
responses: GeneratedResponse[];
|
|
500
|
+
returnType: string;
|
|
501
|
+
functionName: string;
|
|
502
|
+
}
|
|
503
|
+
```
|
|
504
|
+
|
|
505
|
+
### GenerationResult
|
|
506
|
+
|
|
507
|
+
Result of the generation process.
|
|
508
|
+
|
|
509
|
+
```typescript
|
|
510
|
+
interface GenerationResult {
|
|
511
|
+
success: boolean;
|
|
512
|
+
generatedFiles: GeneratedFile[];
|
|
513
|
+
errors: GenerationError[];
|
|
514
|
+
warnings: GenerationWarning[];
|
|
515
|
+
statistics: GenerationStatistics;
|
|
516
|
+
}
|
|
517
|
+
```
|
|
518
|
+
|
|
519
|
+
### GenerationContext
|
|
520
|
+
|
|
521
|
+
Context passed to plugins and generators.
|
|
522
|
+
|
|
523
|
+
```typescript
|
|
524
|
+
interface GenerationContext {
|
|
525
|
+
config: SchemanticConfig;
|
|
526
|
+
schema: OpenAPISchema;
|
|
527
|
+
resolvedSchemas: Map<string, ResolvedSchema>;
|
|
528
|
+
generatedTypes: Map<string, GeneratedType>;
|
|
529
|
+
generatedClients: Map<string, GeneratedApiClient>;
|
|
530
|
+
typeRegistry: TypeRegistry;
|
|
531
|
+
schemaResolver: SchemaResolver;
|
|
532
|
+
}
|
|
533
|
+
```
|
|
534
|
+
|
|
535
|
+
## Error Handling
|
|
536
|
+
|
|
537
|
+
### GenerationError
|
|
538
|
+
|
|
539
|
+
Represents an error during generation.
|
|
540
|
+
|
|
541
|
+
```typescript
|
|
542
|
+
interface GenerationError {
|
|
543
|
+
code: string;
|
|
544
|
+
message: string;
|
|
545
|
+
source?: string;
|
|
546
|
+
line?: number;
|
|
547
|
+
column?: number;
|
|
548
|
+
severity: "error" | "warning";
|
|
549
|
+
}
|
|
550
|
+
```
|
|
551
|
+
|
|
552
|
+
### GenerationWarning
|
|
553
|
+
|
|
554
|
+
Represents a warning during generation.
|
|
555
|
+
|
|
556
|
+
```typescript
|
|
557
|
+
interface GenerationWarning {
|
|
558
|
+
code: string;
|
|
559
|
+
message: string;
|
|
560
|
+
source?: string;
|
|
561
|
+
suggestion?: string;
|
|
562
|
+
}
|
|
563
|
+
```
|
|
564
|
+
|
|
565
|
+
## Utility Functions
|
|
566
|
+
|
|
567
|
+
### Built-in Plugins
|
|
568
|
+
|
|
569
|
+
```typescript
|
|
570
|
+
import { getBuiltinPlugins, getBuiltinPlugin } from "schemantic";
|
|
571
|
+
|
|
572
|
+
// Get all built-in plugins
|
|
573
|
+
const plugins = getBuiltinPlugins();
|
|
574
|
+
|
|
575
|
+
// Get specific built-in plugin
|
|
576
|
+
const jsdocPlugin = getBuiltinPlugin("jsdoc");
|
|
577
|
+
```
|
|
578
|
+
|
|
579
|
+
### Convenience Functions
|
|
580
|
+
|
|
581
|
+
```typescript
|
|
582
|
+
import {
|
|
583
|
+
createParser,
|
|
584
|
+
autoCreateParser,
|
|
585
|
+
createGenerators,
|
|
586
|
+
generateType,
|
|
587
|
+
} from "schemantic";
|
|
588
|
+
|
|
589
|
+
// Create parser
|
|
590
|
+
const parser = createParser("openapi", config);
|
|
591
|
+
|
|
592
|
+
// Auto-create parser
|
|
593
|
+
const autoParser = autoCreateParser(input, config);
|
|
594
|
+
|
|
595
|
+
// Create generators
|
|
596
|
+
const generators = createGenerators(config);
|
|
597
|
+
|
|
598
|
+
// Generate type
|
|
599
|
+
const type = generateType(schema, context, generators);
|
|
600
|
+
```
|