@cerios/openapi-to-zod 1.3.2 → 1.5.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/LICENSE +8 -0
- package/README.md +546 -395
- package/dist/cli.js +831 -1321
- package/dist/cli.js.map +1 -1
- package/dist/cli.mjs +864 -1371
- package/dist/cli.mjs.map +1 -1
- package/dist/index.d.mts +472 -59
- package/dist/index.d.ts +472 -59
- package/dist/index.js +669 -909
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +675 -884
- package/dist/index.mjs.map +1 -1
- package/package.json +89 -104
- package/dist/internal.d.mts +0 -363
- package/dist/internal.d.ts +0 -363
- package/dist/internal.js +0 -759
- package/dist/internal.js.map +0 -1
- package/dist/internal.mjs +0 -706
- package/dist/internal.mjs.map +0 -1
- package/dist/types-DZ4Bw-D5.d.mts +0 -505
- package/dist/types-DZ4Bw-D5.d.ts +0 -505
package/dist/internal.d.ts
DELETED
|
@@ -1,363 +0,0 @@
|
|
|
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';
|
|
2
|
-
import { z } from 'zod';
|
|
3
|
-
import { Loader } from 'cosmiconfig';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* @shared Generator interface for batch execution
|
|
7
|
-
* @since 1.0.0
|
|
8
|
-
* Interface that both OpenApiGenerator and OpenApiPlaywrightGenerator must implement
|
|
9
|
-
*/
|
|
10
|
-
interface Generator {
|
|
11
|
-
generate(): void;
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* Result of processing a single spec
|
|
15
|
-
*/
|
|
16
|
-
interface SpecResult<T> {
|
|
17
|
-
spec: T;
|
|
18
|
-
success: boolean;
|
|
19
|
-
error?: string;
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* Summary of batch execution results
|
|
23
|
-
*/
|
|
24
|
-
interface BatchExecutionSummary<T> {
|
|
25
|
-
total: number;
|
|
26
|
-
successful: number;
|
|
27
|
-
failed: number;
|
|
28
|
-
results: SpecResult<T>[];
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* @shared Execute batch processing of multiple specs with custom generator
|
|
32
|
-
* @since 1.0.0
|
|
33
|
-
* Utility used by core and playwright packages
|
|
34
|
-
*
|
|
35
|
-
* @param specs - Array of spec configurations to process
|
|
36
|
-
* @param executionMode - Execution mode: "parallel" (default) or "sequential"
|
|
37
|
-
* @param createGenerator - Factory function to create generator from spec
|
|
38
|
-
* @param batchSize - Number of specifications to process concurrently in parallel mode
|
|
39
|
-
* @returns BatchExecutionSummary with results
|
|
40
|
-
* @throws Never throws - collects all errors and reports them
|
|
41
|
-
*/
|
|
42
|
-
declare function executeBatch<T>(specs: T[], executionMode: ExecutionMode | undefined, createGenerator: (spec: T) => Generator, batchSize: number): Promise<BatchExecutionSummary<T>>;
|
|
43
|
-
/**
|
|
44
|
-
* Determine exit code based on batch execution results
|
|
45
|
-
* Returns 1 if any spec failed, 0 if all succeeded
|
|
46
|
-
*/
|
|
47
|
-
declare function getBatchExitCode<T>(summary: BatchExecutionSummary<T>): number;
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* @shared Zod schema for request/response options validation
|
|
51
|
-
* @since 1.0.0
|
|
52
|
-
* Utility used by core and playwright packages
|
|
53
|
-
*/
|
|
54
|
-
declare const RequestResponseOptionsSchema: z.ZodObject<{
|
|
55
|
-
mode: z.ZodOptional<z.ZodEnum<{
|
|
56
|
-
strict: "strict";
|
|
57
|
-
normal: "normal";
|
|
58
|
-
loose: "loose";
|
|
59
|
-
}>>;
|
|
60
|
-
useDescribe: z.ZodOptional<z.ZodBoolean>;
|
|
61
|
-
includeDescriptions: z.ZodOptional<z.ZodBoolean>;
|
|
62
|
-
defaultNullable: z.ZodOptional<z.ZodBoolean>;
|
|
63
|
-
emptyObjectBehavior: z.ZodOptional<z.ZodEnum<{
|
|
64
|
-
strict: "strict";
|
|
65
|
-
loose: "loose";
|
|
66
|
-
record: "record";
|
|
67
|
-
}>>;
|
|
68
|
-
}, z.core.$strict>;
|
|
69
|
-
/**
|
|
70
|
-
* @shared Base Zod schema for operation filters (without status codes)
|
|
71
|
-
* @since 1.0.0
|
|
72
|
-
* Utility used by core and playwright packages
|
|
73
|
-
*/
|
|
74
|
-
declare const OperationFiltersSchema: z.ZodObject<{
|
|
75
|
-
includeTags: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
76
|
-
excludeTags: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
77
|
-
includePaths: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
78
|
-
excludePaths: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
79
|
-
includeMethods: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
80
|
-
excludeMethods: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
81
|
-
includeOperationIds: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
82
|
-
excludeOperationIds: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
83
|
-
excludeDeprecated: z.ZodOptional<z.ZodBoolean>;
|
|
84
|
-
}, z.core.$strict>;
|
|
85
|
-
/**
|
|
86
|
-
* Inferred TypeScript type for request/response options
|
|
87
|
-
*/
|
|
88
|
-
type RequestResponseOptions = z.infer<typeof RequestResponseOptionsSchema>;
|
|
89
|
-
/**
|
|
90
|
-
* Inferred TypeScript type for base operation filters
|
|
91
|
-
*/
|
|
92
|
-
type BaseOperationFilters = z.infer<typeof OperationFiltersSchema>;
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
* @shared Format Zod validation errors into user-friendly error messages
|
|
96
|
-
* @since 1.0.0
|
|
97
|
-
* Utility used by core and playwright packages
|
|
98
|
-
*
|
|
99
|
-
* @param error - The Zod validation error
|
|
100
|
-
* @param filepath - Path to the config file that was being validated
|
|
101
|
-
* @param configPath - Optional explicit config path provided by user
|
|
102
|
-
* @param additionalNotes - Optional array of additional notes to append to the error message
|
|
103
|
-
* @returns Formatted error message string
|
|
104
|
-
*/
|
|
105
|
-
declare function formatConfigValidationError(error: z.ZodError, filepath: string | undefined, configPath: string | undefined, additionalNotes?: string[]): string;
|
|
106
|
-
|
|
107
|
-
/**
|
|
108
|
-
* Content type utilities for determining response parsing methods
|
|
109
|
-
*/
|
|
110
|
-
/**
|
|
111
|
-
* Result of content type analysis
|
|
112
|
-
*/
|
|
113
|
-
interface ContentTypeParseResult {
|
|
114
|
-
/**
|
|
115
|
-
* The recommended parsing method
|
|
116
|
-
* - "json": Use response.json() for JSON content types
|
|
117
|
-
* - "text": Use response.text() for text-based content types
|
|
118
|
-
* - "body": Use response.body() for binary content types
|
|
119
|
-
*/
|
|
120
|
-
method: "json" | "text" | "body";
|
|
121
|
-
/**
|
|
122
|
-
* Whether the content type was unknown and fallback was used
|
|
123
|
-
*/
|
|
124
|
-
isUnknown: boolean;
|
|
125
|
-
}
|
|
126
|
-
/**
|
|
127
|
-
* Fallback parsing method for unknown content types
|
|
128
|
-
*/
|
|
129
|
-
type FallbackContentTypeParsing = "json" | "text" | "body";
|
|
130
|
-
/**
|
|
131
|
-
* Determines the appropriate response parsing method based on content type
|
|
132
|
-
*
|
|
133
|
-
* Categories:
|
|
134
|
-
* - JSON: application/json, text/json, *+json suffix
|
|
135
|
-
* - Text: text/* (except text/json), application/xml, *+xml suffix, application/javascript
|
|
136
|
-
* - Binary: image/*, audio/*, video/*, font/*, application/octet-stream, application/pdf, etc.
|
|
137
|
-
*
|
|
138
|
-
* @param contentType - The content type to analyze (e.g., "application/json; charset=utf-8")
|
|
139
|
-
* @param fallback - The method to use for unknown content types (default: "text" for safety)
|
|
140
|
-
* @returns The recommended parsing method and whether the content type was unknown
|
|
141
|
-
*/
|
|
142
|
-
declare function getResponseParseMethod(contentType: string | undefined, fallback?: FallbackContentTypeParsing): ContentTypeParseResult;
|
|
143
|
-
|
|
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
|
-
/**
|
|
183
|
-
* Filter statistics to track which operations were included/excluded
|
|
184
|
-
*/
|
|
185
|
-
interface FilterStatistics {
|
|
186
|
-
totalOperations: number;
|
|
187
|
-
includedOperations: number;
|
|
188
|
-
filteredByTags: number;
|
|
189
|
-
filteredByPaths: number;
|
|
190
|
-
filteredByMethods: number;
|
|
191
|
-
filteredByOperationIds: number;
|
|
192
|
-
filteredByDeprecated: number;
|
|
193
|
-
}
|
|
194
|
-
/**
|
|
195
|
-
* Create a new filter statistics object with all counters initialized to zero
|
|
196
|
-
*/
|
|
197
|
-
declare function createFilterStatistics(): FilterStatistics;
|
|
198
|
-
/**
|
|
199
|
-
* Determine if an operation should be included based on filter criteria
|
|
200
|
-
*
|
|
201
|
-
* Filter logic:
|
|
202
|
-
* 1. If no filters specified, include all operations
|
|
203
|
-
* 2. Empty arrays are treated as "no constraint" (not as "exclude all")
|
|
204
|
-
* 3. Include filters are applied first (allowlist)
|
|
205
|
-
* 4. Exclude filters are applied second (blocklist)
|
|
206
|
-
* 5. Exclude rules always win over include rules
|
|
207
|
-
*
|
|
208
|
-
* @param operation - The OpenAPI operation object
|
|
209
|
-
* @param path - The operation path (e.g., "/users/{id}")
|
|
210
|
-
* @param method - The HTTP method (e.g., "get", "post")
|
|
211
|
-
* @param filters - Optional filter configuration
|
|
212
|
-
* @param stats - Optional statistics object to track filtering reasons
|
|
213
|
-
* @returns true if the operation should be included, false otherwise
|
|
214
|
-
*/
|
|
215
|
-
declare function shouldIncludeOperation(operation: any, path: string, method: string, filters?: OperationFilters, stats?: FilterStatistics): boolean;
|
|
216
|
-
/**
|
|
217
|
-
* Validate filter statistics and emit warnings for filters that matched nothing
|
|
218
|
-
* Helps users debug filter configurations that might be too restrictive or contain typos
|
|
219
|
-
*
|
|
220
|
-
* @param stats - Filter statistics object
|
|
221
|
-
* @param filters - The filter configuration to validate
|
|
222
|
-
*/
|
|
223
|
-
declare function validateFilters(stats: FilterStatistics, filters?: OperationFilters): void;
|
|
224
|
-
/**
|
|
225
|
-
* Format filter statistics for display in generated output
|
|
226
|
-
* Returns a formatted string suitable for inclusion in comments
|
|
227
|
-
*
|
|
228
|
-
* @param stats - Filter statistics object
|
|
229
|
-
* @returns Formatted statistics string
|
|
230
|
-
*/
|
|
231
|
-
declare function formatFilterStatistics(stats: FilterStatistics): string;
|
|
232
|
-
|
|
233
|
-
/**
|
|
234
|
-
* @shared Strips a prefix from a string using either literal string matching or glob patterns
|
|
235
|
-
* @since 1.1.0
|
|
236
|
-
* Shared utility used by core and playwright packages
|
|
237
|
-
*
|
|
238
|
-
* @param input - The full string to strip from
|
|
239
|
-
* @param pattern - The glob pattern to strip
|
|
240
|
-
* @param ensureLeadingChar - Optional character to ensure at start (e.g., "/" for paths)
|
|
241
|
-
* @returns The string with prefix removed, or original string if no match
|
|
242
|
-
*
|
|
243
|
-
* @example
|
|
244
|
-
* // Literal string matching
|
|
245
|
-
* stripPrefix("/api/v1/users", "/api/v1") // => "/users"
|
|
246
|
-
* stripPrefix("Company.Models.User", "Company.Models.") // => "User"
|
|
247
|
-
*
|
|
248
|
-
* @example
|
|
249
|
-
* // Glob pattern matching
|
|
250
|
-
* stripPrefix("/api/v1.0/users", "/api/v*") // => matches and strips
|
|
251
|
-
* stripPrefix("Company.Models.User", "*.Models.") // => "User"
|
|
252
|
-
* stripPrefix("api_v2_UserSchema", "api_v[0-9]_") // => "UserSchema"
|
|
253
|
-
*/
|
|
254
|
-
declare function stripPrefix(input: string, pattern: string | undefined, ensureLeadingChar?: string): string;
|
|
255
|
-
/**
|
|
256
|
-
* @shared Strips a prefix from a path (ensures leading slash)
|
|
257
|
-
* @since 1.1.0
|
|
258
|
-
* Shared utility used by playwright package for path manipulation
|
|
259
|
-
*
|
|
260
|
-
* @param path - The full path to strip from
|
|
261
|
-
* @param pattern - The glob pattern to strip
|
|
262
|
-
* @returns The path with prefix removed, or original path if no match
|
|
263
|
-
*
|
|
264
|
-
* @example
|
|
265
|
-
* stripPathPrefix("/api/v1/users", "/api/v1") // => "/users"
|
|
266
|
-
* stripPathPrefix("/api/v2/posts", "/api/v*") // => "/posts"
|
|
267
|
-
* stripPathPrefix("/api/v1.0/items", "/api/v[0-9].*") // => "/items"
|
|
268
|
-
*/
|
|
269
|
-
declare function stripPathPrefix(path: string, pattern: string | undefined): string;
|
|
270
|
-
|
|
271
|
-
/**
|
|
272
|
-
* OpenAPI $ref resolution utilities
|
|
273
|
-
*
|
|
274
|
-
* Provides functions to resolve $ref references to component definitions
|
|
275
|
-
* Supports: parameters, requestBodies, responses, schemas
|
|
276
|
-
*
|
|
277
|
-
* @internal Used by core and playwright packages
|
|
278
|
-
*/
|
|
279
|
-
|
|
280
|
-
/**
|
|
281
|
-
* Type for any resolvable component
|
|
282
|
-
*/
|
|
283
|
-
type ResolvableComponent = OpenAPIParameter | OpenAPIRequestBody | OpenAPIResponse | OpenAPISchema | any;
|
|
284
|
-
/**
|
|
285
|
-
* Resolve a $ref to a component definition
|
|
286
|
-
* Handles nested $refs by recursively resolving until no more refs found
|
|
287
|
-
*
|
|
288
|
-
* @param obj - Object that may contain a $ref
|
|
289
|
-
* @param spec - The OpenAPI specification
|
|
290
|
-
* @param maxDepth - Maximum recursion depth to prevent infinite loops (default: 10)
|
|
291
|
-
* @returns The resolved component, or the original object if not a reference
|
|
292
|
-
*/
|
|
293
|
-
declare function resolveRef<T extends ResolvableComponent>(obj: T | any, spec: OpenAPISpec, maxDepth?: number): T;
|
|
294
|
-
/**
|
|
295
|
-
* Resolve a parameter reference
|
|
296
|
-
* Convenience wrapper for resolveRef with parameter type
|
|
297
|
-
*/
|
|
298
|
-
declare function resolveParameterRef(param: any, spec: OpenAPISpec): OpenAPIParameter | any;
|
|
299
|
-
/**
|
|
300
|
-
* Resolve a request body reference
|
|
301
|
-
* Convenience wrapper for resolveRef with request body type
|
|
302
|
-
*/
|
|
303
|
-
declare function resolveRequestBodyRef(requestBody: any, spec: OpenAPISpec): OpenAPIRequestBody | any;
|
|
304
|
-
/**
|
|
305
|
-
* Resolve a response reference
|
|
306
|
-
* Convenience wrapper for resolveRef with response type
|
|
307
|
-
*/
|
|
308
|
-
declare function resolveResponseRef(response: any, spec: OpenAPISpec): OpenAPIResponse | any;
|
|
309
|
-
/**
|
|
310
|
-
* Merge path-level parameters with operation-level parameters
|
|
311
|
-
* Operation parameters override path-level parameters with the same name and location
|
|
312
|
-
*
|
|
313
|
-
* @param pathParams - Parameters defined at the path level
|
|
314
|
-
* @param operationParams - Parameters defined at the operation level
|
|
315
|
-
* @param spec - The OpenAPI specification for resolving $refs
|
|
316
|
-
* @returns Merged array of resolved parameters
|
|
317
|
-
*/
|
|
318
|
-
declare function mergeParameters(pathParams: any[] | undefined, operationParams: any[] | undefined, spec: OpenAPISpec): any[];
|
|
319
|
-
|
|
320
|
-
/**
|
|
321
|
-
* String utility functions for escaping and formatting
|
|
322
|
-
*/
|
|
323
|
-
|
|
324
|
-
/**
|
|
325
|
-
* @shared Escape JSDoc comment content to prevent injection
|
|
326
|
-
* @since 1.0.0
|
|
327
|
-
* Utility used by core and playwright packages
|
|
328
|
-
*/
|
|
329
|
-
declare function escapeJSDoc(str: string): string;
|
|
330
|
-
|
|
331
|
-
/**
|
|
332
|
-
* @shared Create a TypeScript loader for cosmiconfig using esbuild
|
|
333
|
-
* @since 1.0.0
|
|
334
|
-
* Utility used by core and playwright packages
|
|
335
|
-
*
|
|
336
|
-
* Creates a loader that transpiles TypeScript config files to JavaScript
|
|
337
|
-
* using esbuild, then executes them to load the configuration.
|
|
338
|
-
*
|
|
339
|
-
* @returns A cosmiconfig Loader function
|
|
340
|
-
*/
|
|
341
|
-
declare function createTypeScriptLoader(): Loader;
|
|
342
|
-
|
|
343
|
-
/**
|
|
344
|
-
* Configure custom date-time format validation
|
|
345
|
-
* Overrides the default z.iso.datetime() with a custom regex pattern
|
|
346
|
-
*
|
|
347
|
-
* @param pattern - Regex pattern (string or RegExp) for date-time validation
|
|
348
|
-
* @throws {Error} If the provided pattern is not a valid regular expression
|
|
349
|
-
* @example
|
|
350
|
-
* // String pattern (required for JSON/YAML configs)
|
|
351
|
-
* configureDateTimeFormat('^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}$')
|
|
352
|
-
*
|
|
353
|
-
* @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)
|
|
360
|
-
*/
|
|
361
|
-
declare function resetFormatMap(): void;
|
|
362
|
-
|
|
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 };
|