schemantic 0.3.0 → 0.4.1

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