@cerios/openapi-to-zod 1.3.1 → 1.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.
@@ -1,4 +1,4 @@
1
- import { E as ExecutionMode, g as OperationFilters, f as OpenAPISpec, b as OpenAPIParameter, c as OpenAPIRequestBody, d as OpenAPIResponse, e as OpenAPISchema } from './types-DZ4Bw-D5.mjs';
1
+ import { E as ExecutionMode, e as OpenAPISchema, f as OpenAPISpec, g as OperationFilters, b as OpenAPIParameter, c as OpenAPIRequestBody, d as OpenAPIResponse } from './types-DZ4Bw-D5.mjs';
2
2
  import { z } from 'zod';
3
3
  import { Loader } from 'cosmiconfig';
4
4
 
@@ -46,6 +46,149 @@ declare function executeBatch<T>(specs: T[], executionMode: ExecutionMode | unde
46
46
  */
47
47
  declare function getBatchExitCode<T>(summary: BatchExecutionSummary<T>): number;
48
48
 
49
+ /**
50
+ * @shared Simple LRU Cache implementation for performance optimization
51
+ * @since 1.0.0
52
+ * Utility used by core and playwright packages
53
+ * Prevents memory leaks from unbounded cache growth
54
+ */
55
+ declare class LRUCache<K, V> {
56
+ private cache;
57
+ private maxSize;
58
+ constructor(maxSize: number);
59
+ get capacity(): number;
60
+ get(key: K): V | undefined;
61
+ set(key: K, value: V): void;
62
+ has(key: K): boolean;
63
+ clear(): void;
64
+ size(): number;
65
+ }
66
+
67
+ /**
68
+ * Name conversion utilities
69
+ */
70
+ interface NamingOptions {
71
+ prefix?: string;
72
+ suffix?: string;
73
+ }
74
+ /**
75
+ * Convert schema name to camelCase with optional prefix/suffix
76
+ * Handles dotted names like "Company.Models.User" -> "companyModelsUser"
77
+ */
78
+ declare function toCamelCase(str: string, options?: NamingOptions): string;
79
+ /**
80
+ * @shared Convert enum value to PascalCase and sanitize for TypeScript enum keys
81
+ * @since 1.0.0
82
+ * Utility used by core and playwright packages
83
+ * Handles dotted names like "Company.Models.User" -> "CompanyModelsUser"
84
+ */
85
+ declare function toPascalCase(str: string | number): string;
86
+
87
+ type ObjectMode = "strict" | "normal" | "loose";
88
+
89
+ interface PropertyGeneratorContext {
90
+ spec: OpenAPISpec;
91
+ schemaDependencies: Map<string, Set<string>>;
92
+ schemaType: "all" | "request" | "response";
93
+ mode: ObjectMode;
94
+ includeDescriptions: boolean;
95
+ useDescribe: boolean;
96
+ namingOptions: NamingOptions;
97
+ stripSchemaPrefix?: string;
98
+ /**
99
+ * Default nullable behavior when not explicitly specified
100
+ * @default false
101
+ */
102
+ defaultNullable: boolean;
103
+ /**
104
+ * Behavior for empty object schemas (objects with no properties defined)
105
+ * @default 'loose'
106
+ */
107
+ emptyObjectBehavior: "strict" | "loose" | "record";
108
+ /**
109
+ * Zod validation string for date-time format fields
110
+ * @default "z.iso.datetime()"
111
+ */
112
+ dateTimeValidation: string;
113
+ /**
114
+ * Instance-level cache for escaped regex patterns (parallel-safe)
115
+ */
116
+ patternCache: LRUCache<string, string>;
117
+ }
118
+ /**
119
+ * Property schema generator with memoization for performance
120
+ */
121
+ declare class PropertyGenerator {
122
+ private context;
123
+ private filteredPropsCache;
124
+ private schemaCache;
125
+ static readonly INCLUSION_RULES: {
126
+ readonly request: (schema: OpenAPISchema) => boolean;
127
+ readonly response: (schema: OpenAPISchema) => boolean;
128
+ readonly all: () => boolean;
129
+ };
130
+ constructor(context: PropertyGeneratorContext);
131
+ /**
132
+ * Check if a property should be included based on schemaType and readOnly/writeOnly flags
133
+ */
134
+ shouldIncludeProperty(schema: OpenAPISchema): boolean;
135
+ /**
136
+ * Recursively filter any schema type (helper for composition schemas)
137
+ */
138
+ private filterSchemaRecursive;
139
+ /**
140
+ * Recursively filter properties in nested objects based on readOnly/writeOnly
141
+ * Performance optimized with memoization
142
+ */
143
+ private filterNestedProperties;
144
+ /**
145
+ * Resolve discriminator mapping to actual schema references
146
+ */
147
+ private resolveDiscriminatorMapping;
148
+ /**
149
+ * Resolve a $ref string to the actual schema
150
+ */
151
+ private resolveSchemaRef;
152
+ /**
153
+ * Resolve a schema name through any aliases to get the actual schema name
154
+ * If the schema is an alias (allOf with single $ref), return the target name
155
+ */
156
+ private resolveSchemaAlias;
157
+ /**
158
+ * Check if this is a circular dependency through aliases
159
+ */
160
+ private isCircularThroughAlias;
161
+ /**
162
+ * Generate union for multiple types (OpenAPI 3.1)
163
+ */
164
+ private generateMultiTypeUnion;
165
+ /**
166
+ * Apply unevaluatedProperties validation to a schema
167
+ */
168
+ private applyUnevaluatedProperties;
169
+ /**
170
+ * Generate Zod schema for a property
171
+ * @param schema - The OpenAPI schema to generate
172
+ * @param currentSchema - The name of the current schema being processed (for circular ref detection)
173
+ * @param isTopLevel - Whether this is a top-level schema definition
174
+ * @param suppressDefaultNullable - When true, don't apply defaultNullable (used when outer schema has explicit nullable: false)
175
+ */
176
+ generatePropertySchema(schema: OpenAPISchema, currentSchema?: string, isTopLevel?: boolean, suppressDefaultNullable?: boolean): string;
177
+ /**
178
+ * Generate inline object shape for use with .extend()
179
+ * Returns just the shape object literal: { prop1: z.string(), prop2: z.number() }
180
+ *
181
+ * This method is specifically for allOf compositions where we need to pass
182
+ * the shape directly to .extend() instead of using z.object({...}).shape.
183
+ * This avoids the .nullable().shape bug when inline objects have nullable: true.
184
+ *
185
+ * According to Zod docs (https://zod.dev/api?id=extend):
186
+ * - .extend() accepts an object of shape definitions
187
+ * - e.g., baseSchema.extend({ prop: z.string() })
188
+ */
189
+ generateInlineObjectShape(schema: OpenAPISchema, currentSchema?: string): string;
190
+ }
191
+
49
192
  /**
50
193
  * @shared Zod schema for request/response options validation
51
194
  * @since 1.0.0
@@ -141,44 +284,6 @@ type FallbackContentTypeParsing = "json" | "text" | "body";
141
284
  */
142
285
  declare function getResponseParseMethod(contentType: string | undefined, fallback?: FallbackContentTypeParsing): ContentTypeParseResult;
143
286
 
144
- /**
145
- * @shared Simple LRU Cache implementation for performance optimization
146
- * @since 1.0.0
147
- * Utility used by core and playwright packages
148
- * Prevents memory leaks from unbounded cache growth
149
- */
150
- declare class LRUCache<K, V> {
151
- private cache;
152
- private maxSize;
153
- constructor(maxSize: number);
154
- get capacity(): number;
155
- get(key: K): V | undefined;
156
- set(key: K, value: V): void;
157
- has(key: K): boolean;
158
- clear(): void;
159
- size(): number;
160
- }
161
-
162
- /**
163
- * Name conversion utilities
164
- */
165
- interface NamingOptions {
166
- prefix?: string;
167
- suffix?: string;
168
- }
169
- /**
170
- * Convert schema name to camelCase with optional prefix/suffix
171
- * Handles dotted names like "Company.Models.User" -> "companyModelsUser"
172
- */
173
- declare function toCamelCase(str: string, options?: NamingOptions): string;
174
- /**
175
- * @shared Convert enum value to PascalCase and sanitize for TypeScript enum keys
176
- * @since 1.0.0
177
- * Utility used by core and playwright packages
178
- * Handles dotted names like "Company.Models.User" -> "CompanyModelsUser"
179
- */
180
- declare function toPascalCase(str: string | number): string;
181
-
182
287
  /**
183
288
  * Filter statistics to track which operations were included/excluded
184
289
  */
@@ -341,23 +446,25 @@ declare function escapeJSDoc(str: string): string;
341
446
  declare function createTypeScriptLoader(): Loader;
342
447
 
343
448
  /**
344
- * Configure custom date-time format validation
345
- * Overrides the default z.iso.datetime() with a custom regex pattern
449
+ * Build the Zod validation string for date-time format
450
+ * Pure function that returns the validation string without side effects
346
451
  *
347
- * @param pattern - Regex pattern (string or RegExp) for date-time validation
452
+ * @param pattern - Optional regex pattern (string or RegExp) for date-time validation
453
+ * @returns Zod validation string (either "z.iso.datetime()" or custom regex)
348
454
  * @throws {Error} If the provided pattern is not a valid regular expression
455
+ *
349
456
  * @example
350
- * // String pattern (required for JSON/YAML configs)
351
- * configureDateTimeFormat('^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}$')
457
+ * // Default (no pattern)
458
+ * buildDateTimeValidation() // Returns "z.iso.datetime()"
352
459
  *
353
460
  * @example
354
- * // RegExp literal (TypeScript configs only)
355
- * configureDateTimeFormat(/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}$/)
356
- */
357
- declare function configureDateTimeFormat(pattern?: string | RegExp): void;
358
- /**
359
- * Reset format map to defaults (useful for testing)
461
+ * // String pattern (for JSON/YAML configs)
462
+ * buildDateTimeValidation('^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}$')
463
+ *
464
+ * @example
465
+ * // RegExp literal (TypeScript configs)
466
+ * buildDateTimeValidation(/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}$/)
360
467
  */
361
- declare function resetFormatMap(): void;
468
+ declare function buildDateTimeValidation(pattern?: string | RegExp): string;
362
469
 
363
- export { type BaseOperationFilters, type ContentTypeParseResult, type FallbackContentTypeParsing, type FilterStatistics, type Generator, LRUCache, OperationFiltersSchema, type RequestResponseOptions, RequestResponseOptionsSchema, configureDateTimeFormat, createFilterStatistics, createTypeScriptLoader, escapeJSDoc, executeBatch, formatConfigValidationError, formatFilterStatistics, getBatchExitCode, getResponseParseMethod, mergeParameters, resetFormatMap, resolveParameterRef, resolveRef, resolveRequestBodyRef, resolveResponseRef, shouldIncludeOperation, stripPathPrefix, stripPrefix, toCamelCase, toPascalCase, validateFilters };
470
+ export { type BaseOperationFilters, type ContentTypeParseResult, type FallbackContentTypeParsing, type FilterStatistics, type Generator, LRUCache, OperationFiltersSchema, PropertyGenerator, type PropertyGeneratorContext, type RequestResponseOptions, RequestResponseOptionsSchema, buildDateTimeValidation, createFilterStatistics, createTypeScriptLoader, escapeJSDoc, executeBatch, formatConfigValidationError, formatFilterStatistics, getBatchExitCode, getResponseParseMethod, mergeParameters, resolveParameterRef, resolveRef, resolveRequestBodyRef, resolveResponseRef, shouldIncludeOperation, stripPathPrefix, stripPrefix, toCamelCase, toPascalCase, validateFilters };
@@ -1,4 +1,4 @@
1
- import { E as ExecutionMode, g as OperationFilters, f as OpenAPISpec, b as OpenAPIParameter, c as OpenAPIRequestBody, d as OpenAPIResponse, e as OpenAPISchema } from './types-DZ4Bw-D5.js';
1
+ import { E as ExecutionMode, e as OpenAPISchema, f as OpenAPISpec, g as OperationFilters, b as OpenAPIParameter, c as OpenAPIRequestBody, d as OpenAPIResponse } from './types-DZ4Bw-D5.js';
2
2
  import { z } from 'zod';
3
3
  import { Loader } from 'cosmiconfig';
4
4
 
@@ -46,6 +46,149 @@ declare function executeBatch<T>(specs: T[], executionMode: ExecutionMode | unde
46
46
  */
47
47
  declare function getBatchExitCode<T>(summary: BatchExecutionSummary<T>): number;
48
48
 
49
+ /**
50
+ * @shared Simple LRU Cache implementation for performance optimization
51
+ * @since 1.0.0
52
+ * Utility used by core and playwright packages
53
+ * Prevents memory leaks from unbounded cache growth
54
+ */
55
+ declare class LRUCache<K, V> {
56
+ private cache;
57
+ private maxSize;
58
+ constructor(maxSize: number);
59
+ get capacity(): number;
60
+ get(key: K): V | undefined;
61
+ set(key: K, value: V): void;
62
+ has(key: K): boolean;
63
+ clear(): void;
64
+ size(): number;
65
+ }
66
+
67
+ /**
68
+ * Name conversion utilities
69
+ */
70
+ interface NamingOptions {
71
+ prefix?: string;
72
+ suffix?: string;
73
+ }
74
+ /**
75
+ * Convert schema name to camelCase with optional prefix/suffix
76
+ * Handles dotted names like "Company.Models.User" -> "companyModelsUser"
77
+ */
78
+ declare function toCamelCase(str: string, options?: NamingOptions): string;
79
+ /**
80
+ * @shared Convert enum value to PascalCase and sanitize for TypeScript enum keys
81
+ * @since 1.0.0
82
+ * Utility used by core and playwright packages
83
+ * Handles dotted names like "Company.Models.User" -> "CompanyModelsUser"
84
+ */
85
+ declare function toPascalCase(str: string | number): string;
86
+
87
+ type ObjectMode = "strict" | "normal" | "loose";
88
+
89
+ interface PropertyGeneratorContext {
90
+ spec: OpenAPISpec;
91
+ schemaDependencies: Map<string, Set<string>>;
92
+ schemaType: "all" | "request" | "response";
93
+ mode: ObjectMode;
94
+ includeDescriptions: boolean;
95
+ useDescribe: boolean;
96
+ namingOptions: NamingOptions;
97
+ stripSchemaPrefix?: string;
98
+ /**
99
+ * Default nullable behavior when not explicitly specified
100
+ * @default false
101
+ */
102
+ defaultNullable: boolean;
103
+ /**
104
+ * Behavior for empty object schemas (objects with no properties defined)
105
+ * @default 'loose'
106
+ */
107
+ emptyObjectBehavior: "strict" | "loose" | "record";
108
+ /**
109
+ * Zod validation string for date-time format fields
110
+ * @default "z.iso.datetime()"
111
+ */
112
+ dateTimeValidation: string;
113
+ /**
114
+ * Instance-level cache for escaped regex patterns (parallel-safe)
115
+ */
116
+ patternCache: LRUCache<string, string>;
117
+ }
118
+ /**
119
+ * Property schema generator with memoization for performance
120
+ */
121
+ declare class PropertyGenerator {
122
+ private context;
123
+ private filteredPropsCache;
124
+ private schemaCache;
125
+ static readonly INCLUSION_RULES: {
126
+ readonly request: (schema: OpenAPISchema) => boolean;
127
+ readonly response: (schema: OpenAPISchema) => boolean;
128
+ readonly all: () => boolean;
129
+ };
130
+ constructor(context: PropertyGeneratorContext);
131
+ /**
132
+ * Check if a property should be included based on schemaType and readOnly/writeOnly flags
133
+ */
134
+ shouldIncludeProperty(schema: OpenAPISchema): boolean;
135
+ /**
136
+ * Recursively filter any schema type (helper for composition schemas)
137
+ */
138
+ private filterSchemaRecursive;
139
+ /**
140
+ * Recursively filter properties in nested objects based on readOnly/writeOnly
141
+ * Performance optimized with memoization
142
+ */
143
+ private filterNestedProperties;
144
+ /**
145
+ * Resolve discriminator mapping to actual schema references
146
+ */
147
+ private resolveDiscriminatorMapping;
148
+ /**
149
+ * Resolve a $ref string to the actual schema
150
+ */
151
+ private resolveSchemaRef;
152
+ /**
153
+ * Resolve a schema name through any aliases to get the actual schema name
154
+ * If the schema is an alias (allOf with single $ref), return the target name
155
+ */
156
+ private resolveSchemaAlias;
157
+ /**
158
+ * Check if this is a circular dependency through aliases
159
+ */
160
+ private isCircularThroughAlias;
161
+ /**
162
+ * Generate union for multiple types (OpenAPI 3.1)
163
+ */
164
+ private generateMultiTypeUnion;
165
+ /**
166
+ * Apply unevaluatedProperties validation to a schema
167
+ */
168
+ private applyUnevaluatedProperties;
169
+ /**
170
+ * Generate Zod schema for a property
171
+ * @param schema - The OpenAPI schema to generate
172
+ * @param currentSchema - The name of the current schema being processed (for circular ref detection)
173
+ * @param isTopLevel - Whether this is a top-level schema definition
174
+ * @param suppressDefaultNullable - When true, don't apply defaultNullable (used when outer schema has explicit nullable: false)
175
+ */
176
+ generatePropertySchema(schema: OpenAPISchema, currentSchema?: string, isTopLevel?: boolean, suppressDefaultNullable?: boolean): string;
177
+ /**
178
+ * Generate inline object shape for use with .extend()
179
+ * Returns just the shape object literal: { prop1: z.string(), prop2: z.number() }
180
+ *
181
+ * This method is specifically for allOf compositions where we need to pass
182
+ * the shape directly to .extend() instead of using z.object({...}).shape.
183
+ * This avoids the .nullable().shape bug when inline objects have nullable: true.
184
+ *
185
+ * According to Zod docs (https://zod.dev/api?id=extend):
186
+ * - .extend() accepts an object of shape definitions
187
+ * - e.g., baseSchema.extend({ prop: z.string() })
188
+ */
189
+ generateInlineObjectShape(schema: OpenAPISchema, currentSchema?: string): string;
190
+ }
191
+
49
192
  /**
50
193
  * @shared Zod schema for request/response options validation
51
194
  * @since 1.0.0
@@ -141,44 +284,6 @@ type FallbackContentTypeParsing = "json" | "text" | "body";
141
284
  */
142
285
  declare function getResponseParseMethod(contentType: string | undefined, fallback?: FallbackContentTypeParsing): ContentTypeParseResult;
143
286
 
144
- /**
145
- * @shared Simple LRU Cache implementation for performance optimization
146
- * @since 1.0.0
147
- * Utility used by core and playwright packages
148
- * Prevents memory leaks from unbounded cache growth
149
- */
150
- declare class LRUCache<K, V> {
151
- private cache;
152
- private maxSize;
153
- constructor(maxSize: number);
154
- get capacity(): number;
155
- get(key: K): V | undefined;
156
- set(key: K, value: V): void;
157
- has(key: K): boolean;
158
- clear(): void;
159
- size(): number;
160
- }
161
-
162
- /**
163
- * Name conversion utilities
164
- */
165
- interface NamingOptions {
166
- prefix?: string;
167
- suffix?: string;
168
- }
169
- /**
170
- * Convert schema name to camelCase with optional prefix/suffix
171
- * Handles dotted names like "Company.Models.User" -> "companyModelsUser"
172
- */
173
- declare function toCamelCase(str: string, options?: NamingOptions): string;
174
- /**
175
- * @shared Convert enum value to PascalCase and sanitize for TypeScript enum keys
176
- * @since 1.0.0
177
- * Utility used by core and playwright packages
178
- * Handles dotted names like "Company.Models.User" -> "CompanyModelsUser"
179
- */
180
- declare function toPascalCase(str: string | number): string;
181
-
182
287
  /**
183
288
  * Filter statistics to track which operations were included/excluded
184
289
  */
@@ -341,23 +446,25 @@ declare function escapeJSDoc(str: string): string;
341
446
  declare function createTypeScriptLoader(): Loader;
342
447
 
343
448
  /**
344
- * Configure custom date-time format validation
345
- * Overrides the default z.iso.datetime() with a custom regex pattern
449
+ * Build the Zod validation string for date-time format
450
+ * Pure function that returns the validation string without side effects
346
451
  *
347
- * @param pattern - Regex pattern (string or RegExp) for date-time validation
452
+ * @param pattern - Optional regex pattern (string or RegExp) for date-time validation
453
+ * @returns Zod validation string (either "z.iso.datetime()" or custom regex)
348
454
  * @throws {Error} If the provided pattern is not a valid regular expression
455
+ *
349
456
  * @example
350
- * // String pattern (required for JSON/YAML configs)
351
- * configureDateTimeFormat('^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}$')
457
+ * // Default (no pattern)
458
+ * buildDateTimeValidation() // Returns "z.iso.datetime()"
352
459
  *
353
460
  * @example
354
- * // RegExp literal (TypeScript configs only)
355
- * configureDateTimeFormat(/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}$/)
356
- */
357
- declare function configureDateTimeFormat(pattern?: string | RegExp): void;
358
- /**
359
- * Reset format map to defaults (useful for testing)
461
+ * // String pattern (for JSON/YAML configs)
462
+ * buildDateTimeValidation('^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}$')
463
+ *
464
+ * @example
465
+ * // RegExp literal (TypeScript configs)
466
+ * buildDateTimeValidation(/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}$/)
360
467
  */
361
- declare function resetFormatMap(): void;
468
+ declare function buildDateTimeValidation(pattern?: string | RegExp): string;
362
469
 
363
- export { type BaseOperationFilters, type ContentTypeParseResult, type FallbackContentTypeParsing, type FilterStatistics, type Generator, LRUCache, OperationFiltersSchema, type RequestResponseOptions, RequestResponseOptionsSchema, configureDateTimeFormat, createFilterStatistics, createTypeScriptLoader, escapeJSDoc, executeBatch, formatConfigValidationError, formatFilterStatistics, getBatchExitCode, getResponseParseMethod, mergeParameters, resetFormatMap, resolveParameterRef, resolveRef, resolveRequestBodyRef, resolveResponseRef, shouldIncludeOperation, stripPathPrefix, stripPrefix, toCamelCase, toPascalCase, validateFilters };
470
+ export { type BaseOperationFilters, type ContentTypeParseResult, type FallbackContentTypeParsing, type FilterStatistics, type Generator, LRUCache, OperationFiltersSchema, PropertyGenerator, type PropertyGeneratorContext, type RequestResponseOptions, RequestResponseOptionsSchema, buildDateTimeValidation, createFilterStatistics, createTypeScriptLoader, escapeJSDoc, executeBatch, formatConfigValidationError, formatFilterStatistics, getBatchExitCode, getResponseParseMethod, mergeParameters, resolveParameterRef, resolveRef, resolveRequestBodyRef, resolveResponseRef, shouldIncludeOperation, stripPathPrefix, stripPrefix, toCamelCase, toPascalCase, validateFilters };