schemantic 0.2.1 → 0.4.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 +196 -159
- package/LICENSE +21 -21
- package/README.md +88 -830
- package/dist/cli/index.d.ts +4 -1
- package/dist/cli/index.d.ts.map +1 -1
- package/dist/cli/index.js +186 -62
- package/dist/cli/index.js.map +1 -1
- package/dist/core/configuration.d.ts +6 -0
- package/dist/core/configuration.d.ts.map +1 -0
- package/dist/core/configuration.js +64 -0
- package/dist/core/configuration.js.map +1 -0
- package/dist/core/index.d.ts +1 -0
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +1 -0
- package/dist/core/index.js.map +1 -1
- package/dist/core/output-writer.d.ts +7 -0
- package/dist/core/output-writer.d.ts.map +1 -0
- package/dist/core/output-writer.js +255 -0
- package/dist/core/output-writer.js.map +1 -0
- package/dist/core/schemantic.d.ts +8 -6
- package/dist/core/schemantic.d.ts.map +1 -1
- package/dist/core/schemantic.js +194 -127
- package/dist/core/schemantic.js.map +1 -1
- package/dist/generators/api-client-generator.d.ts +9 -20
- package/dist/generators/api-client-generator.d.ts.map +1 -1
- package/dist/generators/api-client-generator.js +364 -424
- package/dist/generators/api-client-generator.js.map +1 -1
- package/dist/generators/base.d.ts.map +1 -1
- package/dist/generators/base.js +7 -25
- package/dist/generators/base.js.map +1 -1
- package/dist/generators/enum-generator.d.ts.map +1 -1
- package/dist/generators/enum-generator.js +30 -3
- package/dist/generators/enum-generator.js.map +1 -1
- package/dist/generators/hook-generator.d.ts +3 -17
- package/dist/generators/hook-generator.d.ts.map +1 -1
- package/dist/generators/hook-generator.js +51 -445
- package/dist/generators/hook-generator.js.map +1 -1
- package/dist/generators/naming.d.ts +10 -0
- package/dist/generators/naming.d.ts.map +1 -0
- package/dist/generators/naming.js +331 -0
- package/dist/generators/naming.js.map +1 -0
- package/dist/generators/object-generator.d.ts +0 -4
- package/dist/generators/object-generator.d.ts.map +1 -1
- package/dist/generators/object-generator.js +13 -101
- package/dist/generators/object-generator.js.map +1 -1
- package/dist/generators/primitive-generator.d.ts +1 -13
- package/dist/generators/primitive-generator.d.ts.map +1 -1
- package/dist/generators/primitive-generator.js +11 -76
- package/dist/generators/primitive-generator.js.map +1 -1
- package/dist/generators/projections.d.ts +10 -0
- package/dist/generators/projections.d.ts.map +1 -0
- package/dist/generators/projections.js +65 -0
- package/dist/generators/projections.js.map +1 -0
- package/dist/generators/schema-type.d.ts +23 -0
- package/dist/generators/schema-type.d.ts.map +1 -0
- package/dist/generators/schema-type.js +233 -0
- package/dist/generators/schema-type.js.map +1 -0
- package/dist/parsers/base.d.ts +2 -0
- package/dist/parsers/base.d.ts.map +1 -1
- package/dist/parsers/base.js +12 -2
- package/dist/parsers/base.js.map +1 -1
- package/dist/parsers/factory.d.ts.map +1 -1
- package/dist/parsers/factory.js +2 -1
- package/dist/parsers/factory.js.map +1 -1
- package/dist/parsers/openapi.d.ts +4 -0
- package/dist/parsers/openapi.d.ts.map +1 -1
- package/dist/parsers/openapi.js +107 -20
- package/dist/parsers/openapi.js.map +1 -1
- package/dist/plugins/branded-types.d.ts.map +1 -1
- package/dist/plugins/branded-types.js +231 -365
- package/dist/plugins/branded-types.js.map +1 -1
- package/dist/plugins/builtin.d.ts.map +1 -1
- package/dist/plugins/builtin.js +6 -141
- package/dist/plugins/builtin.js.map +1 -1
- package/dist/plugins/index.d.ts +4 -0
- package/dist/plugins/index.d.ts.map +1 -1
- package/dist/plugins/index.js +17 -0
- package/dist/plugins/index.js.map +1 -1
- package/dist/plugins/loader.d.ts +5 -1
- package/dist/plugins/loader.d.ts.map +1 -1
- package/dist/plugins/loader.js +42 -5
- package/dist/plugins/loader.js.map +1 -1
- package/dist/plugins/manager.d.ts.map +1 -1
- package/dist/plugins/manager.js +7 -7
- package/dist/plugins/manager.js.map +1 -1
- package/dist/plugins/performance-monitoring.d.ts +31 -1
- package/dist/plugins/performance-monitoring.d.ts.map +1 -1
- package/dist/plugins/performance-monitoring.js +146 -207
- package/dist/plugins/performance-monitoring.js.map +1 -1
- package/dist/plugins/request-deduplication.d.ts.map +1 -1
- package/dist/plugins/request-deduplication.js +151 -586
- package/dist/plugins/request-deduplication.js.map +1 -1
- package/dist/plugins/zod-validation.d.ts +23 -15
- package/dist/plugins/zod-validation.d.ts.map +1 -1
- package/dist/plugins/zod-validation.js +390 -268
- package/dist/plugins/zod-validation.js.map +1 -1
- package/dist/types/core.d.ts +20 -4
- package/dist/types/core.d.ts.map +1 -1
- package/dist/types/core.js +2 -1
- package/dist/types/core.js.map +1 -1
- package/dist/types/openapi.d.ts +14 -1
- package/dist/types/openapi.d.ts.map +1 -1
- package/docs/ADVANCED_PLUGINS_IMPLEMENTATION.md +24 -355
- package/docs/ADVANCED_PLUGIN_DEVELOPMENT.md +33 -309
- package/docs/API.md +80 -600
- package/docs/AUDIT.md +49 -0
- package/docs/CONFIGURATION.md +81 -722
- package/docs/FASTAPI_TUTORIAL.md +109 -1497
- package/docs/NAMING_MIGRATION.md +59 -0
- package/docs/PLUGINS.md +49 -687
- package/docs/PLUGIN_DEVELOPMENT.md +53 -720
- package/docs/REAUDIT.md +399 -0
- package/docs/RELEASING.md +88 -0
- package/docs/REMEDIATION.md +58 -0
- package/docs/superpowers/plans/2026-10-10-audit-remediation.md +113 -0
- package/package.json +114 -95
- package/dist/__tests__/setup.d.ts +0 -6
- package/dist/__tests__/setup.d.ts.map +0 -1
- package/dist/__tests__/setup.js +0 -30
- package/dist/__tests__/setup.js.map +0 -1
- package/dist/__tests__/test-config.d.ts +0 -36
- package/dist/__tests__/test-config.d.ts.map +0 -1
- package/dist/__tests__/test-config.js +0 -563
- package/dist/__tests__/test-config.js.map +0 -1
- package/dist/lib/api/api-client.d.ts +0 -71
- package/dist/lib/api/api-client.d.ts.map +0 -1
- package/dist/lib/api/api-client.js +0 -238
- package/dist/lib/api/api-client.js.map +0 -1
- package/dist/lib/api/barrel.d.ts +0 -4
- package/dist/lib/api/barrel.d.ts.map +0 -1
- package/dist/lib/api/barrel.js +0 -26
- package/dist/lib/api/barrel.js.map +0 -1
- package/dist/lib/api/hooks.d.ts +0 -36
- package/dist/lib/api/hooks.d.ts.map +0 -1
- package/dist/lib/api/hooks.js +0 -120
- package/dist/lib/api/hooks.js.map +0 -1
- package/dist/lib/api/index.d.ts +0 -4
- package/dist/lib/api/index.d.ts.map +0 -1
- package/dist/lib/api/index.js +0 -8
- package/dist/lib/api/index.js.map +0 -1
- package/dist/lib/api/types.d.ts +0 -366
- package/dist/lib/api/types.d.ts.map +0 -1
- package/dist/lib/api/types.js +0 -315
- package/dist/lib/api/types.js.map +0 -1
package/docs/API.md
CHANGED
|
@@ -1,600 +1,80 @@
|
|
|
1
|
-
# API
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
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
|
-
```
|
|
1
|
+
# API reference
|
|
2
|
+
|
|
3
|
+
Import supported APIs from `schemantic`, not blocked repository/deep paths. The package exports core classes/types, parsers, generators, plugin management/loading, built-in plugin objects, and supported utility factories. Generated client APIs are exported from the generated `index.ts`, not the schemantic package.
|
|
4
|
+
|
|
5
|
+
```ts
|
|
6
|
+
import { Schemantic } from 'schemantic';
|
|
7
|
+
import type { SchemanticOptions, SchemanticPlugin } from 'schemantic';
|
|
8
|
+
|
|
9
|
+
const options: SchemanticOptions = { schemaFile: './openapi.json', outputDir: './generated' };
|
|
10
|
+
const generator = new Schemantic(options);
|
|
11
|
+
const plugin: SchemanticPlugin = {
|
|
12
|
+
name: 'example', version: '1.0.0', description: 'Example plugin',
|
|
13
|
+
beforeGeneration(context) { console.log(context.schema.info.title); },
|
|
14
|
+
};
|
|
15
|
+
generator.getPluginManager().registerPlugin(plugin);
|
|
16
|
+
generator.getPluginManager().enablePlugin(plugin.name);
|
|
17
|
+
const result = await generator.generate();
|
|
18
|
+
if (!result.success) throw new Error(result.errors.map(error => error.message).join('\n'));
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
| Method | Result |
|
|
22
|
+
| --- | --- |
|
|
23
|
+
| `generate()` | `Promise<GenerationResult>` with success, generated files, errors, warnings, statistics |
|
|
24
|
+
| `validate()` | Promise of `{ isValid, errors, warnings }`; no generated writes |
|
|
25
|
+
| `getConfig()` | Current configuration |
|
|
26
|
+
| `getPluginManager()` | Manager for registering, enabling, disabling, and inspecting plugins |
|
|
27
|
+
|
|
28
|
+
Generation results include file path/content/type/dependencies/size and statistics for type/endpoint/file counts, bytes and elapsed generation time. A successful result is not a claim of full OpenAPI coverage or server behavior; inspect warnings and compile the output with your consumer settings.
|
|
29
|
+
|
|
30
|
+
## Generated client
|
|
31
|
+
|
|
32
|
+
Client class names derive from `info.title`; the following example assumes `Users API`.
|
|
33
|
+
|
|
34
|
+
```ts
|
|
35
|
+
import { UsersApiClient as ApiClient, ApiClientError } from './generated/index.js';
|
|
36
|
+
|
|
37
|
+
const client = new ApiClient({
|
|
38
|
+
baseUrl: 'http://localhost:8000',
|
|
39
|
+
headers: { 'X-Api-Key': 'example' },
|
|
40
|
+
timeout: 30000,
|
|
41
|
+
retries: 3,
|
|
42
|
+
retryDelay: 1000,
|
|
43
|
+
});
|
|
44
|
+
client.setAuthToken('token');
|
|
45
|
+
client.clearAuthToken();
|
|
46
|
+
// Catch ApiClientError for HTTP failures; status and response describe the failure.
|
|
47
|
+
void ApiClientError;
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
`baseUrl` is required. `headers` accepts the fetch header forms: a string record, pairs, or `Headers`. Timeout and retry delay are milliseconds; retries apply only to supported idempotent methods/transient failures. Each generated operation takes its schema-derived positional parameters and an optional final `RequestInit`. Supply per-call headers there, or use `setDefaultHeader(name, value)` / `removeDefaultHeader(name)` to change case-insensitive defaults. `setAuthToken` and `clearAuthToken` manage bearer authorization. OAuth login orchestration and automatic plugin middleware are not implemented.
|
|
51
|
+
|
|
52
|
+
Response bodies are decoded according to media/status metadata. JSON returns data, text-based media returns text, binary media returns Blob, and empty responses return undefined. XML is returned as text, not parsed into objects. Multiple declared response media may produce union types.
|
|
53
|
+
|
|
54
|
+
## Generated plain React hooks
|
|
55
|
+
|
|
56
|
+
Generate with `--hooks` or `generateHooks: true`, install React in the consumer, then use `createApiHooks(client)` from generated output. GET operations generate `use<Operation>Query(args?, requestInit?)`; other operations generate `use<Operation>Mutation()`.
|
|
57
|
+
|
|
58
|
+
Query results contain `{ data, error, loading, refetch }`. Query argument groups use schema wire parameter names under `path`, `query`, `header`, or `cookie`. Mutation results contain `{ mutate, data, error, loading, reset }`. Call `mutate({ path?, query?, header?, cookie?, body? }, requestInit?)` with the fields required by that operation. Payload groups are schema-derived; inspect the emitted signature.
|
|
59
|
+
|
|
60
|
+
Mutation state tracks the latest call: an older completion cannot replace its result/error or clear its pending loading state. Each caller still receives its own promise result. Reset, unmount, and client changes invalidate pending shared-state publication; changing the client clears mutation state. These hooks use React state/effects. They do not implement TanStack Query options such as `enabled`, `onSuccess`, `onError`, invalidation/query keys, or `isLoading`. Each `mutate` returns its own promise result; errors reject that promise. Handle errors with try/catch in your caller.
|
|
61
|
+
|
|
62
|
+
## Plugin loader
|
|
63
|
+
|
|
64
|
+
`new PluginLoader().loadPlugin(specifier, directory?)` selects local file or consumer-resolved package loading. Supported JavaScript module files are `.js`, `.cjs`, and `.mjs`; compile TypeScript plugins first. Modules may export a plugin directly, as default, or as `plugin`. Duplicate exported names fail. `plugin load` in the CLI inspects a module; it does not persist registration for another process.
|
|
65
|
+
|
|
66
|
+
See [configuration](CONFIGURATION.md), [plugins](PLUGINS.md), and the [current plugin interface](../src/types/core.ts) for the exact supported fields/hooks.
|
|
67
|
+
|
|
68
|
+
## Generated naming helpers
|
|
69
|
+
|
|
70
|
+
With default `propertyNaming: "camelCase"`, generated `conversion.ts` is exported by the generated index. Generated JSON/form requests serialize application properties to the schema wire names, and JSON responses deserialize declared properties to application names automatically. Caller-provided FormData retains its own keys and boundaries. For the tutorial User schema:
|
|
71
|
+
|
|
72
|
+
```ts
|
|
73
|
+
import { serializeUser, deserializeUser } from './generated/index.js';
|
|
74
|
+
|
|
75
|
+
const wireValue = serializeUser({ id: 1, displayName: 'Example' });
|
|
76
|
+
const applicationValue = deserializeUser({ id: 1, display_name: 'Example' });
|
|
77
|
+
console.log(wireValue, applicationValue.displayName);
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
Typed helper names derive from component type names, including configured type prefixes/suffixes. Generic `serializeValue(value, schema)` and `deserializeValue(value, schema)` accept a wire-schema object and return unknown. The schema registry used for local refs is embedded in the generated module. These functions convert declared names; `deserializeUser` does not assert that unknown input satisfies the User schema. Nullability, dictionary keys, enum values, and binary values are preserved. `propertyNaming: "preserve"` retains wire property names and omits the conversion module.
|