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/CONFIGURATION.md
CHANGED
|
@@ -1,722 +1,81 @@
|
|
|
1
|
-
# Configuration
|
|
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
|
-
"plugins": [
|
|
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
|
-
|
|
82
|
-
URL to the OpenAPI schema endpoint.
|
|
83
|
-
|
|
84
|
-
```typescript
|
|
85
|
-
schemaUrl: "http://localhost:8000/openapi.json";
|
|
86
|
-
```
|
|
87
|
-
|
|
88
|
-
Common framework endpoints:
|
|
89
|
-
|
|
90
|
-
- FastAPI (default): `http://localhost:8000/openapi.json`
|
|
91
|
-
- ASP.NET Core (.NET): `https://localhost:5001/swagger/v1/swagger.json`
|
|
92
|
-
|
|
93
|
-
Examples to fetch a local snapshot:
|
|
94
|
-
|
|
95
|
-
```bash
|
|
96
|
-
# FastAPI
|
|
97
|
-
curl -s http://localhost:8000/openapi.json -o ./openapi-schema.json
|
|
98
|
-
|
|
99
|
-
# ASP.NET Core (.NET) — dev certs
|
|
100
|
-
curl -k -s https://localhost:5001/swagger/v1/swagger.json -o ./openapi-schema.json
|
|
101
|
-
|
|
102
|
-
# Generate from file
|
|
103
|
-
npx schemantic generate --file ./openapi-schema.json --output ./src/generated --client --types
|
|
104
|
-
```
|
|
105
|
-
|
|
106
|
-
#### `schemaFile`
|
|
107
|
-
|
|
108
|
-
Path to a local OpenAPI schema file.
|
|
109
|
-
|
|
110
|
-
```typescript
|
|
111
|
-
schemaFile: "./schema.json";
|
|
112
|
-
```
|
|
113
|
-
|
|
114
|
-
#### `schemaData`
|
|
115
|
-
|
|
116
|
-
OpenAPI schema object (for programmatic usage).
|
|
117
|
-
|
|
118
|
-
```typescript
|
|
119
|
-
schemaData: {
|
|
120
|
-
openapi: '3.0.0',
|
|
121
|
-
info: { title: 'My API', version: '1.0.0' },
|
|
122
|
-
paths: { /* ... */ }
|
|
123
|
-
}
|
|
124
|
-
```
|
|
125
|
-
|
|
126
|
-
### Output Configuration
|
|
127
|
-
|
|
128
|
-
#### `outputDir`
|
|
129
|
-
|
|
130
|
-
Directory where generated files will be saved.
|
|
131
|
-
|
|
132
|
-
```typescript
|
|
133
|
-
outputDir: "./src/generated";
|
|
134
|
-
```
|
|
135
|
-
|
|
136
|
-
#### `outputFileName`
|
|
137
|
-
|
|
138
|
-
Custom filename for the generated API client.
|
|
139
|
-
|
|
140
|
-
```typescript
|
|
141
|
-
outputFileName: "api-client.ts";
|
|
142
|
-
```
|
|
143
|
-
|
|
144
|
-
### Generation Options
|
|
145
|
-
|
|
146
|
-
#### `generateTypes`
|
|
147
|
-
|
|
148
|
-
Whether to generate TypeScript types.
|
|
149
|
-
|
|
150
|
-
```typescript
|
|
151
|
-
generateTypes: true;
|
|
152
|
-
```
|
|
153
|
-
|
|
154
|
-
#### `generateApiClient`
|
|
155
|
-
|
|
156
|
-
Whether to generate API client.
|
|
157
|
-
|
|
158
|
-
```typescript
|
|
159
|
-
generateApiClient: true;
|
|
160
|
-
```
|
|
161
|
-
|
|
162
|
-
#### `generateHooks`
|
|
163
|
-
|
|
164
|
-
Whether to generate React hooks factory.
|
|
165
|
-
|
|
166
|
-
```typescript
|
|
167
|
-
generateHooks: false;
|
|
168
|
-
```
|
|
169
|
-
|
|
170
|
-
When enabled, generates `hooks.ts` with a `createApiHooks(client)` function that returns query and mutation hooks for each endpoint. The hooks follow React patterns:
|
|
171
|
-
|
|
172
|
-
- Query hooks (GET methods): `useXxxQuery` with automatic fetching
|
|
173
|
-
- Mutation hooks (POST/PUT/PATCH/DELETE): `useXxxMutation` with manual trigger
|
|
174
|
-
|
|
175
|
-
Example usage:
|
|
176
|
-
|
|
177
|
-
```typescript
|
|
178
|
-
import { ECommerceApiClient, createApiHooks } from "./generated";
|
|
179
|
-
|
|
180
|
-
const client = new ECommerceApiClient({ baseUrl: "http://localhost:8000" });
|
|
181
|
-
const { useGetUsersUsersGetQuery, useCreateUserUsersPostMutation } =
|
|
182
|
-
createApiHooks(client);
|
|
183
|
-
|
|
184
|
-
function UsersList() {
|
|
185
|
-
const { data, loading, error, refetch } = useGetUsersUsersGetQuery();
|
|
186
|
-
const { mutate: createUser } = useCreateUserUsersPostMutation();
|
|
187
|
-
// ... component logic
|
|
188
|
-
}
|
|
189
|
-
```
|
|
190
|
-
|
|
191
|
-
#### `generateQueries`
|
|
192
|
-
|
|
193
|
-
Whether to generate query builders.
|
|
194
|
-
|
|
195
|
-
```typescript
|
|
196
|
-
generateQueries: false;
|
|
197
|
-
```
|
|
198
|
-
|
|
199
|
-
### TypeScript Configuration
|
|
200
|
-
|
|
201
|
-
#### `useStrictTypes`
|
|
202
|
-
|
|
203
|
-
Whether to use strict TypeScript types.
|
|
204
|
-
|
|
205
|
-
```typescript
|
|
206
|
-
useStrictTypes: true;
|
|
207
|
-
```
|
|
208
|
-
|
|
209
|
-
#### `useOptionalChaining`
|
|
210
|
-
|
|
211
|
-
Whether to use optional chaining (`?.`).
|
|
212
|
-
|
|
213
|
-
```typescript
|
|
214
|
-
useOptionalChaining: true;
|
|
215
|
-
```
|
|
216
|
-
|
|
217
|
-
#### `useNullishCoalescing`
|
|
218
|
-
|
|
219
|
-
Whether to use nullish coalescing (`??`).
|
|
220
|
-
|
|
221
|
-
```typescript
|
|
222
|
-
useNullishCoalescing: true;
|
|
223
|
-
```
|
|
224
|
-
|
|
225
|
-
### Naming Conventions
|
|
226
|
-
|
|
227
|
-
#### `namingConvention`
|
|
228
|
-
|
|
229
|
-
Naming convention for generated types and methods.
|
|
230
|
-
|
|
231
|
-
```typescript
|
|
232
|
-
namingConvention: "camelCase"; // 'camelCase' | 'snake_case' | 'PascalCase'
|
|
233
|
-
```
|
|
234
|
-
|
|
235
|
-
Examples:
|
|
236
|
-
|
|
237
|
-
- `camelCase`: `getUser`, `createUser`, `userId`
|
|
238
|
-
- `snake_case`: `get_user`, `create_user`, `user_id`
|
|
239
|
-
- `PascalCase`: `GetUser`, `CreateUser`, `UserId`
|
|
240
|
-
|
|
241
|
-
#### `typePrefix`
|
|
242
|
-
|
|
243
|
-
Prefix to add to generated type names.
|
|
244
|
-
|
|
245
|
-
```typescript
|
|
246
|
-
typePrefix: ""; // empty by default (no prefix)
|
|
247
|
-
```
|
|
248
|
-
|
|
249
|
-
By default no prefix is added. Set a value here to add one, e.g. `"MyAPI"` to produce `MyAPIUser`.
|
|
250
|
-
|
|
251
|
-
#### `typeSuffix`
|
|
252
|
-
|
|
253
|
-
Suffix to add to generated type names.
|
|
254
|
-
|
|
255
|
-
```typescript
|
|
256
|
-
typeSuffix: "Type";
|
|
257
|
-
```
|
|
258
|
-
|
|
259
|
-
This will generate types like `UserType`, `ProductType`, etc.
|
|
260
|
-
|
|
261
|
-
### Customization
|
|
262
|
-
|
|
263
|
-
#### `customTypeMappings`
|
|
264
|
-
|
|
265
|
-
Custom mappings for OpenAPI schema types to TypeScript types.
|
|
266
|
-
|
|
267
|
-
```typescript
|
|
268
|
-
customTypeMappings: {
|
|
269
|
-
'uuid': 'string',
|
|
270
|
-
'datetime': 'Date',
|
|
271
|
-
'decimal': 'number',
|
|
272
|
-
'email': 'string',
|
|
273
|
-
'password': 'string'
|
|
274
|
-
}
|
|
275
|
-
```
|
|
276
|
-
|
|
277
|
-
#### `excludePaths`
|
|
278
|
-
|
|
279
|
-
Paths to exclude from API client generation.
|
|
280
|
-
|
|
281
|
-
```typescript
|
|
282
|
-
excludePaths: ["/health", "/docs", "/redoc"];
|
|
283
|
-
```
|
|
284
|
-
|
|
285
|
-
#### `includePaths`
|
|
286
|
-
|
|
287
|
-
Paths to include in API client generation (all others will be excluded).
|
|
288
|
-
|
|
289
|
-
```typescript
|
|
290
|
-
includePaths: ["/api/v1/*"];
|
|
291
|
-
```
|
|
292
|
-
|
|
293
|
-
#### `excludeSchemas`
|
|
294
|
-
|
|
295
|
-
Schema names to exclude from type generation.
|
|
296
|
-
|
|
297
|
-
```typescript
|
|
298
|
-
excludeSchemas: ["Error", "ValidationError", "InternalError"];
|
|
299
|
-
```
|
|
300
|
-
|
|
301
|
-
#### `includeSchemas`
|
|
302
|
-
|
|
303
|
-
Schema names to include in type generation (all others will be excluded).
|
|
304
|
-
|
|
305
|
-
```typescript
|
|
306
|
-
includeSchemas: ["User", "Product", "Order"];
|
|
307
|
-
```
|
|
308
|
-
|
|
309
|
-
### Plugin Configuration
|
|
310
|
-
|
|
311
|
-
#### `plugins`
|
|
312
|
-
|
|
313
|
-
Array of plugin configurations.
|
|
314
|
-
|
|
315
|
-
```typescript
|
|
316
|
-
plugins: [
|
|
317
|
-
{ name: "jsdoc", enabled: true },
|
|
318
|
-
{ name: "validation", enabled: true },
|
|
319
|
-
// { name: "react-hooks", enabled: false }, // temporarily disabled project-wide
|
|
320
|
-
{ name: "custom-plugin", enabled: true, options: { debug: true } },
|
|
321
|
-
];
|
|
322
|
-
```
|
|
323
|
-
|
|
324
|
-
Plugin configuration options:
|
|
325
|
-
|
|
326
|
-
- `name`: Plugin name (required)
|
|
327
|
-
- `enabled`: Whether the plugin is enabled (required)
|
|
328
|
-
- `options`: Plugin-specific options (optional)
|
|
329
|
-
|
|
330
|
-
### Advanced Options
|
|
331
|
-
|
|
332
|
-
#### `preserveComments`
|
|
333
|
-
|
|
334
|
-
Whether to preserve comments from the OpenAPI schema.
|
|
335
|
-
|
|
336
|
-
```typescript
|
|
337
|
-
preserveComments: true;
|
|
338
|
-
```
|
|
339
|
-
|
|
340
|
-
#### `generateIndexFile`
|
|
341
|
-
|
|
342
|
-
Whether to generate an index file that exports all generated types.
|
|
343
|
-
|
|
344
|
-
```typescript
|
|
345
|
-
generateIndexFile: true;
|
|
346
|
-
```
|
|
347
|
-
|
|
348
|
-
#### `generateBarrelExports`
|
|
349
|
-
|
|
350
|
-
Whether to generate barrel export files.
|
|
351
|
-
|
|
352
|
-
```typescript
|
|
353
|
-
generateBarrelExports: true;
|
|
354
|
-
```
|
|
355
|
-
|
|
356
|
-
## Environment Variables
|
|
357
|
-
|
|
358
|
-
You can use environment variables for configuration:
|
|
359
|
-
|
|
360
|
-
```bash
|
|
361
|
-
export TYPE_SYNC_SCHEMA_URL="http://localhost:8000/openapi.json"
|
|
362
|
-
export TYPE_SYNC_OUTPUT_DIR="./generated"
|
|
363
|
-
export TYPE_SYNC_NAMING_CONVENTION="camelCase"
|
|
364
|
-
```
|
|
365
|
-
|
|
366
|
-
Access in configuration:
|
|
367
|
-
|
|
368
|
-
```typescript
|
|
369
|
-
const config: SchemanticConfig = {
|
|
370
|
-
schemaUrl: process.env.TYPE_SYNC_SCHEMA_URL,
|
|
371
|
-
outputDir: process.env.TYPE_SYNC_OUTPUT_DIR || "./generated",
|
|
372
|
-
namingConvention:
|
|
373
|
-
(process.env.TYPE_SYNC_NAMING_CONVENTION as any) || "camelCase",
|
|
374
|
-
};
|
|
375
|
-
```
|
|
376
|
-
|
|
377
|
-
## CLI Configuration
|
|
378
|
-
|
|
379
|
-
### Global Options
|
|
380
|
-
|
|
381
|
-
```bash
|
|
382
|
-
--verbose, -v # Verbose output
|
|
383
|
-
--quiet, -q # Quiet output
|
|
384
|
-
--no-color # Disable colored output
|
|
385
|
-
--config <file> # Configuration file path
|
|
386
|
-
```
|
|
387
|
-
|
|
388
|
-
### Input Options
|
|
389
|
-
|
|
390
|
-
```bash
|
|
391
|
-
--url, -u <url> # OpenAPI schema URL
|
|
392
|
-
--file, -f <file> # OpenAPI schema file path
|
|
393
|
-
```
|
|
394
|
-
|
|
395
|
-
### Output Options
|
|
396
|
-
|
|
397
|
-
```bash
|
|
398
|
-
--output, -o <dir> # Output directory
|
|
399
|
-
```
|
|
400
|
-
|
|
401
|
-
### Generation Options
|
|
402
|
-
|
|
403
|
-
```bash
|
|
404
|
-
--types # Generate types only
|
|
405
|
-
--client # Generate API client only
|
|
406
|
-
--hooks # Generate React hooks factory
|
|
407
|
-
```
|
|
408
|
-
|
|
409
|
-
### TypeScript Options
|
|
410
|
-
|
|
411
|
-
```bash
|
|
412
|
-
--strict # Use strict TypeScript types
|
|
413
|
-
--naming <convention> # Naming convention
|
|
414
|
-
```
|
|
415
|
-
|
|
416
|
-
### Customization Options
|
|
417
|
-
|
|
418
|
-
```bash
|
|
419
|
-
--prefix <prefix> # Type name prefix
|
|
420
|
-
--suffix <suffix> # Type name suffix
|
|
421
|
-
--exclude-paths <paths> # Exclude paths (comma-separated)
|
|
422
|
-
--include-paths <paths> # Include paths (comma-separated)
|
|
423
|
-
--exclude-schemas <schemas> # Exclude schemas (comma-separated)
|
|
424
|
-
--include-schemas <schemas> # Include schemas (comma-separated)
|
|
425
|
-
```
|
|
426
|
-
|
|
427
|
-
### Plugin Options
|
|
428
|
-
|
|
429
|
-
```bash
|
|
430
|
-
--plugins <plugins> # Enable plugins (comma-separated)
|
|
431
|
-
```
|
|
432
|
-
|
|
433
|
-
## Configuration Examples
|
|
434
|
-
|
|
435
|
-
### Basic Configuration
|
|
436
|
-
|
|
437
|
-
```typescript
|
|
438
|
-
const basicConfig: SchemanticConfig = {
|
|
439
|
-
schemaUrl: "http://localhost:8000/openapi.json",
|
|
440
|
-
outputDir: "./generated",
|
|
441
|
-
generateTypes: true,
|
|
442
|
-
generateApiClient: true,
|
|
443
|
-
};
|
|
444
|
-
```
|
|
445
|
-
|
|
446
|
-
### Advanced Configuration
|
|
447
|
-
|
|
448
|
-
```typescript
|
|
449
|
-
const advancedConfig: SchemanticConfig = {
|
|
450
|
-
schemaUrl: "http://localhost:8000/openapi.json",
|
|
451
|
-
outputDir: "./src/generated",
|
|
452
|
-
outputFileName: "api-client.ts",
|
|
453
|
-
|
|
454
|
-
generateTypes: true,
|
|
455
|
-
generateApiClient: true,
|
|
456
|
-
generateHooks: true,
|
|
457
|
-
|
|
458
|
-
useStrictTypes: true,
|
|
459
|
-
useOptionalChaining: true,
|
|
460
|
-
useNullishCoalescing: true,
|
|
461
|
-
|
|
462
|
-
namingConvention: "camelCase",
|
|
463
|
-
typePrefix: "",
|
|
464
|
-
typeSuffix: "Type",
|
|
465
|
-
|
|
466
|
-
customTypeMappings: {
|
|
467
|
-
uuid: "string",
|
|
468
|
-
datetime: "Date",
|
|
469
|
-
decimal: "number",
|
|
470
|
-
},
|
|
471
|
-
|
|
472
|
-
excludePaths: ["/health", "/docs", "/redoc"],
|
|
473
|
-
includePaths: ["/api/v1/*"],
|
|
474
|
-
|
|
475
|
-
excludeSchemas: ["Error", "ValidationError"],
|
|
476
|
-
includeSchemas: ["User", "Product", "Order"],
|
|
477
|
-
|
|
478
|
-
plugins: [
|
|
479
|
-
{ name: "jsdoc", enabled: true },
|
|
480
|
-
{ name: "validation", enabled: true },
|
|
481
|
-
{ name: "react-hooks", enabled: true },
|
|
482
|
-
],
|
|
483
|
-
|
|
484
|
-
preserveComments: true,
|
|
485
|
-
generateIndexFile: true,
|
|
486
|
-
generateBarrelExports: true,
|
|
487
|
-
};
|
|
488
|
-
```
|
|
489
|
-
|
|
490
|
-
### FastAPI Specific Configuration
|
|
491
|
-
|
|
492
|
-
```typescript
|
|
493
|
-
const fastApiConfig: SchemanticConfig = {
|
|
494
|
-
schemaUrl: "http://localhost:8000/openapi.json",
|
|
495
|
-
outputDir: "./generated",
|
|
496
|
-
|
|
497
|
-
generateTypes: true,
|
|
498
|
-
generateApiClient: true,
|
|
499
|
-
|
|
500
|
-
useStrictTypes: true,
|
|
501
|
-
namingConvention: "camelCase",
|
|
502
|
-
|
|
503
|
-
customTypeMappings: {
|
|
504
|
-
uuid: "string",
|
|
505
|
-
datetime: "string",
|
|
506
|
-
date: "string",
|
|
507
|
-
time: "string",
|
|
508
|
-
email: "string",
|
|
509
|
-
url: "string",
|
|
510
|
-
password: "string",
|
|
511
|
-
},
|
|
512
|
-
|
|
513
|
-
excludePaths: ["/docs", "/redoc", "/openapi.json"],
|
|
514
|
-
|
|
515
|
-
plugins: [
|
|
516
|
-
{ name: "jsdoc", enabled: true },
|
|
517
|
-
{ name: "validation", enabled: true },
|
|
518
|
-
],
|
|
519
|
-
};
|
|
520
|
-
```
|
|
521
|
-
|
|
522
|
-
### React Application Configuration
|
|
523
|
-
|
|
524
|
-
```typescript
|
|
525
|
-
const reactConfig: SchemanticConfig = {
|
|
526
|
-
schemaUrl: "http://localhost:8000/openapi.json",
|
|
527
|
-
outputDir: "./src/api",
|
|
528
|
-
|
|
529
|
-
generateTypes: true,
|
|
530
|
-
generateApiClient: true,
|
|
531
|
-
generateHooks: true,
|
|
532
|
-
|
|
533
|
-
useStrictTypes: true,
|
|
534
|
-
namingConvention: "camelCase",
|
|
535
|
-
|
|
536
|
-
plugins: [
|
|
537
|
-
{ name: "jsdoc", enabled: true },
|
|
538
|
-
{ name: "react-hooks", enabled: true },
|
|
539
|
-
{ name: "validation", enabled: true },
|
|
540
|
-
],
|
|
541
|
-
|
|
542
|
-
generateIndexFile: true,
|
|
543
|
-
};
|
|
544
|
-
```
|
|
545
|
-
|
|
546
|
-
### Node.js Application Configuration
|
|
547
|
-
|
|
548
|
-
```typescript
|
|
549
|
-
const nodeConfig: SchemanticConfig = {
|
|
550
|
-
schemaUrl: "http://localhost:8000/openapi.json",
|
|
551
|
-
outputDir: "./lib/api",
|
|
552
|
-
|
|
553
|
-
generateTypes: true,
|
|
554
|
-
generateApiClient: true,
|
|
555
|
-
|
|
556
|
-
useStrictTypes: true,
|
|
557
|
-
namingConvention: "camelCase",
|
|
558
|
-
|
|
559
|
-
plugins: [
|
|
560
|
-
{ name: "jsdoc", enabled: true },
|
|
561
|
-
{ name: "validation", enabled: true },
|
|
562
|
-
],
|
|
563
|
-
|
|
564
|
-
generateIndexFile: true,
|
|
565
|
-
};
|
|
566
|
-
```
|
|
567
|
-
|
|
568
|
-
## Configuration Validation
|
|
569
|
-
|
|
570
|
-
Schemantic validates your configuration and will throw errors for:
|
|
571
|
-
|
|
572
|
-
- Missing required fields
|
|
573
|
-
- Invalid values
|
|
574
|
-
- Conflicting options
|
|
575
|
-
- Plugin configuration errors
|
|
576
|
-
|
|
577
|
-
Example validation errors:
|
|
578
|
-
|
|
579
|
-
```typescript
|
|
580
|
-
// Error: Missing required field
|
|
581
|
-
const invalidConfig = {
|
|
582
|
-
// Missing outputDir
|
|
583
|
-
schemaUrl: "http://localhost:8000/openapi.json",
|
|
584
|
-
};
|
|
585
|
-
|
|
586
|
-
// Error: Invalid naming convention
|
|
587
|
-
const invalidNamingConfig = {
|
|
588
|
-
schemaUrl: "http://localhost:8000/openapi.json",
|
|
589
|
-
outputDir: "./generated",
|
|
590
|
-
namingConvention: "invalid", // Must be 'camelCase', 'snake_case', or 'PascalCase'
|
|
591
|
-
};
|
|
592
|
-
|
|
593
|
-
// Error: Conflicting options
|
|
594
|
-
const conflictingConfig = {
|
|
595
|
-
schemaUrl: "http://localhost:8000/openapi.json",
|
|
596
|
-
outputDir: "./generated",
|
|
597
|
-
excludePaths: ["/api/*"],
|
|
598
|
-
includePaths: ["/api/v1/*"], // This conflicts with excludePaths
|
|
599
|
-
};
|
|
600
|
-
```
|
|
601
|
-
|
|
602
|
-
## Configuration Inheritance
|
|
603
|
-
|
|
604
|
-
You can extend configurations:
|
|
605
|
-
|
|
606
|
-
```typescript
|
|
607
|
-
const baseConfig: SchemanticConfig = {
|
|
608
|
-
schemaUrl: "http://localhost:8000/openapi.json",
|
|
609
|
-
outputDir: "./generated",
|
|
610
|
-
generateTypes: true,
|
|
611
|
-
generateApiClient: true,
|
|
612
|
-
useStrictTypes: true,
|
|
613
|
-
namingConvention: "camelCase",
|
|
614
|
-
};
|
|
615
|
-
|
|
616
|
-
const developmentConfig: SchemanticConfig = {
|
|
617
|
-
...baseConfig,
|
|
618
|
-
plugins: [
|
|
619
|
-
{ name: "jsdoc", enabled: true },
|
|
620
|
-
{ name: "validation", enabled: true },
|
|
621
|
-
],
|
|
622
|
-
};
|
|
623
|
-
|
|
624
|
-
const productionConfig: SchemanticConfig = {
|
|
625
|
-
...baseConfig,
|
|
626
|
-
outputDir: "./dist/api",
|
|
627
|
-
plugins: [{ name: "jsdoc", enabled: true }],
|
|
628
|
-
};
|
|
629
|
-
```
|
|
630
|
-
|
|
631
|
-
## Configuration Tips
|
|
632
|
-
|
|
633
|
-
### 1. Use Configuration Files
|
|
634
|
-
|
|
635
|
-
For complex configurations, use configuration files instead of CLI arguments:
|
|
636
|
-
|
|
637
|
-
```bash
|
|
638
|
-
# Instead of long CLI command
|
|
639
|
-
npx schemantic generate --url http://localhost:8000/openapi.json --output ./generated --naming camelCase --plugins jsdoc,validation
|
|
640
|
-
|
|
641
|
-
# Use configuration file
|
|
642
|
-
npx schemantic generate --config schemantic.config.json
|
|
643
|
-
```
|
|
644
|
-
|
|
645
|
-
### 2. Environment-Specific Configurations
|
|
646
|
-
|
|
647
|
-
Create different configurations for different environments:
|
|
648
|
-
|
|
649
|
-
```typescript
|
|
650
|
-
// config/development.ts
|
|
651
|
-
export const developmentConfig: SchemanticConfig = {
|
|
652
|
-
schemaUrl: "http://localhost:8000/openapi.json",
|
|
653
|
-
outputDir: "./src/generated",
|
|
654
|
-
plugins: [
|
|
655
|
-
{ name: "jsdoc", enabled: true },
|
|
656
|
-
{ name: "validation", enabled: true },
|
|
657
|
-
],
|
|
658
|
-
};
|
|
659
|
-
|
|
660
|
-
// config/production.ts
|
|
661
|
-
export const productionConfig: SchemanticConfig = {
|
|
662
|
-
schemaUrl: "https://api.example.com/openapi.json",
|
|
663
|
-
outputDir: "./dist/api",
|
|
664
|
-
plugins: [{ name: "jsdoc", enabled: true }],
|
|
665
|
-
};
|
|
666
|
-
```
|
|
667
|
-
|
|
668
|
-
### 3. Plugin Configuration
|
|
669
|
-
|
|
670
|
-
Configure plugins with options:
|
|
671
|
-
|
|
672
|
-
```typescript
|
|
673
|
-
plugins: [
|
|
674
|
-
{
|
|
675
|
-
name: "validation",
|
|
676
|
-
enabled: true,
|
|
677
|
-
options: {
|
|
678
|
-
strict: true,
|
|
679
|
-
addImports: true,
|
|
680
|
-
},
|
|
681
|
-
},
|
|
682
|
-
{
|
|
683
|
-
name: "react-hooks",
|
|
684
|
-
enabled: true,
|
|
685
|
-
options: {
|
|
686
|
-
useReactQuery: true,
|
|
687
|
-
generateMutations: true,
|
|
688
|
-
},
|
|
689
|
-
},
|
|
690
|
-
];
|
|
691
|
-
```
|
|
692
|
-
|
|
693
|
-
### 4. Path Filtering
|
|
694
|
-
|
|
695
|
-
Use path filtering to control what gets generated:
|
|
696
|
-
|
|
697
|
-
```typescript
|
|
698
|
-
// Only generate API v1 endpoints
|
|
699
|
-
includePaths: ['/api/v1/*'],
|
|
700
|
-
|
|
701
|
-
// Exclude documentation endpoints
|
|
702
|
-
excludePaths: ['/docs', '/redoc', '/openapi.json'],
|
|
703
|
-
|
|
704
|
-
// Only generate specific schemas
|
|
705
|
-
includeSchemas: ['User', 'Product', 'Order'],
|
|
706
|
-
```
|
|
707
|
-
|
|
708
|
-
### 5. Custom Type Mappings
|
|
709
|
-
|
|
710
|
-
Map OpenAPI types to your preferred TypeScript types:
|
|
711
|
-
|
|
712
|
-
```typescript
|
|
713
|
-
customTypeMappings: {
|
|
714
|
-
'uuid': 'string', // UUID to string
|
|
715
|
-
'datetime': 'Date', // DateTime to Date
|
|
716
|
-
'decimal': 'number', // Decimal to number
|
|
717
|
-
'email': 'string', // Email to string
|
|
718
|
-
'password': 'string', // Password to string
|
|
719
|
-
'binary': 'Buffer', // Binary to Buffer
|
|
720
|
-
'byte': 'string', // Byte to string (base64)
|
|
721
|
-
};
|
|
722
|
-
```
|
|
1
|
+
# Configuration
|
|
2
|
+
|
|
3
|
+
The constructor accepts `SchemanticOptions`, an input type with optional defaulted fields. `SchemanticConfig` describes the resolved configuration. A source is required for generation/validation; configuration initialization may omit it.
|
|
4
|
+
|
|
5
|
+
```ts
|
|
6
|
+
import { Schemantic } from 'schemantic';
|
|
7
|
+
import type { SchemanticOptions } from 'schemantic';
|
|
8
|
+
|
|
9
|
+
const options: SchemanticOptions = {
|
|
10
|
+
schemaFile: './openapi.json',
|
|
11
|
+
outputDir: './src/generated',
|
|
12
|
+
generateHooks: false,
|
|
13
|
+
};
|
|
14
|
+
const generator = new Schemantic(options);
|
|
15
|
+
console.log(generator.getConfig().outputDir);
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
The CLI supports JSON and CommonJS `.cjs`/`.js` configurations, not TypeScript or ESM configuration modules. Prefer `.cjs` when your project has `"type": "module"`.
|
|
19
|
+
|
|
20
|
+
```json
|
|
21
|
+
{
|
|
22
|
+
"schemaFile": "./openapi.json",
|
|
23
|
+
"outputDir": "./src/generated",
|
|
24
|
+
"generateTypes": true,
|
|
25
|
+
"generateApiClient": true,
|
|
26
|
+
"generateHooks": false,
|
|
27
|
+
"plugins": [{ "name": "jsdoc", "enabled": true }]
|
|
28
|
+
}
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
```js
|
|
32
|
+
// schemantic.config.cjs
|
|
33
|
+
module.exports = {
|
|
34
|
+
schemaFile: './openapi.json',
|
|
35
|
+
outputDir: './src/generated',
|
|
36
|
+
plugins: [{ name: './plugins/my-plugin.cjs', enabled: true }],
|
|
37
|
+
};
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
Discovery checks only the current directory, in order: `schemantic.config.json`, `schemantic.config.cjs`, then `schemantic.config.js`. Both `generate` and `validate` accept `--config [file]`; bare `--config` requires a discoverable configuration. Explicit paths override discovery. Schema/output/plugin file paths from a config are relative to its directory, while command-line paths are relative to the working directory. Package plugin names resolve from the consumer/config directory.
|
|
41
|
+
|
|
42
|
+
```sh
|
|
43
|
+
npx schemantic generate
|
|
44
|
+
npx schemantic validate --config ./schemantic.config.cjs
|
|
45
|
+
npx schemantic generate --config ./schemantic.config.json --file ./other.json --output ./other-output --verbose
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
Defaults are applied before config values, then explicit CLI values. An explicit schema source replaces the configured source. `--url` and `--file` together fail. Unknown fields and wrong field types fail: booleans must be JSON booleans, not strings. Unsupported active settings fail instead of silently doing nothing.
|
|
49
|
+
|
|
50
|
+
| Field | Default or contract |
|
|
51
|
+
| --- | --- |
|
|
52
|
+
| `schemaFile` / `schemaUrl` / `schemaData` | One source; file/URL input must be OpenAPI JSON |
|
|
53
|
+
| `outputDir` | `./src/generated` |
|
|
54
|
+
| `outputFileName` | `api-client.ts`; must be a safe output path |
|
|
55
|
+
| `generateTypes` | `true`; required model output accompanies a generated client |
|
|
56
|
+
| `generateApiClient` | `true` |
|
|
57
|
+
| `generateHooks` | `false`; requires client generation and consumer React |
|
|
58
|
+
| `generateIndexFile` | `true` |
|
|
59
|
+
| `useStrictTypes` | `true` |
|
|
60
|
+
| `namingConvention` | `camelCase`; controls generated identifiers, not JSON wire values |
|
|
61
|
+
| `propertyNaming` | `camelCase`; use `preserve` to retain wire properties in application types |
|
|
62
|
+
| `typePrefix` / `typeSuffix` | Empty strings |
|
|
63
|
+
| `includePaths` / `excludePaths` | Arrays of path patterns |
|
|
64
|
+
| `includeSchemas` / `excludeSchemas` | Arrays of schema names/patterns |
|
|
65
|
+
| `customTypeMappings` | Map of OpenAPI formats/type mappings to TypeScript strings |
|
|
66
|
+
| `plugins` | Array of `{ name, enabled, options? }`; name is builtin/file/package |
|
|
67
|
+
| `preserveComments` | `true` |
|
|
68
|
+
|
|
69
|
+
`generateQueries: true` is unavailable. Optional chaining and nullish coalescing syntax switches are retained for compatibility but disabling them is unsupported. The `strict-mode` plugin has been retired and fails with an actionable diagnostic; remove it from plugin configuration and use the core strict defaults. Plugin options are JSON objects; callable custom behavior belongs in programmatic plugin factories/runtime constructors.
|
|
70
|
+
|
|
71
|
+
`init --yes --template default|types|react` writes a JSON configuration. Existing files are protected; `init --force` explicitly replaces one. `--yes` accepts defaults, including hooks off for the default template. Interactive Enter follows the displayed `(Y/n)` or `(y/N)` choice.
|
|
72
|
+
|
|
73
|
+
Watch mode requires a local schema file. It watches that file, serializes regeneration, and reports failures with a nonzero process status. Remote polling and automatic schema repair are not provided.
|
|
74
|
+
|
|
75
|
+
## Property names and wire conversion
|
|
76
|
+
|
|
77
|
+
Schema-declared application properties use camelCase by default: `display_name` becomes `displayName`. The original wire schema is retained for serializers/deserializers. Generated JSON/form request bodies use wire names automatically; generated JSON responses use application names. Caller-supplied FormData is already a wire representation and retains its keys/boundaries. PascalCase type/class names remain separate from property naming. Dynamic dictionary keys and enum values are never globally renamed.
|
|
78
|
+
|
|
79
|
+
Use `propertyNaming: "preserve"` to retain the old application property shape; this mode omits `conversion.ts`. In camelCase mode, `conversion.ts` exports generic `serializeValue(value, wireSchema)`/`deserializeValue(value, wireSchema)` and typed helpers such as `serializeUser`/`deserializeUser` for generated component models. Helpers use local references, recursive schemas, arrays, and composition metadata. They convert names without validating the payload; apply the emitted validation helpers separately when needed.
|
|
80
|
+
|
|
81
|
+
Colliding names such as `user_id` and `userId` are rejected. Ambiguous unions whose matching variants rename values differently require a discriminator. Cyclic JavaScript payload objects are rejected; recursive schema references remain supported.
|