@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/dist/index.mjs CHANGED
@@ -722,7 +722,6 @@ ${properties.join(",\n")}
722
722
  // src/validators/string-validator.ts
723
723
  import { escapePattern } from "@cerios/openapi-core";
724
724
  var DEFAULT_FORMAT_MAP = {
725
- uuid: "z.uuid()",
726
725
  email: "z.email()",
727
726
  uri: "z.url()",
728
727
  url: "z.url()",
@@ -749,6 +748,16 @@ var DEFAULT_FORMAT_MAP = {
749
748
  "json-pointer": 'z.string().refine((val) => val === "" || /^(\\/([^~/]|~0|~1)+)+$/.test(val), { message: "Must be a valid JSON Pointer (RFC 6901)" })',
750
749
  "relative-json-pointer": 'z.string().refine((val) => /^(0|[1-9]\\d*)(#|(\\/([^~/]|~0|~1)+)*)$/.test(val), { message: "Must be a valid relative JSON Pointer" })'
751
750
  };
751
+ function buildUuidValidation(format) {
752
+ if (!format || format === "uuid") {
753
+ return "z.uuid()";
754
+ }
755
+ if (format === "guid") {
756
+ return "z.guid()";
757
+ }
758
+ const version = format.replace("uuid", "");
759
+ return `z.uuid({ version: "${version}" })`;
760
+ }
752
761
  function buildDateTimeValidation(pattern) {
753
762
  if (!pattern) {
754
763
  return "z.iso.datetime()";
@@ -772,6 +781,8 @@ function generateStringValidation(schema, useDescribe, context) {
772
781
  const format = schema.format || "";
773
782
  if (format === "date-time") {
774
783
  validation = context.dateTimeValidation;
784
+ } else if (format === "uuid" || format === "guid") {
785
+ validation = context.uuidValidation;
775
786
  } else {
776
787
  validation = DEFAULT_FORMAT_MAP[format] || "z.string()";
777
788
  }
@@ -1251,6 +1262,7 @@ var _PropertyGenerator = class _PropertyGenerator {
1251
1262
  case "string":
1252
1263
  validation = generateStringValidation(schema, this.context.useDescribe, {
1253
1264
  dateTimeValidation: this.context.dateTimeValidation,
1265
+ uuidValidation: this.context.uuidValidation,
1254
1266
  patternCache: this.context.patternCache
1255
1267
  });
1256
1268
  break;
@@ -1473,11 +1485,13 @@ var OpenApiGenerator = class {
1473
1485
  cacheSize: (_h = options.cacheSize) != null ? _h : 1e3,
1474
1486
  batchSize: (_i = options.batchSize) != null ? _i : 10,
1475
1487
  customDateTimeFormatRegex: options.customDateTimeFormatRegex,
1488
+ uuidFormat: options.uuidFormat,
1476
1489
  includeHeader: options.includeHeader,
1477
1490
  fileHeader: options.fileHeader
1478
1491
  };
1479
1492
  this.patternCache = new LRUCache2((_j = this.options.cacheSize) != null ? _j : 1e3);
1480
1493
  this.dateTimeValidation = buildDateTimeValidation(this.options.customDateTimeFormatRegex);
1494
+ this.uuidValidation = buildUuidValidation(this.options.uuidFormat);
1481
1495
  this.spec = loadOpenAPISpec(this.options.input);
1482
1496
  this.validateSpec();
1483
1497
  this.requestOptions = this.resolveOptionsForContext("request");
@@ -1498,6 +1512,7 @@ var OpenApiGenerator = class {
1498
1512
  },
1499
1513
  stripSchemaPrefix: this.options.stripSchemaPrefix,
1500
1514
  dateTimeValidation: this.dateTimeValidation,
1515
+ uuidValidation: this.uuidValidation,
1501
1516
  patternCache: this.patternCache,
1502
1517
  separateTypesFile: this.separateSchemasMode,
1503
1518
  warn: (msg) => {
@@ -2039,6 +2054,7 @@ ${typeCode}`;
2039
2054
  },
2040
2055
  stripSchemaPrefix: this.options.stripSchemaPrefix,
2041
2056
  dateTimeValidation: this.dateTimeValidation,
2057
+ uuidValidation: this.uuidValidation,
2042
2058
  patternCache: this.patternCache,
2043
2059
  separateTypesFile: this.separateSchemasMode,
2044
2060
  warn: (msg) => {
@@ -2291,7 +2307,8 @@ ${propsCode}
2291
2307
  email: "z.email()",
2292
2308
  uri: "z.url()",
2293
2309
  url: "z.url()",
2294
- uuid: "z.uuid()"
2310
+ uuid: this.uuidValidation,
2311
+ guid: this.uuidValidation
2295
2312
  };
2296
2313
  if (schema.format && formatMap[schema.format]) {
2297
2314
  let zodType2 = formatMap[schema.format];
@@ -2542,6 +2559,7 @@ export {
2542
2559
  SchemaGenerationError2 as SchemaGenerationError,
2543
2560
  SpecValidationError2 as SpecValidationError,
2544
2561
  buildDateTimeValidation,
2562
+ buildUuidValidation,
2545
2563
  defineConfig
2546
2564
  };
2547
2565
  //# sourceMappingURL=index.mjs.map