@cerios/openapi-to-zod 0.6.0 → 1.0.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/dist/index.d.mts CHANGED
@@ -1,3 +1,6 @@
1
+ import { O as OpenApiGeneratorOptions } from './types-BjoP91vk.mjs';
2
+ export { C as CommonSchemaOptions, a as ConfigFile, E as ExecutionMode, b as OpenAPISchema, c as OpenAPISpec, d as OperationFilters, R as RequestOptions, e as ResponseOptions, f as defineConfig } from './types-BjoP91vk.mjs';
3
+
1
4
  /**
2
5
  * Custom error classes for better error handling and debugging
3
6
  */
@@ -50,298 +53,6 @@ declare class CliOptionsError extends GeneratorError {
50
53
  constructor(message: string, context?: Record<string, unknown>);
51
54
  }
52
55
 
53
- /**
54
- * Common options shared by both request and response contexts
55
- */
56
- interface CommonSchemaOptions {
57
- /**
58
- * Object validation mode
59
- * - 'strict': Uses z.strictObject() - no additional properties allowed
60
- * - 'normal': Uses z.object() - additional properties allowed
61
- * - 'loose': Uses z.looseObject() - explicitly allows additional properties
62
- */
63
- mode?: "strict" | "normal" | "loose";
64
- /**
65
- * Whether to add .describe() calls for better error messages
66
- * @default false
67
- */
68
- useDescribe?: boolean;
69
- /**
70
- * Whether to include descriptions as JSDoc comments
71
- */
72
- includeDescriptions?: boolean;
73
- }
74
- /**
75
- * Request-specific options that can override root-level options
76
- */
77
- interface RequestOptions extends CommonSchemaOptions {
78
- }
79
- /**
80
- * Response-specific options that can override root-level options
81
- */
82
- interface ResponseOptions extends CommonSchemaOptions {
83
- }
84
- interface OpenApiGeneratorOptions {
85
- /**
86
- * Object validation mode
87
- * - 'strict': Uses z.strictObject() - no additional properties allowed
88
- * - 'normal': Uses z.object() - additional properties allowed
89
- * - 'loose': Uses z.looseObject() - explicitly allows additional properties
90
- */
91
- mode?: "strict" | "normal" | "loose";
92
- /**
93
- * Input OpenAPI YAML file path
94
- */
95
- input: string;
96
- /**
97
- * Output TypeScript file path
98
- * Optional when using string generation methods (generateString)
99
- * Required when calling generate() to write to a file
100
- */
101
- output?: string;
102
- /**
103
- * Whether to include descriptions as JSDoc comments
104
- */
105
- includeDescriptions?: boolean;
106
- /**
107
- * Whether to add .describe() calls for better error messages
108
- * @default false
109
- */
110
- useDescribe?: boolean;
111
- /**
112
- * Schema filtering mode
113
- * - 'all': Generate all schemas (default)
114
- * - 'request': Only include schemas suitable for requests (excludes readOnly)
115
- * - 'response': Only include schemas suitable for responses (excludes writeOnly)
116
- */
117
- schemaType?: "all" | "request" | "response";
118
- /**
119
- * Prefix to add to all generated schema names
120
- * @example "api" -> "apiUserSchema"
121
- */
122
- prefix?: string;
123
- /**
124
- * Suffix to add before "Schema" in generated names
125
- * @example "dto" -> "userDtoSchema"
126
- */
127
- suffix?: string;
128
- /**
129
- * Whether to include generation statistics in output file
130
- * @default true
131
- */
132
- showStats?: boolean;
133
- /**
134
- * Request-specific options that override root-level options
135
- * Applied when schemas are used in request contexts
136
- */
137
- request?: RequestOptions;
138
- /**
139
- * Response-specific options that override root-level options
140
- * Applied when schemas are used in response contexts
141
- */
142
- response?: ResponseOptions;
143
- /**
144
- * Filter which operations to include/exclude from generation
145
- * Useful for generating separate schemas for different API subsets
146
- *
147
- * Filtering logic:
148
- * 1. If no filters specified, all operations are included
149
- * 2. Empty arrays are treated as "no constraint" (not as "exclude all")
150
- * 3. Include filters are applied first (allowlist)
151
- * 4. Exclude filters are applied second (blocklist)
152
- * 5. Exclude rules always win over include rules
153
- *
154
- * Supports glob patterns for paths and operationIds (e.g., "/api/v1/**", "get*")
155
- *
156
- * @example
157
- * // Only generate schemas for user-related endpoints
158
- * operationFilters: {
159
- * includeTags: ["users"]
160
- * }
161
- *
162
- * @example
163
- * // Generate only GET endpoints, excluding deprecated ones
164
- * operationFilters: {
165
- * includeMethods: ["get"],
166
- * excludeDeprecated: true
167
- * }
168
- *
169
- * @example
170
- * // Generate only v1 API endpoints
171
- * operationFilters: {
172
- * includePaths: ["/api/v1/**"]
173
- * }
174
- */
175
- operationFilters?: OperationFilters;
176
- }
177
- /**
178
- * Operation filtering options
179
- * Controls which operations from the OpenAPI spec are included in generation
180
- */
181
- interface OperationFilters {
182
- /**
183
- * Include only operations with these tags
184
- * If specified, only operations with at least one matching tag are included
185
- * Empty array = no constraint
186
- */
187
- includeTags?: string[];
188
- /**
189
- * Exclude operations with these tags
190
- * Operations with any matching tag are excluded
191
- * Empty array = no constraint
192
- */
193
- excludeTags?: string[];
194
- /**
195
- * Include only operations matching these path patterns
196
- * Supports glob patterns (e.g., "/users/**", "/api/v1/*")
197
- * Empty array = no constraint
198
- */
199
- includePaths?: string[];
200
- /**
201
- * Exclude operations matching these path patterns
202
- * Supports glob patterns (e.g., "/internal/**", "/admin/*")
203
- * Empty array = no constraint
204
- */
205
- excludePaths?: string[];
206
- /**
207
- * Include only these HTTP methods
208
- * Valid values: "get", "post", "put", "patch", "delete", "head", "options"
209
- * Empty array = no constraint
210
- */
211
- includeMethods?: string[];
212
- /**
213
- * Exclude these HTTP methods
214
- * Valid values: "get", "post", "put", "patch", "delete", "head", "options"
215
- * Empty array = no constraint
216
- */
217
- excludeMethods?: string[];
218
- /**
219
- * Include only operations matching these operationId patterns
220
- * Supports glob patterns (e.g., "getUser*", "*Admin")
221
- * Empty array = no constraint
222
- */
223
- includeOperationIds?: string[];
224
- /**
225
- * Exclude operations matching these operationId patterns
226
- * Supports glob patterns (e.g., "deleteUser*", "*Internal")
227
- * Empty array = no constraint
228
- */
229
- excludeOperationIds?: string[];
230
- /**
231
- * Whether to exclude deprecated operations
232
- * @default false
233
- */
234
- excludeDeprecated?: boolean;
235
- }
236
- interface OpenAPISchema {
237
- type?: string | string[];
238
- format?: string;
239
- enum?: (string | number)[];
240
- const?: string | number | boolean | null;
241
- properties?: Record<string, OpenAPISchema>;
242
- required?: string[];
243
- items?: OpenAPISchema;
244
- prefixItems?: OpenAPISchema[];
245
- allOf?: OpenAPISchema[];
246
- oneOf?: OpenAPISchema[];
247
- anyOf?: OpenAPISchema[];
248
- $ref?: string;
249
- nullable?: boolean;
250
- minLength?: number;
251
- maxLength?: number;
252
- minimum?: number;
253
- maximum?: number;
254
- exclusiveMinimum?: boolean | number;
255
- exclusiveMaximum?: boolean | number;
256
- multipleOf?: number;
257
- pattern?: string;
258
- description?: string;
259
- title?: string;
260
- example?: any;
261
- examples?: any[];
262
- additionalProperties?: boolean | OpenAPISchema;
263
- minProperties?: number;
264
- maxProperties?: number;
265
- minItems?: number;
266
- maxItems?: number;
267
- uniqueItems?: boolean;
268
- contains?: OpenAPISchema;
269
- minContains?: number;
270
- maxContains?: number;
271
- discriminator?: {
272
- propertyName: string;
273
- mapping?: Record<string, string>;
274
- };
275
- readOnly?: boolean;
276
- writeOnly?: boolean;
277
- deprecated?: boolean;
278
- dependentRequired?: Record<string, string[]>;
279
- dependencies?: Record<string, string[] | OpenAPISchema>;
280
- patternProperties?: Record<string, OpenAPISchema>;
281
- propertyNames?: OpenAPISchema;
282
- contentMediaType?: string;
283
- contentEncoding?: string;
284
- not?: OpenAPISchema;
285
- if?: OpenAPISchema;
286
- then?: OpenAPISchema;
287
- else?: OpenAPISchema;
288
- unevaluatedProperties?: boolean | OpenAPISchema;
289
- unevaluatedItems?: boolean | OpenAPISchema;
290
- }
291
- interface OpenAPISpec {
292
- components?: {
293
- schemas?: Record<string, OpenAPISchema>;
294
- };
295
- paths?: Record<string, any>;
296
- }
297
- /**
298
- * Execution mode for batch processing
299
- * - 'parallel': Process all specs concurrently (default, faster)
300
- * - 'sequential': Process specs one at a time (safer for resource constraints)
301
- */
302
- type ExecutionMode = "parallel" | "sequential";
303
- /**
304
- * Root configuration file structure
305
- */
306
- interface ConfigFile {
307
- /**
308
- * Global default options applied to all specs
309
- * Can be overridden by individual spec configurations
310
- */
311
- defaults?: Partial<Omit<OpenApiGeneratorOptions, "input" | "output">>;
312
- /**
313
- * Array of OpenAPI specifications to process
314
- * Each spec must have input and output paths
315
- */
316
- specs: OpenApiGeneratorOptions[];
317
- /**
318
- * Execution mode for batch processing
319
- * @default "parallel"
320
- */
321
- executionMode?: ExecutionMode;
322
- }
323
- /**
324
- * Helper function for type-safe config file creation
325
- * Provides IDE autocomplete and type checking for config files
326
- *
327
- * @example
328
- * ```typescript
329
- * import { defineConfig } from '@cerios/openapi-to-zod';
330
- *
331
- * export default defineConfig({
332
- * defaults: {
333
- * mode: 'strict',
334
- * includeDescriptions: true
335
- * },
336
- * specs: [
337
- * { input: 'api-v1.yaml', output: 'schemas/v1.ts' },
338
- * { input: 'api-v2.yaml', output: 'schemas/v2.ts', mode: 'normal' }
339
- * ]
340
- * });
341
- * ```
342
- */
343
- declare function defineConfig(config: ConfigFile): ConfigFile;
344
-
345
56
  declare class OpenApiGenerator {
346
57
  private schemas;
347
58
  private types;
@@ -414,6 +125,11 @@ declare class OpenApiGenerator {
414
125
  * Generate query parameter schemas for each operation
415
126
  */
416
127
  private generateQueryParameterSchemas;
128
+ /**
129
+ * Check if a header should be ignored based on filter patterns
130
+ * @internal
131
+ */
132
+ private shouldIgnoreHeader;
417
133
  /**
418
134
  * Generate header parameter schemas for each operation
419
135
  * Header parameters are always string type (HTTP header semantics)
@@ -434,55 +150,4 @@ declare class OpenApiGenerator {
434
150
  private generateStats;
435
151
  }
436
152
 
437
- /**
438
- * Filter statistics to track which operations were included/excluded
439
- */
440
- interface FilterStatistics {
441
- totalOperations: number;
442
- includedOperations: number;
443
- filteredByTags: number;
444
- filteredByPaths: number;
445
- filteredByMethods: number;
446
- filteredByOperationIds: number;
447
- filteredByDeprecated: number;
448
- }
449
- /**
450
- * Create a new filter statistics object with all counters initialized to zero
451
- */
452
- declare function createFilterStatistics(): FilterStatistics;
453
- /**
454
- * Determine if an operation should be included based on filter criteria
455
- *
456
- * Filter logic:
457
- * 1. If no filters specified, include all operations
458
- * 2. Empty arrays are treated as "no constraint" (not as "exclude all")
459
- * 3. Include filters are applied first (allowlist)
460
- * 4. Exclude filters are applied second (blocklist)
461
- * 5. Exclude rules always win over include rules
462
- *
463
- * @param operation - The OpenAPI operation object
464
- * @param path - The operation path (e.g., "/users/{id}")
465
- * @param method - The HTTP method (e.g., "get", "post")
466
- * @param filters - Optional filter configuration
467
- * @param stats - Optional statistics object to track filtering reasons
468
- * @returns true if the operation should be included, false otherwise
469
- */
470
- declare function shouldIncludeOperation(operation: any, path: string, method: string, filters?: OperationFilters, stats?: FilterStatistics): boolean;
471
- /**
472
- * Validate filter statistics and emit warnings for filters that matched nothing
473
- * Helps users debug filter configurations that might be too restrictive or contain typos
474
- *
475
- * @param stats - Filter statistics object
476
- * @param filters - The filter configuration to validate
477
- */
478
- declare function validateFilters(stats: FilterStatistics, filters?: OperationFilters): void;
479
- /**
480
- * Format filter statistics for display in generated output
481
- * Returns a formatted string suitable for inclusion in comments
482
- *
483
- * @param stats - Filter statistics object
484
- * @returns Formatted statistics string
485
- */
486
- declare function formatFilterStatistics(stats: FilterStatistics): string;
487
-
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 };
153
+ export { CircularReferenceError, CliOptionsError, ConfigValidationError, FileOperationError, GeneratorError, OpenApiGenerator, OpenApiGeneratorOptions, SchemaGenerationError, SpecValidationError };