@cerios/openapi-to-zod 0.5.2 → 0.6.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/README.md +7 -16
- package/dist/cli.js +56 -325
- package/dist/cli.js.map +1 -1
- package/dist/cli.mjs +56 -325
- package/dist/cli.mjs.map +1 -1
- package/dist/index.d.mts +1 -77
- package/dist/index.d.ts +1 -77
- package/dist/index.js +51 -312
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +51 -312
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -50,18 +50,6 @@ declare class CliOptionsError extends GeneratorError {
|
|
|
50
50
|
constructor(message: string, context?: Record<string, unknown>);
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
-
/**
|
|
54
|
-
* Type generation mode
|
|
55
|
-
* - 'inferred': Generate Zod schemas with z.infer<typeof schema> types (default)
|
|
56
|
-
* - 'native': Generate native TypeScript types without Zod schemas
|
|
57
|
-
*/
|
|
58
|
-
type TypeMode = "inferred" | "native";
|
|
59
|
-
/**
|
|
60
|
-
* Native enum generation type (used when typeMode is 'native')
|
|
61
|
-
* - 'union': Generate union types like 'a' | 'b' | 'c' (default)
|
|
62
|
-
* - 'enum': Generate TypeScript enums like enum StatusEnum { A = 'a', B = 'b' }
|
|
63
|
-
*/
|
|
64
|
-
type NativeEnumType = "union" | "enum";
|
|
65
53
|
/**
|
|
66
54
|
* Common options shared by both request and response contexts
|
|
67
55
|
*/
|
|
@@ -73,12 +61,6 @@ interface CommonSchemaOptions {
|
|
|
73
61
|
* - 'loose': Uses z.looseObject() - explicitly allows additional properties
|
|
74
62
|
*/
|
|
75
63
|
mode?: "strict" | "normal" | "loose";
|
|
76
|
-
/**
|
|
77
|
-
* Enum generation type
|
|
78
|
-
* - 'zod': Uses z.enum() with inferred types (default)
|
|
79
|
-
* - 'typescript': Uses TypeScript enums with z.enum() referencing them
|
|
80
|
-
*/
|
|
81
|
-
enumType?: "zod" | "typescript";
|
|
82
64
|
/**
|
|
83
65
|
* Whether to add .describe() calls for better error messages
|
|
84
66
|
* @default false
|
|
@@ -91,25 +73,11 @@ interface CommonSchemaOptions {
|
|
|
91
73
|
}
|
|
92
74
|
/**
|
|
93
75
|
* Request-specific options that can override root-level options
|
|
94
|
-
* Requests support native TypeScript type generation as an alternative to Zod schemas
|
|
95
76
|
*/
|
|
96
77
|
interface RequestOptions extends CommonSchemaOptions {
|
|
97
|
-
/**
|
|
98
|
-
* Type generation mode
|
|
99
|
-
* - 'inferred': Generate Zod schemas with z.infer types (default)
|
|
100
|
-
* - 'native': Generate native TypeScript types without Zod validation
|
|
101
|
-
*/
|
|
102
|
-
typeMode?: TypeMode;
|
|
103
|
-
/**
|
|
104
|
-
* Native enum generation type (when typeMode is 'native')
|
|
105
|
-
* - 'union': Generate union types (default)
|
|
106
|
-
* - 'enum': Generate TypeScript enums
|
|
107
|
-
*/
|
|
108
|
-
nativeEnumType?: NativeEnumType;
|
|
109
78
|
}
|
|
110
79
|
/**
|
|
111
80
|
* Response-specific options that can override root-level options
|
|
112
|
-
* Responses always use Zod schemas for runtime validation
|
|
113
81
|
*/
|
|
114
82
|
interface ResponseOptions extends CommonSchemaOptions {
|
|
115
83
|
}
|
|
@@ -135,12 +103,6 @@ interface OpenApiGeneratorOptions {
|
|
|
135
103
|
* Whether to include descriptions as JSDoc comments
|
|
136
104
|
*/
|
|
137
105
|
includeDescriptions?: boolean;
|
|
138
|
-
/**
|
|
139
|
-
* Enum generation type
|
|
140
|
-
* - 'zod': Uses z.enum() with inferred types (default)
|
|
141
|
-
* - 'typescript': Uses TypeScript enums with z.enum() referencing them
|
|
142
|
-
*/
|
|
143
|
-
enumType?: "zod" | "typescript";
|
|
144
106
|
/**
|
|
145
107
|
* Whether to add .describe() calls for better error messages
|
|
146
108
|
* @default false
|
|
@@ -168,23 +130,14 @@ interface OpenApiGeneratorOptions {
|
|
|
168
130
|
* @default true
|
|
169
131
|
*/
|
|
170
132
|
showStats?: boolean;
|
|
171
|
-
/**
|
|
172
|
-
* Native enum generation type (when typeMode is 'native')
|
|
173
|
-
* - 'union': Generate union types (default)
|
|
174
|
-
* - 'enum': Generate TypeScript enums with 'Enum' suffix
|
|
175
|
-
* @default 'union'
|
|
176
|
-
*/
|
|
177
|
-
nativeEnumType?: NativeEnumType;
|
|
178
133
|
/**
|
|
179
134
|
* Request-specific options that override root-level options
|
|
180
135
|
* Applied when schemas are used in request contexts
|
|
181
|
-
* Supports native TypeScript type generation
|
|
182
136
|
*/
|
|
183
137
|
request?: RequestOptions;
|
|
184
138
|
/**
|
|
185
139
|
* Response-specific options that override root-level options
|
|
186
140
|
* Applied when schemas are used in response contexts
|
|
187
|
-
* Always generates Zod schemas for runtime validation
|
|
188
141
|
*/
|
|
189
142
|
response?: ResponseOptions;
|
|
190
143
|
/**
|
|
@@ -392,14 +345,11 @@ declare function defineConfig(config: ConfigFile): ConfigFile;
|
|
|
392
345
|
declare class OpenApiGenerator {
|
|
393
346
|
private schemas;
|
|
394
347
|
private types;
|
|
395
|
-
private enums;
|
|
396
|
-
private nativeEnums;
|
|
397
348
|
private schemaDependencies;
|
|
398
349
|
private options;
|
|
399
350
|
private spec;
|
|
400
351
|
private propertyGenerator;
|
|
401
352
|
private schemaUsageMap;
|
|
402
|
-
private schemaTypeModeMap;
|
|
403
353
|
private requestOptions;
|
|
404
354
|
private responseOptions;
|
|
405
355
|
private needsZodImport;
|
|
@@ -421,7 +371,6 @@ declare class OpenApiGenerator {
|
|
|
421
371
|
/**
|
|
422
372
|
* Resolve options for a specific context (request or response)
|
|
423
373
|
* Nested options silently override root-level options
|
|
424
|
-
* Response schemas always use 'inferred' mode (Zod schemas)
|
|
425
374
|
*/
|
|
426
375
|
private resolveOptionsForContext;
|
|
427
376
|
/**
|
|
@@ -449,11 +398,6 @@ declare class OpenApiGenerator {
|
|
|
449
398
|
* Detect circular references and mark them as "both" context for safety
|
|
450
399
|
*/
|
|
451
400
|
private detectCircularReferences;
|
|
452
|
-
/**
|
|
453
|
-
* Determine the typeMode for each schema based on its usage context
|
|
454
|
-
* Response schemas always use 'inferred' mode
|
|
455
|
-
*/
|
|
456
|
-
private determineSchemaTypeModes;
|
|
457
401
|
/**
|
|
458
402
|
* Validate the OpenAPI specification
|
|
459
403
|
*/
|
|
@@ -479,26 +423,6 @@ declare class OpenApiGenerator {
|
|
|
479
423
|
* Generate Zod type for a query parameter schema
|
|
480
424
|
*/
|
|
481
425
|
private generateQueryParamType;
|
|
482
|
-
/**
|
|
483
|
-
* Generate native TypeScript enum
|
|
484
|
-
*/
|
|
485
|
-
private generateNativeEnum;
|
|
486
|
-
/**
|
|
487
|
-
* Convert string to valid enum key
|
|
488
|
-
*/
|
|
489
|
-
private toEnumKey;
|
|
490
|
-
/**
|
|
491
|
-
* Add constraint annotations to JSDoc for native types
|
|
492
|
-
*/
|
|
493
|
-
private addConstraintsToJSDoc;
|
|
494
|
-
/**
|
|
495
|
-
* Generate native TypeScript type definition from OpenAPI schema
|
|
496
|
-
*/
|
|
497
|
-
private generateNativeTypeDefinition;
|
|
498
|
-
/**
|
|
499
|
-
* Generate TypeScript object type definition
|
|
500
|
-
*/
|
|
501
|
-
private generateObjectType;
|
|
502
426
|
/**
|
|
503
427
|
* Topological sort for schema dependencies
|
|
504
428
|
* Returns schemas in the order they should be declared
|
|
@@ -561,4 +485,4 @@ declare function validateFilters(stats: FilterStatistics, filters?: OperationFil
|
|
|
561
485
|
*/
|
|
562
486
|
declare function formatFilterStatistics(stats: FilterStatistics): string;
|
|
563
487
|
|
|
564
|
-
export { CircularReferenceError, CliOptionsError, type CommonSchemaOptions, type ConfigFile, ConfigValidationError, type ExecutionMode, FileOperationError, type FilterStatistics, GeneratorError, type
|
|
488
|
+
export { CircularReferenceError, CliOptionsError, type CommonSchemaOptions, type ConfigFile, ConfigValidationError, type ExecutionMode, FileOperationError, type FilterStatistics, GeneratorError, type OpenAPISchema, type OpenAPISpec, OpenApiGenerator, type OpenApiGeneratorOptions, type OperationFilters, type RequestOptions, type ResponseOptions, SchemaGenerationError, SpecValidationError, createFilterStatistics, defineConfig, formatFilterStatistics, shouldIncludeOperation, validateFilters };
|
package/dist/index.d.ts
CHANGED
|
@@ -50,18 +50,6 @@ declare class CliOptionsError extends GeneratorError {
|
|
|
50
50
|
constructor(message: string, context?: Record<string, unknown>);
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
-
/**
|
|
54
|
-
* Type generation mode
|
|
55
|
-
* - 'inferred': Generate Zod schemas with z.infer<typeof schema> types (default)
|
|
56
|
-
* - 'native': Generate native TypeScript types without Zod schemas
|
|
57
|
-
*/
|
|
58
|
-
type TypeMode = "inferred" | "native";
|
|
59
|
-
/**
|
|
60
|
-
* Native enum generation type (used when typeMode is 'native')
|
|
61
|
-
* - 'union': Generate union types like 'a' | 'b' | 'c' (default)
|
|
62
|
-
* - 'enum': Generate TypeScript enums like enum StatusEnum { A = 'a', B = 'b' }
|
|
63
|
-
*/
|
|
64
|
-
type NativeEnumType = "union" | "enum";
|
|
65
53
|
/**
|
|
66
54
|
* Common options shared by both request and response contexts
|
|
67
55
|
*/
|
|
@@ -73,12 +61,6 @@ interface CommonSchemaOptions {
|
|
|
73
61
|
* - 'loose': Uses z.looseObject() - explicitly allows additional properties
|
|
74
62
|
*/
|
|
75
63
|
mode?: "strict" | "normal" | "loose";
|
|
76
|
-
/**
|
|
77
|
-
* Enum generation type
|
|
78
|
-
* - 'zod': Uses z.enum() with inferred types (default)
|
|
79
|
-
* - 'typescript': Uses TypeScript enums with z.enum() referencing them
|
|
80
|
-
*/
|
|
81
|
-
enumType?: "zod" | "typescript";
|
|
82
64
|
/**
|
|
83
65
|
* Whether to add .describe() calls for better error messages
|
|
84
66
|
* @default false
|
|
@@ -91,25 +73,11 @@ interface CommonSchemaOptions {
|
|
|
91
73
|
}
|
|
92
74
|
/**
|
|
93
75
|
* Request-specific options that can override root-level options
|
|
94
|
-
* Requests support native TypeScript type generation as an alternative to Zod schemas
|
|
95
76
|
*/
|
|
96
77
|
interface RequestOptions extends CommonSchemaOptions {
|
|
97
|
-
/**
|
|
98
|
-
* Type generation mode
|
|
99
|
-
* - 'inferred': Generate Zod schemas with z.infer types (default)
|
|
100
|
-
* - 'native': Generate native TypeScript types without Zod validation
|
|
101
|
-
*/
|
|
102
|
-
typeMode?: TypeMode;
|
|
103
|
-
/**
|
|
104
|
-
* Native enum generation type (when typeMode is 'native')
|
|
105
|
-
* - 'union': Generate union types (default)
|
|
106
|
-
* - 'enum': Generate TypeScript enums
|
|
107
|
-
*/
|
|
108
|
-
nativeEnumType?: NativeEnumType;
|
|
109
78
|
}
|
|
110
79
|
/**
|
|
111
80
|
* Response-specific options that can override root-level options
|
|
112
|
-
* Responses always use Zod schemas for runtime validation
|
|
113
81
|
*/
|
|
114
82
|
interface ResponseOptions extends CommonSchemaOptions {
|
|
115
83
|
}
|
|
@@ -135,12 +103,6 @@ interface OpenApiGeneratorOptions {
|
|
|
135
103
|
* Whether to include descriptions as JSDoc comments
|
|
136
104
|
*/
|
|
137
105
|
includeDescriptions?: boolean;
|
|
138
|
-
/**
|
|
139
|
-
* Enum generation type
|
|
140
|
-
* - 'zod': Uses z.enum() with inferred types (default)
|
|
141
|
-
* - 'typescript': Uses TypeScript enums with z.enum() referencing them
|
|
142
|
-
*/
|
|
143
|
-
enumType?: "zod" | "typescript";
|
|
144
106
|
/**
|
|
145
107
|
* Whether to add .describe() calls for better error messages
|
|
146
108
|
* @default false
|
|
@@ -168,23 +130,14 @@ interface OpenApiGeneratorOptions {
|
|
|
168
130
|
* @default true
|
|
169
131
|
*/
|
|
170
132
|
showStats?: boolean;
|
|
171
|
-
/**
|
|
172
|
-
* Native enum generation type (when typeMode is 'native')
|
|
173
|
-
* - 'union': Generate union types (default)
|
|
174
|
-
* - 'enum': Generate TypeScript enums with 'Enum' suffix
|
|
175
|
-
* @default 'union'
|
|
176
|
-
*/
|
|
177
|
-
nativeEnumType?: NativeEnumType;
|
|
178
133
|
/**
|
|
179
134
|
* Request-specific options that override root-level options
|
|
180
135
|
* Applied when schemas are used in request contexts
|
|
181
|
-
* Supports native TypeScript type generation
|
|
182
136
|
*/
|
|
183
137
|
request?: RequestOptions;
|
|
184
138
|
/**
|
|
185
139
|
* Response-specific options that override root-level options
|
|
186
140
|
* Applied when schemas are used in response contexts
|
|
187
|
-
* Always generates Zod schemas for runtime validation
|
|
188
141
|
*/
|
|
189
142
|
response?: ResponseOptions;
|
|
190
143
|
/**
|
|
@@ -392,14 +345,11 @@ declare function defineConfig(config: ConfigFile): ConfigFile;
|
|
|
392
345
|
declare class OpenApiGenerator {
|
|
393
346
|
private schemas;
|
|
394
347
|
private types;
|
|
395
|
-
private enums;
|
|
396
|
-
private nativeEnums;
|
|
397
348
|
private schemaDependencies;
|
|
398
349
|
private options;
|
|
399
350
|
private spec;
|
|
400
351
|
private propertyGenerator;
|
|
401
352
|
private schemaUsageMap;
|
|
402
|
-
private schemaTypeModeMap;
|
|
403
353
|
private requestOptions;
|
|
404
354
|
private responseOptions;
|
|
405
355
|
private needsZodImport;
|
|
@@ -421,7 +371,6 @@ declare class OpenApiGenerator {
|
|
|
421
371
|
/**
|
|
422
372
|
* Resolve options for a specific context (request or response)
|
|
423
373
|
* Nested options silently override root-level options
|
|
424
|
-
* Response schemas always use 'inferred' mode (Zod schemas)
|
|
425
374
|
*/
|
|
426
375
|
private resolveOptionsForContext;
|
|
427
376
|
/**
|
|
@@ -449,11 +398,6 @@ declare class OpenApiGenerator {
|
|
|
449
398
|
* Detect circular references and mark them as "both" context for safety
|
|
450
399
|
*/
|
|
451
400
|
private detectCircularReferences;
|
|
452
|
-
/**
|
|
453
|
-
* Determine the typeMode for each schema based on its usage context
|
|
454
|
-
* Response schemas always use 'inferred' mode
|
|
455
|
-
*/
|
|
456
|
-
private determineSchemaTypeModes;
|
|
457
401
|
/**
|
|
458
402
|
* Validate the OpenAPI specification
|
|
459
403
|
*/
|
|
@@ -479,26 +423,6 @@ declare class OpenApiGenerator {
|
|
|
479
423
|
* Generate Zod type for a query parameter schema
|
|
480
424
|
*/
|
|
481
425
|
private generateQueryParamType;
|
|
482
|
-
/**
|
|
483
|
-
* Generate native TypeScript enum
|
|
484
|
-
*/
|
|
485
|
-
private generateNativeEnum;
|
|
486
|
-
/**
|
|
487
|
-
* Convert string to valid enum key
|
|
488
|
-
*/
|
|
489
|
-
private toEnumKey;
|
|
490
|
-
/**
|
|
491
|
-
* Add constraint annotations to JSDoc for native types
|
|
492
|
-
*/
|
|
493
|
-
private addConstraintsToJSDoc;
|
|
494
|
-
/**
|
|
495
|
-
* Generate native TypeScript type definition from OpenAPI schema
|
|
496
|
-
*/
|
|
497
|
-
private generateNativeTypeDefinition;
|
|
498
|
-
/**
|
|
499
|
-
* Generate TypeScript object type definition
|
|
500
|
-
*/
|
|
501
|
-
private generateObjectType;
|
|
502
426
|
/**
|
|
503
427
|
* Topological sort for schema dependencies
|
|
504
428
|
* Returns schemas in the order they should be declared
|
|
@@ -561,4 +485,4 @@ declare function validateFilters(stats: FilterStatistics, filters?: OperationFil
|
|
|
561
485
|
*/
|
|
562
486
|
declare function formatFilterStatistics(stats: FilterStatistics): string;
|
|
563
487
|
|
|
564
|
-
export { CircularReferenceError, CliOptionsError, type CommonSchemaOptions, type ConfigFile, ConfigValidationError, type ExecutionMode, FileOperationError, type FilterStatistics, GeneratorError, type
|
|
488
|
+
export { CircularReferenceError, CliOptionsError, type CommonSchemaOptions, type ConfigFile, ConfigValidationError, type ExecutionMode, FileOperationError, type FilterStatistics, GeneratorError, type OpenAPISchema, type OpenAPISpec, OpenApiGenerator, type OpenApiGeneratorOptions, type OperationFilters, type RequestOptions, type ResponseOptions, SchemaGenerationError, SpecValidationError, createFilterStatistics, defineConfig, formatFilterStatistics, shouldIncludeOperation, validateFilters };
|