@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/README.md +270 -51
- package/dist/cli.js +234 -164
- package/dist/cli.js.map +1 -1
- package/dist/cli.mjs +290 -202
- package/dist/cli.mjs.map +1 -1
- package/dist/index.d.mts +9 -344
- package/dist/index.d.ts +9 -344
- package/dist/index.js +39 -13
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +38 -8
- package/dist/index.mjs.map +1 -1
- package/dist/internal.d.mts +200 -0
- package/dist/internal.d.ts +200 -0
- package/dist/internal.js +464 -0
- package/dist/internal.js.map +1 -0
- package/dist/internal.mjs +422 -0
- package/dist/internal.mjs.map +1 -0
- package/dist/types-BjoP91vk.d.mts +314 -0
- package/dist/types-BjoP91vk.d.ts +314 -0
- package/package.json +21 -10
package/dist/index.mjs
CHANGED
|
@@ -67,6 +67,7 @@ var ConfigurationError = class extends GeneratorError {
|
|
|
67
67
|
// src/openapi-generator.ts
|
|
68
68
|
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "fs";
|
|
69
69
|
import { dirname, normalize } from "path";
|
|
70
|
+
import { minimatch as minimatch2 } from "minimatch";
|
|
70
71
|
import { parse } from "yaml";
|
|
71
72
|
|
|
72
73
|
// src/utils/name-utils.ts
|
|
@@ -203,6 +204,9 @@ var LRUCache = class {
|
|
|
203
204
|
this.cache = /* @__PURE__ */ new Map();
|
|
204
205
|
this.maxSize = maxSize;
|
|
205
206
|
}
|
|
207
|
+
get capacity() {
|
|
208
|
+
return this.maxSize;
|
|
209
|
+
}
|
|
206
210
|
get(key) {
|
|
207
211
|
if (!this.cache.has(key)) return void 0;
|
|
208
212
|
const value = this.cache.get(key);
|
|
@@ -752,6 +756,11 @@ ${properties.join(",\n")}
|
|
|
752
756
|
|
|
753
757
|
// src/validators/string-validator.ts
|
|
754
758
|
var PATTERN_CACHE = new LRUCache(1e3);
|
|
759
|
+
function configurePatternCache(size) {
|
|
760
|
+
if (size > 0 && size !== PATTERN_CACHE.capacity) {
|
|
761
|
+
PATTERN_CACHE = new LRUCache(size);
|
|
762
|
+
}
|
|
763
|
+
}
|
|
755
764
|
var FORMAT_MAP = {
|
|
756
765
|
uuid: "z.uuid()",
|
|
757
766
|
email: "z.email()",
|
|
@@ -1372,7 +1381,7 @@ var OpenApiGenerator = class {
|
|
|
1372
1381
|
this.schemaUsageMap = /* @__PURE__ */ new Map();
|
|
1373
1382
|
this.needsZodImport = true;
|
|
1374
1383
|
this.filterStats = createFilterStatistics();
|
|
1375
|
-
var _a, _b, _c;
|
|
1384
|
+
var _a, _b, _c, _d, _e;
|
|
1376
1385
|
if (!options.input) {
|
|
1377
1386
|
throw new ConfigurationError("Input path is required", { providedOptions: options });
|
|
1378
1387
|
}
|
|
@@ -1388,8 +1397,14 @@ var OpenApiGenerator = class {
|
|
|
1388
1397
|
showStats: (_c = options.showStats) != null ? _c : true,
|
|
1389
1398
|
request: options.request,
|
|
1390
1399
|
response: options.response,
|
|
1391
|
-
operationFilters: options.operationFilters
|
|
1400
|
+
operationFilters: options.operationFilters,
|
|
1401
|
+
ignoreHeaders: options.ignoreHeaders,
|
|
1402
|
+
cacheSize: (_d = options.cacheSize) != null ? _d : 1e3,
|
|
1403
|
+
batchSize: (_e = options.batchSize) != null ? _e : 10
|
|
1392
1404
|
};
|
|
1405
|
+
if (this.options.cacheSize) {
|
|
1406
|
+
configurePatternCache(this.options.cacheSize);
|
|
1407
|
+
}
|
|
1393
1408
|
try {
|
|
1394
1409
|
const fs = __require("fs");
|
|
1395
1410
|
if (!fs.existsSync(this.options.input)) {
|
|
@@ -1525,6 +1540,7 @@ var OpenApiGenerator = class {
|
|
|
1525
1540
|
const normalizedOutput = normalize(this.options.output);
|
|
1526
1541
|
this.ensureDirectoryExists(normalizedOutput);
|
|
1527
1542
|
writeFileSync(normalizedOutput, output);
|
|
1543
|
+
console.log(` \u2713 Generated ${normalizedOutput}`);
|
|
1528
1544
|
}
|
|
1529
1545
|
/**
|
|
1530
1546
|
* Resolve options for a specific context (request or response)
|
|
@@ -1935,6 +1951,24 @@ ${propsCode}
|
|
|
1935
1951
|
}
|
|
1936
1952
|
}
|
|
1937
1953
|
}
|
|
1954
|
+
/**
|
|
1955
|
+
* Check if a header should be ignored based on filter patterns
|
|
1956
|
+
* @internal
|
|
1957
|
+
*/
|
|
1958
|
+
shouldIgnoreHeader(headerName) {
|
|
1959
|
+
const ignorePatterns = this.options.ignoreHeaders;
|
|
1960
|
+
if (!ignorePatterns || ignorePatterns.length === 0) {
|
|
1961
|
+
return false;
|
|
1962
|
+
}
|
|
1963
|
+
if (ignorePatterns.includes("*")) {
|
|
1964
|
+
return true;
|
|
1965
|
+
}
|
|
1966
|
+
const headerLower = headerName.toLowerCase();
|
|
1967
|
+
return ignorePatterns.some((pattern) => {
|
|
1968
|
+
const patternLower = pattern.toLowerCase();
|
|
1969
|
+
return minimatch2(headerLower, patternLower);
|
|
1970
|
+
});
|
|
1971
|
+
}
|
|
1938
1972
|
/**
|
|
1939
1973
|
* Generate header parameter schemas for each operation
|
|
1940
1974
|
* Header parameters are always string type (HTTP header semantics)
|
|
@@ -1957,7 +1991,7 @@ ${propsCode}
|
|
|
1957
1991
|
continue;
|
|
1958
1992
|
}
|
|
1959
1993
|
const headerParams = operation.parameters.filter(
|
|
1960
|
-
(param) => param && typeof param === "object" && param.in === "header"
|
|
1994
|
+
(param) => param && typeof param === "object" && param.in === "header" && !this.shouldIgnoreHeader(param.name)
|
|
1961
1995
|
);
|
|
1962
1996
|
if (headerParams.length === 0) {
|
|
1963
1997
|
continue;
|
|
@@ -2167,10 +2201,6 @@ export {
|
|
|
2167
2201
|
OpenApiGenerator,
|
|
2168
2202
|
SchemaGenerationError,
|
|
2169
2203
|
SpecValidationError,
|
|
2170
|
-
|
|
2171
|
-
defineConfig,
|
|
2172
|
-
formatFilterStatistics,
|
|
2173
|
-
shouldIncludeOperation,
|
|
2174
|
-
validateFilters
|
|
2204
|
+
defineConfig
|
|
2175
2205
|
};
|
|
2176
2206
|
//# sourceMappingURL=index.mjs.map
|