@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.mjs
DELETED
|
@@ -1,706 +0,0 @@
|
|
|
1
|
-
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
2
|
-
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
3
|
-
}) : x)(function(x) {
|
|
4
|
-
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
5
|
-
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
6
|
-
});
|
|
7
|
-
|
|
8
|
-
// src/errors.ts
|
|
9
|
-
var GeneratorError = class extends Error {
|
|
10
|
-
constructor(message, code, context) {
|
|
11
|
-
var _a;
|
|
12
|
-
super(message);
|
|
13
|
-
this.code = code;
|
|
14
|
-
this.context = context;
|
|
15
|
-
this.name = "GeneratorError";
|
|
16
|
-
(_a = Error.captureStackTrace) == null ? void 0 : _a.call(Error, this, this.constructor);
|
|
17
|
-
}
|
|
18
|
-
};
|
|
19
|
-
var ConfigurationError = class extends GeneratorError {
|
|
20
|
-
constructor(message, context) {
|
|
21
|
-
super(message, "CONFIGURATION_ERROR", context);
|
|
22
|
-
this.name = "ConfigurationError";
|
|
23
|
-
}
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
// src/batch-executor.ts
|
|
27
|
-
async function processSpec(spec, index, total, createGenerator) {
|
|
28
|
-
const specInput = spec.input || "spec";
|
|
29
|
-
const specOutput = spec.output || "output";
|
|
30
|
-
console.log(`Processing [${index + 1}/${total}] ${specInput}...`);
|
|
31
|
-
try {
|
|
32
|
-
const generator = createGenerator(spec);
|
|
33
|
-
generator.generate();
|
|
34
|
-
return {
|
|
35
|
-
spec,
|
|
36
|
-
success: true
|
|
37
|
-
};
|
|
38
|
-
} catch (error) {
|
|
39
|
-
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
40
|
-
console.error(`\u2717 Failed to generate ${specOutput}: ${errorMessage}`);
|
|
41
|
-
return {
|
|
42
|
-
spec,
|
|
43
|
-
success: false,
|
|
44
|
-
error: errorMessage
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
async function executeParallel(specs, createGenerator, batchSize) {
|
|
49
|
-
console.log(`
|
|
50
|
-
Executing ${specs.length} specification(s) in parallel (batch size: ${batchSize})...
|
|
51
|
-
`);
|
|
52
|
-
const results = [];
|
|
53
|
-
for (let i = 0; i < specs.length; i += batchSize) {
|
|
54
|
-
const batch = specs.slice(i, Math.min(i + batchSize, specs.length));
|
|
55
|
-
const batchPromises = batch.map(
|
|
56
|
-
(spec, batchIndex) => processSpec(spec, i + batchIndex, specs.length, createGenerator)
|
|
57
|
-
);
|
|
58
|
-
const batchResults = await Promise.allSettled(batchPromises);
|
|
59
|
-
for (let j = 0; j < batchResults.length; j++) {
|
|
60
|
-
const result = batchResults[j];
|
|
61
|
-
if (result.status === "fulfilled") {
|
|
62
|
-
results.push(result.value);
|
|
63
|
-
} else {
|
|
64
|
-
results.push({
|
|
65
|
-
spec: batch[j],
|
|
66
|
-
success: false,
|
|
67
|
-
error: result.reason instanceof Error ? result.reason.message : String(result.reason)
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
return results;
|
|
73
|
-
}
|
|
74
|
-
async function executeSequential(specs, createGenerator) {
|
|
75
|
-
console.log(`
|
|
76
|
-
Executing ${specs.length} spec(s) sequentially...
|
|
77
|
-
`);
|
|
78
|
-
const results = [];
|
|
79
|
-
for (let i = 0; i < specs.length; i++) {
|
|
80
|
-
const result = await processSpec(specs[i], i, specs.length, createGenerator);
|
|
81
|
-
results.push(result);
|
|
82
|
-
}
|
|
83
|
-
return results;
|
|
84
|
-
}
|
|
85
|
-
function printSummary(summary) {
|
|
86
|
-
console.log(`
|
|
87
|
-
${"=".repeat(50)}`);
|
|
88
|
-
console.log("Batch Execution Summary");
|
|
89
|
-
console.log("=".repeat(50));
|
|
90
|
-
console.log(`Total specs: ${summary.total}`);
|
|
91
|
-
console.log(`Successful: ${summary.successful}`);
|
|
92
|
-
console.log(`Failed: ${summary.failed}`);
|
|
93
|
-
if (summary.failed > 0) {
|
|
94
|
-
console.log("\nFailed specs:");
|
|
95
|
-
for (const result of summary.results) {
|
|
96
|
-
if (!result.success) {
|
|
97
|
-
const specInput = result.spec.input || "spec";
|
|
98
|
-
console.error(` \u2717 ${specInput}`);
|
|
99
|
-
console.error(` Error: ${result.error}`);
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
console.log(`${"=".repeat(50)}
|
|
104
|
-
`);
|
|
105
|
-
}
|
|
106
|
-
async function executeBatch(specs, executionMode = "parallel", createGenerator, batchSize) {
|
|
107
|
-
if (specs.length === 0) {
|
|
108
|
-
throw new ConfigurationError("No specs provided for batch execution", { specsCount: 0, executionMode });
|
|
109
|
-
}
|
|
110
|
-
let results = [];
|
|
111
|
-
try {
|
|
112
|
-
results = executionMode === "parallel" ? await executeParallel(specs, createGenerator, batchSize) : await executeSequential(specs, createGenerator);
|
|
113
|
-
const summary = {
|
|
114
|
-
total: results.length,
|
|
115
|
-
successful: results.filter((r) => r.success).length,
|
|
116
|
-
failed: results.filter((r) => !r.success).length,
|
|
117
|
-
results
|
|
118
|
-
};
|
|
119
|
-
printSummary(summary);
|
|
120
|
-
return summary;
|
|
121
|
-
} finally {
|
|
122
|
-
if (results.length > batchSize) {
|
|
123
|
-
for (const result of results) {
|
|
124
|
-
if (result.spec) {
|
|
125
|
-
result.spec = null;
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
if (global.gc) {
|
|
129
|
-
global.gc();
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
function getBatchExitCode(summary) {
|
|
135
|
-
return summary.failed > 0 ? 1 : 0;
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
// src/utils/config-schemas.ts
|
|
139
|
-
import { z } from "zod";
|
|
140
|
-
var RequestResponseOptionsSchema = z.strictObject({
|
|
141
|
-
mode: z.enum(["strict", "normal", "loose"]).optional(),
|
|
142
|
-
useDescribe: z.boolean().optional(),
|
|
143
|
-
includeDescriptions: z.boolean().optional(),
|
|
144
|
-
defaultNullable: z.boolean().optional(),
|
|
145
|
-
emptyObjectBehavior: z.enum(["strict", "loose", "record"]).optional()
|
|
146
|
-
});
|
|
147
|
-
var OperationFiltersSchema = z.strictObject({
|
|
148
|
-
includeTags: z.array(z.string()).optional(),
|
|
149
|
-
excludeTags: z.array(z.string()).optional(),
|
|
150
|
-
includePaths: z.array(z.string()).optional(),
|
|
151
|
-
excludePaths: z.array(z.string()).optional(),
|
|
152
|
-
includeMethods: z.array(z.string()).optional(),
|
|
153
|
-
excludeMethods: z.array(z.string()).optional(),
|
|
154
|
-
includeOperationIds: z.array(z.string()).optional(),
|
|
155
|
-
excludeOperationIds: z.array(z.string()).optional(),
|
|
156
|
-
excludeDeprecated: z.boolean().optional()
|
|
157
|
-
});
|
|
158
|
-
|
|
159
|
-
// src/utils/config-validation.ts
|
|
160
|
-
function formatConfigValidationError(error, filepath, configPath, additionalNotes) {
|
|
161
|
-
var _a;
|
|
162
|
-
const formattedErrors = ((_a = error.issues) == null ? void 0 : _a.map((err) => {
|
|
163
|
-
const path = err.path.length > 0 ? err.path.join(".") : "root";
|
|
164
|
-
return ` - ${path}: ${err.message}`;
|
|
165
|
-
}).join("\n")) || "Unknown validation error";
|
|
166
|
-
const configSource = filepath || configPath || "config file";
|
|
167
|
-
const lines = [
|
|
168
|
-
`Invalid configuration file at: ${configSource}`,
|
|
169
|
-
"",
|
|
170
|
-
"Validation errors:",
|
|
171
|
-
formattedErrors,
|
|
172
|
-
"",
|
|
173
|
-
"Please check your configuration file and ensure:",
|
|
174
|
-
" - All required fields are present (specs array with input/output)",
|
|
175
|
-
" - Field names are spelled correctly (no typos)",
|
|
176
|
-
" - Values match the expected types (e.g., mode: 'strict' | 'normal' | 'loose')",
|
|
177
|
-
" - No unknown/extra properties are included"
|
|
178
|
-
];
|
|
179
|
-
if (additionalNotes && additionalNotes.length > 0) {
|
|
180
|
-
lines.push(...additionalNotes.map((note) => ` - ${note}`));
|
|
181
|
-
}
|
|
182
|
-
return lines.join("\n");
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
// src/utils/content-type-utils.ts
|
|
186
|
-
function getResponseParseMethod(contentType, fallback = "text") {
|
|
187
|
-
if (!contentType) {
|
|
188
|
-
return { method: fallback, isUnknown: true };
|
|
189
|
-
}
|
|
190
|
-
const normalized = contentType.toLowerCase().split(";")[0].trim();
|
|
191
|
-
if (!normalized) {
|
|
192
|
-
return { method: fallback, isUnknown: true };
|
|
193
|
-
}
|
|
194
|
-
if (normalized === "application/json" || normalized === "text/json" || normalized.endsWith("+json")) {
|
|
195
|
-
return { method: "json", isUnknown: false };
|
|
196
|
-
}
|
|
197
|
-
if (normalized.startsWith("text/")) {
|
|
198
|
-
return { method: "text", isUnknown: false };
|
|
199
|
-
}
|
|
200
|
-
if (normalized === "application/xml" || normalized.endsWith("+xml")) {
|
|
201
|
-
return { method: "text", isUnknown: false };
|
|
202
|
-
}
|
|
203
|
-
if (normalized === "application/javascript" || normalized === "application/x-javascript" || normalized === "application/ecmascript") {
|
|
204
|
-
return { method: "text", isUnknown: false };
|
|
205
|
-
}
|
|
206
|
-
if (normalized.startsWith("image/")) {
|
|
207
|
-
return { method: "body", isUnknown: false };
|
|
208
|
-
}
|
|
209
|
-
if (normalized.startsWith("audio/")) {
|
|
210
|
-
return { method: "body", isUnknown: false };
|
|
211
|
-
}
|
|
212
|
-
if (normalized.startsWith("video/")) {
|
|
213
|
-
return { method: "body", isUnknown: false };
|
|
214
|
-
}
|
|
215
|
-
if (normalized.startsWith("font/")) {
|
|
216
|
-
return { method: "body", isUnknown: false };
|
|
217
|
-
}
|
|
218
|
-
if (normalized === "application/octet-stream" || normalized === "application/pdf" || normalized === "application/zip" || normalized === "application/gzip" || normalized === "application/x-tar" || normalized === "application/x-7z-compressed" || normalized === "application/x-rar-compressed" || normalized === "application/wasm" || normalized === "application/x-protobuf") {
|
|
219
|
-
return { method: "body", isUnknown: false };
|
|
220
|
-
}
|
|
221
|
-
return { method: fallback, isUnknown: true };
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
// src/utils/lru-cache.ts
|
|
225
|
-
var LRUCache = class {
|
|
226
|
-
constructor(maxSize) {
|
|
227
|
-
this.cache = /* @__PURE__ */ new Map();
|
|
228
|
-
this.maxSize = maxSize;
|
|
229
|
-
}
|
|
230
|
-
get capacity() {
|
|
231
|
-
return this.maxSize;
|
|
232
|
-
}
|
|
233
|
-
get(key) {
|
|
234
|
-
if (!this.cache.has(key)) return void 0;
|
|
235
|
-
const value = this.cache.get(key);
|
|
236
|
-
if (value === void 0) return void 0;
|
|
237
|
-
this.cache.delete(key);
|
|
238
|
-
this.cache.set(key, value);
|
|
239
|
-
return value;
|
|
240
|
-
}
|
|
241
|
-
set(key, value) {
|
|
242
|
-
if (this.cache.has(key)) {
|
|
243
|
-
this.cache.delete(key);
|
|
244
|
-
} else if (this.cache.size >= this.maxSize) {
|
|
245
|
-
const firstKey = this.cache.keys().next().value;
|
|
246
|
-
if (firstKey !== void 0) {
|
|
247
|
-
this.cache.delete(firstKey);
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
this.cache.set(key, value);
|
|
251
|
-
}
|
|
252
|
-
has(key) {
|
|
253
|
-
return this.cache.has(key);
|
|
254
|
-
}
|
|
255
|
-
clear() {
|
|
256
|
-
this.cache.clear();
|
|
257
|
-
}
|
|
258
|
-
size() {
|
|
259
|
-
return this.cache.size;
|
|
260
|
-
}
|
|
261
|
-
};
|
|
262
|
-
|
|
263
|
-
// src/utils/name-utils.ts
|
|
264
|
-
function sanitizeIdentifier(str) {
|
|
265
|
-
return str.replace(/[^a-zA-Z0-9._\-\s]+/g, "_");
|
|
266
|
-
}
|
|
267
|
-
function toCamelCase(str, options) {
|
|
268
|
-
const sanitized = sanitizeIdentifier(str);
|
|
269
|
-
const words = sanitized.split(/[.\-_\s]+/).filter((word) => word.length > 0);
|
|
270
|
-
let name;
|
|
271
|
-
if (words.length === 0) {
|
|
272
|
-
name = str.charAt(0).toLowerCase() + str.slice(1);
|
|
273
|
-
} else if (words.length === 1) {
|
|
274
|
-
name = words[0].charAt(0).toLowerCase() + words[0].slice(1);
|
|
275
|
-
} else {
|
|
276
|
-
name = words[0].charAt(0).toLowerCase() + words[0].slice(1) + words.slice(1).map((word) => word.charAt(0).toUpperCase() + word.slice(1)).join("");
|
|
277
|
-
}
|
|
278
|
-
if (options == null ? void 0 : options.prefix) {
|
|
279
|
-
const prefix = options.prefix.charAt(0).toLowerCase() + options.prefix.slice(1);
|
|
280
|
-
name = prefix + name.charAt(0).toUpperCase() + name.slice(1);
|
|
281
|
-
}
|
|
282
|
-
if (options == null ? void 0 : options.suffix) {
|
|
283
|
-
const suffix = options.suffix.charAt(0).toUpperCase() + options.suffix.slice(1);
|
|
284
|
-
name = name + suffix;
|
|
285
|
-
}
|
|
286
|
-
return name;
|
|
287
|
-
}
|
|
288
|
-
function toPascalCase(str) {
|
|
289
|
-
const stringValue = String(str);
|
|
290
|
-
const isAlreadyValidCase = /^[a-zA-Z][a-zA-Z0-9]*$/.test(stringValue);
|
|
291
|
-
if (isAlreadyValidCase) {
|
|
292
|
-
return stringValue.charAt(0).toUpperCase() + stringValue.slice(1);
|
|
293
|
-
}
|
|
294
|
-
const sanitized = sanitizeIdentifier(stringValue);
|
|
295
|
-
const words = sanitized.split(/[.\-_\s]+/).filter((word) => word.length > 0);
|
|
296
|
-
let result;
|
|
297
|
-
if (words.length === 0) {
|
|
298
|
-
result = "Value";
|
|
299
|
-
} else {
|
|
300
|
-
result = words.map((word) => word.charAt(0).toUpperCase() + word.slice(1)).join("");
|
|
301
|
-
}
|
|
302
|
-
if (/^\d/.test(result)) {
|
|
303
|
-
result = `N${result}`;
|
|
304
|
-
}
|
|
305
|
-
if (!result || /^_+$/.test(result)) {
|
|
306
|
-
return "Value";
|
|
307
|
-
}
|
|
308
|
-
return result;
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
// src/utils/operation-filters.ts
|
|
312
|
-
import { minimatch } from "minimatch";
|
|
313
|
-
function createFilterStatistics() {
|
|
314
|
-
return {
|
|
315
|
-
totalOperations: 0,
|
|
316
|
-
includedOperations: 0,
|
|
317
|
-
filteredByTags: 0,
|
|
318
|
-
filteredByPaths: 0,
|
|
319
|
-
filteredByMethods: 0,
|
|
320
|
-
filteredByOperationIds: 0,
|
|
321
|
-
filteredByDeprecated: 0
|
|
322
|
-
};
|
|
323
|
-
}
|
|
324
|
-
function matchesAnyPattern(value, patterns) {
|
|
325
|
-
if (!patterns || patterns.length === 0) {
|
|
326
|
-
return false;
|
|
327
|
-
}
|
|
328
|
-
if (!value) {
|
|
329
|
-
return false;
|
|
330
|
-
}
|
|
331
|
-
return patterns.some((pattern) => minimatch(value, pattern));
|
|
332
|
-
}
|
|
333
|
-
function containsAny(arr, values) {
|
|
334
|
-
if (!values || values.length === 0) {
|
|
335
|
-
return false;
|
|
336
|
-
}
|
|
337
|
-
if (!arr || arr.length === 0) {
|
|
338
|
-
return false;
|
|
339
|
-
}
|
|
340
|
-
return values.some((value) => arr.includes(value));
|
|
341
|
-
}
|
|
342
|
-
function shouldIncludeOperation(operation, path, method, filters, stats) {
|
|
343
|
-
if (!filters) {
|
|
344
|
-
return true;
|
|
345
|
-
}
|
|
346
|
-
const methodLower = method.toLowerCase();
|
|
347
|
-
const operationId = operation == null ? void 0 : operation.operationId;
|
|
348
|
-
const tags = (operation == null ? void 0 : operation.tags) || [];
|
|
349
|
-
const deprecated = (operation == null ? void 0 : operation.deprecated) === true;
|
|
350
|
-
if (filters.includeTags && filters.includeTags.length > 0) {
|
|
351
|
-
if (!containsAny(tags, filters.includeTags)) {
|
|
352
|
-
if (stats) stats.filteredByTags++;
|
|
353
|
-
return false;
|
|
354
|
-
}
|
|
355
|
-
}
|
|
356
|
-
if (filters.includePaths && filters.includePaths.length > 0) {
|
|
357
|
-
if (!matchesAnyPattern(path, filters.includePaths)) {
|
|
358
|
-
if (stats) stats.filteredByPaths++;
|
|
359
|
-
return false;
|
|
360
|
-
}
|
|
361
|
-
}
|
|
362
|
-
if (filters.includeMethods && filters.includeMethods.length > 0) {
|
|
363
|
-
const methodsLower = filters.includeMethods.map((m) => m.toLowerCase());
|
|
364
|
-
if (!methodsLower.includes(methodLower)) {
|
|
365
|
-
if (stats) stats.filteredByMethods++;
|
|
366
|
-
return false;
|
|
367
|
-
}
|
|
368
|
-
}
|
|
369
|
-
if (filters.includeOperationIds && filters.includeOperationIds.length > 0) {
|
|
370
|
-
if (!matchesAnyPattern(operationId, filters.includeOperationIds)) {
|
|
371
|
-
if (stats) stats.filteredByOperationIds++;
|
|
372
|
-
return false;
|
|
373
|
-
}
|
|
374
|
-
}
|
|
375
|
-
if (filters.excludeDeprecated === true && deprecated) {
|
|
376
|
-
if (stats) stats.filteredByDeprecated++;
|
|
377
|
-
return false;
|
|
378
|
-
}
|
|
379
|
-
if (filters.excludeTags && filters.excludeTags.length > 0) {
|
|
380
|
-
if (containsAny(tags, filters.excludeTags)) {
|
|
381
|
-
if (stats) stats.filteredByTags++;
|
|
382
|
-
return false;
|
|
383
|
-
}
|
|
384
|
-
}
|
|
385
|
-
if (filters.excludePaths && filters.excludePaths.length > 0) {
|
|
386
|
-
if (matchesAnyPattern(path, filters.excludePaths)) {
|
|
387
|
-
if (stats) stats.filteredByPaths++;
|
|
388
|
-
return false;
|
|
389
|
-
}
|
|
390
|
-
}
|
|
391
|
-
if (filters.excludeMethods && filters.excludeMethods.length > 0) {
|
|
392
|
-
const methodsLower = filters.excludeMethods.map((m) => m.toLowerCase());
|
|
393
|
-
if (methodsLower.includes(methodLower)) {
|
|
394
|
-
if (stats) stats.filteredByMethods++;
|
|
395
|
-
return false;
|
|
396
|
-
}
|
|
397
|
-
}
|
|
398
|
-
if (filters.excludeOperationIds && filters.excludeOperationIds.length > 0) {
|
|
399
|
-
if (matchesAnyPattern(operationId, filters.excludeOperationIds)) {
|
|
400
|
-
if (stats) stats.filteredByOperationIds++;
|
|
401
|
-
return false;
|
|
402
|
-
}
|
|
403
|
-
}
|
|
404
|
-
return true;
|
|
405
|
-
}
|
|
406
|
-
function validateFilters(stats, filters) {
|
|
407
|
-
if (!filters || stats.totalOperations === 0) {
|
|
408
|
-
return;
|
|
409
|
-
}
|
|
410
|
-
if (stats.includedOperations === 0) {
|
|
411
|
-
console.warn(
|
|
412
|
-
`\u26A0\uFE0F Warning: All ${stats.totalOperations} operations were filtered out. Check your operationFilters configuration.`
|
|
413
|
-
);
|
|
414
|
-
const filterBreakdown = [];
|
|
415
|
-
if (stats.filteredByTags > 0) filterBreakdown.push(`${stats.filteredByTags} by tags`);
|
|
416
|
-
if (stats.filteredByPaths > 0) filterBreakdown.push(`${stats.filteredByPaths} by paths`);
|
|
417
|
-
if (stats.filteredByMethods > 0) filterBreakdown.push(`${stats.filteredByMethods} by methods`);
|
|
418
|
-
if (stats.filteredByOperationIds > 0) filterBreakdown.push(`${stats.filteredByOperationIds} by operationIds`);
|
|
419
|
-
if (stats.filteredByDeprecated > 0) filterBreakdown.push(`${stats.filteredByDeprecated} by deprecated flag`);
|
|
420
|
-
if (filterBreakdown.length > 0) {
|
|
421
|
-
console.warn(` Filtered: ${filterBreakdown.join(", ")}`);
|
|
422
|
-
}
|
|
423
|
-
}
|
|
424
|
-
}
|
|
425
|
-
function formatFilterStatistics(stats) {
|
|
426
|
-
if (stats.totalOperations === 0) {
|
|
427
|
-
return "";
|
|
428
|
-
}
|
|
429
|
-
const lines = [];
|
|
430
|
-
lines.push("Operation Filtering:");
|
|
431
|
-
lines.push(` Total operations: ${stats.totalOperations}`);
|
|
432
|
-
lines.push(` Included operations: ${stats.includedOperations}`);
|
|
433
|
-
const filteredCount = stats.filteredByTags + stats.filteredByPaths + stats.filteredByMethods + stats.filteredByOperationIds + stats.filteredByDeprecated;
|
|
434
|
-
if (filteredCount > 0) {
|
|
435
|
-
lines.push(` Filtered operations: ${filteredCount}`);
|
|
436
|
-
if (stats.filteredByTags > 0) lines.push(` - By tags: ${stats.filteredByTags}`);
|
|
437
|
-
if (stats.filteredByPaths > 0) lines.push(` - By paths: ${stats.filteredByPaths}`);
|
|
438
|
-
if (stats.filteredByMethods > 0) lines.push(` - By methods: ${stats.filteredByMethods}`);
|
|
439
|
-
if (stats.filteredByOperationIds > 0) lines.push(` - By operationIds: ${stats.filteredByOperationIds}`);
|
|
440
|
-
if (stats.filteredByDeprecated > 0) lines.push(` - By deprecated: ${stats.filteredByDeprecated}`);
|
|
441
|
-
}
|
|
442
|
-
return lines.join("\n");
|
|
443
|
-
}
|
|
444
|
-
|
|
445
|
-
// src/utils/pattern-utils.ts
|
|
446
|
-
import { minimatch as minimatch2 } from "minimatch";
|
|
447
|
-
function isValidGlobPattern(pattern) {
|
|
448
|
-
try {
|
|
449
|
-
new minimatch2.Minimatch(pattern);
|
|
450
|
-
return true;
|
|
451
|
-
} catch {
|
|
452
|
-
return false;
|
|
453
|
-
}
|
|
454
|
-
}
|
|
455
|
-
function isGlobPattern(pattern) {
|
|
456
|
-
return /[*?[\]{}!]/.test(pattern);
|
|
457
|
-
}
|
|
458
|
-
function stripPrefix(input, pattern, ensureLeadingChar) {
|
|
459
|
-
if (!pattern) {
|
|
460
|
-
return input;
|
|
461
|
-
}
|
|
462
|
-
if (isGlobPattern(pattern) && !isValidGlobPattern(pattern)) {
|
|
463
|
-
console.warn(`\u26A0\uFE0F Invalid glob pattern "${pattern}": Pattern is malformed`);
|
|
464
|
-
return input;
|
|
465
|
-
}
|
|
466
|
-
if (isGlobPattern(pattern)) {
|
|
467
|
-
let longestMatch = -1;
|
|
468
|
-
for (let i = 1; i <= input.length; i++) {
|
|
469
|
-
const testPrefix = input.substring(0, i);
|
|
470
|
-
if (minimatch2(testPrefix, pattern)) {
|
|
471
|
-
longestMatch = i;
|
|
472
|
-
}
|
|
473
|
-
}
|
|
474
|
-
if (longestMatch > 0) {
|
|
475
|
-
const stripped = input.substring(longestMatch);
|
|
476
|
-
if (ensureLeadingChar) {
|
|
477
|
-
if (stripped === "") {
|
|
478
|
-
return ensureLeadingChar;
|
|
479
|
-
}
|
|
480
|
-
if (!stripped.startsWith(ensureLeadingChar)) {
|
|
481
|
-
return `${ensureLeadingChar}${stripped}`;
|
|
482
|
-
}
|
|
483
|
-
}
|
|
484
|
-
return stripped === "" && !ensureLeadingChar ? input : stripped;
|
|
485
|
-
}
|
|
486
|
-
return input;
|
|
487
|
-
}
|
|
488
|
-
if (input.startsWith(pattern)) {
|
|
489
|
-
const stripped = input.substring(pattern.length);
|
|
490
|
-
if (ensureLeadingChar) {
|
|
491
|
-
if (stripped === "") {
|
|
492
|
-
return ensureLeadingChar;
|
|
493
|
-
}
|
|
494
|
-
if (!stripped.startsWith(ensureLeadingChar)) {
|
|
495
|
-
return `${ensureLeadingChar}${stripped}`;
|
|
496
|
-
}
|
|
497
|
-
}
|
|
498
|
-
return stripped;
|
|
499
|
-
}
|
|
500
|
-
return input;
|
|
501
|
-
}
|
|
502
|
-
function stripPathPrefix(path, pattern) {
|
|
503
|
-
if (!pattern) {
|
|
504
|
-
return path;
|
|
505
|
-
}
|
|
506
|
-
if (!isGlobPattern(pattern)) {
|
|
507
|
-
let normalizedPattern = pattern.trim();
|
|
508
|
-
if (!normalizedPattern.startsWith("/")) {
|
|
509
|
-
normalizedPattern = `/${normalizedPattern}`;
|
|
510
|
-
}
|
|
511
|
-
if (normalizedPattern.endsWith("/") && normalizedPattern !== "/") {
|
|
512
|
-
normalizedPattern = normalizedPattern.slice(0, -1);
|
|
513
|
-
}
|
|
514
|
-
return stripPrefix(path, normalizedPattern, "/");
|
|
515
|
-
}
|
|
516
|
-
return stripPrefix(path, pattern, "/");
|
|
517
|
-
}
|
|
518
|
-
|
|
519
|
-
// src/utils/ref-resolver.ts
|
|
520
|
-
function resolveRef(obj, spec, maxDepth = 10) {
|
|
521
|
-
var _a, _b, _c, _d;
|
|
522
|
-
if (!obj || typeof obj !== "object" || maxDepth <= 0) return obj;
|
|
523
|
-
if (!obj.$ref) return obj;
|
|
524
|
-
const ref = obj.$ref;
|
|
525
|
-
let resolved = null;
|
|
526
|
-
const paramMatch = ref.match(/^#\/components\/parameters\/(.+)$/);
|
|
527
|
-
const requestBodyMatch = ref.match(/^#\/components\/requestBodies\/(.+)$/);
|
|
528
|
-
const responseMatch = ref.match(/^#\/components\/responses\/(.+)$/);
|
|
529
|
-
const schemaMatch = ref.match(/^#\/components\/schemas\/(.+)$/);
|
|
530
|
-
if (paramMatch && ((_a = spec.components) == null ? void 0 : _a.parameters)) {
|
|
531
|
-
const name = paramMatch[1];
|
|
532
|
-
resolved = spec.components.parameters[name];
|
|
533
|
-
} else if (requestBodyMatch && ((_b = spec.components) == null ? void 0 : _b.requestBodies)) {
|
|
534
|
-
const name = requestBodyMatch[1];
|
|
535
|
-
resolved = spec.components.requestBodies[name];
|
|
536
|
-
} else if (responseMatch && ((_c = spec.components) == null ? void 0 : _c.responses)) {
|
|
537
|
-
const name = responseMatch[1];
|
|
538
|
-
resolved = spec.components.responses[name];
|
|
539
|
-
} else if (schemaMatch && ((_d = spec.components) == null ? void 0 : _d.schemas)) {
|
|
540
|
-
const name = schemaMatch[1];
|
|
541
|
-
resolved = spec.components.schemas[name];
|
|
542
|
-
}
|
|
543
|
-
if (resolved) {
|
|
544
|
-
if (resolved.$ref) {
|
|
545
|
-
return resolveRef(resolved, spec, maxDepth - 1);
|
|
546
|
-
}
|
|
547
|
-
return resolved;
|
|
548
|
-
}
|
|
549
|
-
return obj;
|
|
550
|
-
}
|
|
551
|
-
function resolveParameterRef(param, spec) {
|
|
552
|
-
return resolveRef(param, spec);
|
|
553
|
-
}
|
|
554
|
-
function resolveRequestBodyRef(requestBody, spec) {
|
|
555
|
-
return resolveRef(requestBody, spec);
|
|
556
|
-
}
|
|
557
|
-
function resolveResponseRef(response, spec) {
|
|
558
|
-
return resolveRef(response, spec);
|
|
559
|
-
}
|
|
560
|
-
function mergeParameters(pathParams, operationParams, spec) {
|
|
561
|
-
const resolvedPathParams = (pathParams || []).map((p) => resolveParameterRef(p, spec));
|
|
562
|
-
const resolvedOperationParams = (operationParams || []).map((p) => resolveParameterRef(p, spec));
|
|
563
|
-
const merged = [...resolvedPathParams];
|
|
564
|
-
for (const opParam of resolvedOperationParams) {
|
|
565
|
-
if (!opParam || typeof opParam !== "object") continue;
|
|
566
|
-
const existingIndex = merged.findIndex(
|
|
567
|
-
(p) => p && typeof p === "object" && p.name === opParam.name && p.in === opParam.in
|
|
568
|
-
);
|
|
569
|
-
if (existingIndex >= 0) {
|
|
570
|
-
merged[existingIndex] = opParam;
|
|
571
|
-
} else {
|
|
572
|
-
merged.push(opParam);
|
|
573
|
-
}
|
|
574
|
-
}
|
|
575
|
-
return merged;
|
|
576
|
-
}
|
|
577
|
-
|
|
578
|
-
// src/utils/string-utils.ts
|
|
579
|
-
function escapePattern(str) {
|
|
580
|
-
return str.replace(/\//g, "\\/");
|
|
581
|
-
}
|
|
582
|
-
function escapeJSDoc(str) {
|
|
583
|
-
return str.replace(/\*\//g, "*\\/");
|
|
584
|
-
}
|
|
585
|
-
|
|
586
|
-
// src/utils/typescript-loader.ts
|
|
587
|
-
function createTypeScriptLoader() {
|
|
588
|
-
return async (filepath) => {
|
|
589
|
-
try {
|
|
590
|
-
const esbuild = await import("esbuild");
|
|
591
|
-
const fs = await import("fs");
|
|
592
|
-
const path = await import("path");
|
|
593
|
-
const tsCode = fs.readFileSync(filepath, "utf-8");
|
|
594
|
-
const result = await esbuild.build({
|
|
595
|
-
stdin: {
|
|
596
|
-
contents: tsCode,
|
|
597
|
-
loader: "ts",
|
|
598
|
-
resolveDir: path.dirname(filepath),
|
|
599
|
-
sourcefile: filepath
|
|
600
|
-
},
|
|
601
|
-
format: "cjs",
|
|
602
|
-
platform: "node",
|
|
603
|
-
target: "node18",
|
|
604
|
-
bundle: false,
|
|
605
|
-
write: false
|
|
606
|
-
});
|
|
607
|
-
const jsCode = result.outputFiles[0].text;
|
|
608
|
-
const module = { exports: {} };
|
|
609
|
-
const func = new Function("exports", "module", "require", "__filename", "__dirname", jsCode);
|
|
610
|
-
func(module.exports, module, __require, filepath, path.dirname(filepath));
|
|
611
|
-
return module.exports.default || module.exports;
|
|
612
|
-
} catch (error) {
|
|
613
|
-
throw new Error(
|
|
614
|
-
`Failed to load TypeScript config from ${filepath}: ${error instanceof Error ? error.message : String(error)}`
|
|
615
|
-
);
|
|
616
|
-
}
|
|
617
|
-
};
|
|
618
|
-
}
|
|
619
|
-
|
|
620
|
-
// src/validators/string-validator.ts
|
|
621
|
-
var PATTERN_CACHE = new LRUCache(1e3);
|
|
622
|
-
var DEFAULT_FORMAT_MAP = {
|
|
623
|
-
uuid: "z.uuid()",
|
|
624
|
-
email: "z.email()",
|
|
625
|
-
uri: "z.url()",
|
|
626
|
-
url: "z.url()",
|
|
627
|
-
"uri-reference": 'z.string().refine((val) => !/\\s/.test(val), { message: "Must be a valid URI reference" })',
|
|
628
|
-
hostname: 'z.string().refine((val) => /^(?=.{1,253}$)(?:(?!-)[A-Za-z0-9-]{1,63}(?<!-)\\.)*(?!-)[A-Za-z0-9-]{1,63}(?<!-)$/.test(val), { message: "Must be a valid hostname" })',
|
|
629
|
-
byte: "z.base64()",
|
|
630
|
-
binary: "z.string()",
|
|
631
|
-
date: "z.iso.date()",
|
|
632
|
-
time: "z.iso.time()",
|
|
633
|
-
duration: 'z.string().refine((val) => /^P(?:(?:\\d+Y)?(?:\\d+M)?(?:\\d+D)?(?:T(?:\\d+H)?(?:\\d+M)?(?:\\d+(?:\\.\\d+)?S)?)?|\\d+W)$/.test(val) && !/^PT?$/.test(val), { message: "Must be a valid ISO 8601 duration" })',
|
|
634
|
-
ipv4: "z.ipv4()",
|
|
635
|
-
ipv6: "z.ipv6()",
|
|
636
|
-
emoji: "z.emoji()",
|
|
637
|
-
base64: "z.base64()",
|
|
638
|
-
base64url: "z.base64url()",
|
|
639
|
-
nanoid: "z.nanoid()",
|
|
640
|
-
cuid: "z.cuid()",
|
|
641
|
-
cuid2: "z.cuid2()",
|
|
642
|
-
ulid: "z.ulid()",
|
|
643
|
-
cidr: "z.cidrv4()",
|
|
644
|
-
// Default to v4
|
|
645
|
-
cidrv4: "z.cidrv4()",
|
|
646
|
-
cidrv6: "z.cidrv6()",
|
|
647
|
-
"json-pointer": 'z.string().refine((val) => val === "" || /^(\\/([^~/]|~0|~1)+)+$/.test(val), { message: "Must be a valid JSON Pointer (RFC 6901)" })',
|
|
648
|
-
"relative-json-pointer": 'z.string().refine((val) => /^(0|[1-9]\\d*)(#|(\\/([^~/]|~0|~1)+)*)$/.test(val), { message: "Must be a valid relative JSON Pointer" })'
|
|
649
|
-
};
|
|
650
|
-
var FORMAT_MAP = {
|
|
651
|
-
...DEFAULT_FORMAT_MAP,
|
|
652
|
-
"date-time": "z.iso.datetime()"
|
|
653
|
-
};
|
|
654
|
-
function configureDateTimeFormat(pattern) {
|
|
655
|
-
if (!pattern) {
|
|
656
|
-
FORMAT_MAP["date-time"] = "z.iso.datetime()";
|
|
657
|
-
return;
|
|
658
|
-
}
|
|
659
|
-
const patternStr = pattern instanceof RegExp ? pattern.source : pattern;
|
|
660
|
-
if (patternStr === "") {
|
|
661
|
-
FORMAT_MAP["date-time"] = "z.iso.datetime()";
|
|
662
|
-
return;
|
|
663
|
-
}
|
|
664
|
-
try {
|
|
665
|
-
new RegExp(patternStr);
|
|
666
|
-
} catch (error) {
|
|
667
|
-
throw new Error(
|
|
668
|
-
`Invalid regular expression pattern for customDateTimeFormatRegex: ${patternStr}. ${error instanceof Error ? error.message : "Pattern is malformed"}`
|
|
669
|
-
);
|
|
670
|
-
}
|
|
671
|
-
const escapedPattern = escapePattern(patternStr);
|
|
672
|
-
FORMAT_MAP["date-time"] = `z.string().regex(/${escapedPattern}/)`;
|
|
673
|
-
}
|
|
674
|
-
function resetFormatMap() {
|
|
675
|
-
FORMAT_MAP = {
|
|
676
|
-
...DEFAULT_FORMAT_MAP,
|
|
677
|
-
"date-time": "z.iso.datetime()"
|
|
678
|
-
};
|
|
679
|
-
}
|
|
680
|
-
export {
|
|
681
|
-
LRUCache,
|
|
682
|
-
OperationFiltersSchema,
|
|
683
|
-
RequestResponseOptionsSchema,
|
|
684
|
-
configureDateTimeFormat,
|
|
685
|
-
createFilterStatistics,
|
|
686
|
-
createTypeScriptLoader,
|
|
687
|
-
escapeJSDoc,
|
|
688
|
-
executeBatch,
|
|
689
|
-
formatConfigValidationError,
|
|
690
|
-
formatFilterStatistics,
|
|
691
|
-
getBatchExitCode,
|
|
692
|
-
getResponseParseMethod,
|
|
693
|
-
mergeParameters,
|
|
694
|
-
resetFormatMap,
|
|
695
|
-
resolveParameterRef,
|
|
696
|
-
resolveRef,
|
|
697
|
-
resolveRequestBodyRef,
|
|
698
|
-
resolveResponseRef,
|
|
699
|
-
shouldIncludeOperation,
|
|
700
|
-
stripPathPrefix,
|
|
701
|
-
stripPrefix,
|
|
702
|
-
toCamelCase,
|
|
703
|
-
toPascalCase,
|
|
704
|
-
validateFilters
|
|
705
|
-
};
|
|
706
|
-
//# sourceMappingURL=internal.mjs.map
|