@cerios/openapi-to-zod 1.6.0 → 1.7.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 +30 -0
- package/dist/cli.js +21 -2
- package/dist/cli.js.map +1 -1
- package/dist/cli.mjs +21 -2
- package/dist/cli.mjs.map +1 -1
- package/dist/index.d.mts +40 -1
- package/dist/index.d.ts +40 -1
- package/dist/index.js +21 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +20 -2
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/cli.mjs
CHANGED
|
@@ -5747,6 +5747,16 @@ var init_object_validator = __esm({
|
|
|
5747
5747
|
|
|
5748
5748
|
// src/validators/string-validator.ts
|
|
5749
5749
|
import { escapePattern } from "@cerios/openapi-core";
|
|
5750
|
+
function buildUuidValidation(format) {
|
|
5751
|
+
if (!format || format === "uuid") {
|
|
5752
|
+
return "z.uuid()";
|
|
5753
|
+
}
|
|
5754
|
+
if (format === "guid") {
|
|
5755
|
+
return "z.guid()";
|
|
5756
|
+
}
|
|
5757
|
+
const version = format.replace("uuid", "");
|
|
5758
|
+
return `z.uuid({ version: "${version}" })`;
|
|
5759
|
+
}
|
|
5750
5760
|
function buildDateTimeValidation(pattern) {
|
|
5751
5761
|
if (!pattern) {
|
|
5752
5762
|
return "z.iso.datetime()";
|
|
@@ -5770,6 +5780,8 @@ function generateStringValidation(schema, useDescribe, context) {
|
|
|
5770
5780
|
const format = schema.format || "";
|
|
5771
5781
|
if (format === "date-time") {
|
|
5772
5782
|
validation = context.dateTimeValidation;
|
|
5783
|
+
} else if (format === "uuid" || format === "guid") {
|
|
5784
|
+
validation = context.uuidValidation;
|
|
5773
5785
|
} else {
|
|
5774
5786
|
validation = DEFAULT_FORMAT_MAP[format] || "z.string()";
|
|
5775
5787
|
}
|
|
@@ -5843,7 +5855,6 @@ var init_string_validator = __esm({
|
|
|
5843
5855
|
init_esm_shims();
|
|
5844
5856
|
init_string_utils();
|
|
5845
5857
|
DEFAULT_FORMAT_MAP = {
|
|
5846
|
-
uuid: "z.uuid()",
|
|
5847
5858
|
email: "z.email()",
|
|
5848
5859
|
uri: "z.url()",
|
|
5849
5860
|
url: "z.url()",
|
|
@@ -6306,6 +6317,7 @@ var init_property_generator = __esm({
|
|
|
6306
6317
|
case "string":
|
|
6307
6318
|
validation = generateStringValidation(schema, this.context.useDescribe, {
|
|
6308
6319
|
dateTimeValidation: this.context.dateTimeValidation,
|
|
6320
|
+
uuidValidation: this.context.uuidValidation,
|
|
6309
6321
|
patternCache: this.context.patternCache
|
|
6310
6322
|
});
|
|
6311
6323
|
break;
|
|
@@ -6508,11 +6520,13 @@ var init_openapi_generator = __esm({
|
|
|
6508
6520
|
cacheSize: (_h = options.cacheSize) != null ? _h : 1e3,
|
|
6509
6521
|
batchSize: (_i = options.batchSize) != null ? _i : 10,
|
|
6510
6522
|
customDateTimeFormatRegex: options.customDateTimeFormatRegex,
|
|
6523
|
+
uuidFormat: options.uuidFormat,
|
|
6511
6524
|
includeHeader: options.includeHeader,
|
|
6512
6525
|
fileHeader: options.fileHeader
|
|
6513
6526
|
};
|
|
6514
6527
|
this.patternCache = new LRUCache2((_j = this.options.cacheSize) != null ? _j : 1e3);
|
|
6515
6528
|
this.dateTimeValidation = buildDateTimeValidation(this.options.customDateTimeFormatRegex);
|
|
6529
|
+
this.uuidValidation = buildUuidValidation(this.options.uuidFormat);
|
|
6516
6530
|
this.spec = loadOpenAPISpec(this.options.input);
|
|
6517
6531
|
this.validateSpec();
|
|
6518
6532
|
this.requestOptions = this.resolveOptionsForContext("request");
|
|
@@ -6533,6 +6547,7 @@ var init_openapi_generator = __esm({
|
|
|
6533
6547
|
},
|
|
6534
6548
|
stripSchemaPrefix: this.options.stripSchemaPrefix,
|
|
6535
6549
|
dateTimeValidation: this.dateTimeValidation,
|
|
6550
|
+
uuidValidation: this.uuidValidation,
|
|
6536
6551
|
patternCache: this.patternCache,
|
|
6537
6552
|
separateTypesFile: this.separateSchemasMode,
|
|
6538
6553
|
warn: (msg) => {
|
|
@@ -7074,6 +7089,7 @@ ${typeCode}`;
|
|
|
7074
7089
|
},
|
|
7075
7090
|
stripSchemaPrefix: this.options.stripSchemaPrefix,
|
|
7076
7091
|
dateTimeValidation: this.dateTimeValidation,
|
|
7092
|
+
uuidValidation: this.uuidValidation,
|
|
7077
7093
|
patternCache: this.patternCache,
|
|
7078
7094
|
separateTypesFile: this.separateSchemasMode,
|
|
7079
7095
|
warn: (msg) => {
|
|
@@ -7326,7 +7342,8 @@ ${propsCode}
|
|
|
7326
7342
|
email: "z.email()",
|
|
7327
7343
|
uri: "z.url()",
|
|
7328
7344
|
url: "z.url()",
|
|
7329
|
-
uuid:
|
|
7345
|
+
uuid: this.uuidValidation,
|
|
7346
|
+
guid: this.uuidValidation
|
|
7330
7347
|
};
|
|
7331
7348
|
if (schema.format && formatMap[schema.format]) {
|
|
7332
7349
|
let zodType2 = formatMap[schema.format];
|
|
@@ -7620,6 +7637,7 @@ function mergeConfigWithDefaults(config) {
|
|
|
7620
7637
|
suffix: defaults.suffix,
|
|
7621
7638
|
showStats: defaults.showStats,
|
|
7622
7639
|
customDateTimeFormatRegex: defaults.customDateTimeFormatRegex,
|
|
7640
|
+
uuidFormat: defaults.uuidFormat,
|
|
7623
7641
|
enumFormat: defaults.enumFormat,
|
|
7624
7642
|
fileHeader: defaults.fileHeader,
|
|
7625
7643
|
// Override with spec-specific values
|
|
@@ -7642,6 +7660,7 @@ var init_config_loader = __esm({
|
|
|
7642
7660
|
request: RequestResponseOptionsSchema.optional(),
|
|
7643
7661
|
response: RequestResponseOptionsSchema.optional(),
|
|
7644
7662
|
customDateTimeFormatRegex: RegexPatternSchema.optional(),
|
|
7663
|
+
uuidFormat: z.enum(["uuid", "guid", "uuidv1", "uuidv2", "uuidv3", "uuidv4", "uuidv5", "uuidv6", "uuidv7", "uuidv8"]).optional(),
|
|
7645
7664
|
outputZodSchemas: z.string().optional(),
|
|
7646
7665
|
enumFormat: z.enum(["union", "const-object"]).optional(),
|
|
7647
7666
|
typeAssertionThreshold: z.number().int().gte(0).optional()
|