@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/README.md
CHANGED
|
@@ -542,6 +542,36 @@ When using a custom regex, the generator will produce:
|
|
|
542
542
|
|
|
543
543
|
**Note:** This option only affects `date-time` format fields. Other formats (like `date`, `email`, `uuid`) remain unchanged.
|
|
544
544
|
|
|
545
|
+
### UUID Format
|
|
546
|
+
|
|
547
|
+
By default, the generator uses `z.uuid()` for `uuid` and `guid` format fields. You can change this with the `uuidFormat` option to use a specific UUID version or GUID validation:
|
|
548
|
+
|
|
549
|
+
```typescript
|
|
550
|
+
import { defineConfig } from "@cerios/openapi-to-zod";
|
|
551
|
+
|
|
552
|
+
export default defineConfig({
|
|
553
|
+
defaults: {
|
|
554
|
+
uuidFormat: "uuidv4",
|
|
555
|
+
},
|
|
556
|
+
specs: [
|
|
557
|
+
{
|
|
558
|
+
input: "openapi.yaml",
|
|
559
|
+
outputTypes: "src/schemas.ts",
|
|
560
|
+
},
|
|
561
|
+
],
|
|
562
|
+
});
|
|
563
|
+
```
|
|
564
|
+
|
|
565
|
+
**Available values:**
|
|
566
|
+
|
|
567
|
+
| Value | Generated Output |
|
|
568
|
+
| ----------------------- | -------------------------------- |
|
|
569
|
+
| `"uuid"` (default) | `z.uuid()` |
|
|
570
|
+
| `"guid"` | `z.guid()` |
|
|
571
|
+
| `"uuidv1"` – `"uuidv8"` | `z.uuid({ version: "v1" })` etc. |
|
|
572
|
+
|
|
573
|
+
**Note:** Both `format: "uuid"` and `format: "guid"` in OpenAPI specs follow the configured `uuidFormat` setting.
|
|
574
|
+
|
|
545
575
|
## Advanced Features
|
|
546
576
|
|
|
547
577
|
### Operation Filtering
|
package/dist/cli.js
CHANGED
|
@@ -5718,7 +5718,6 @@ ${properties.join(",\n")}
|
|
|
5718
5718
|
init_cjs_shims();
|
|
5719
5719
|
var import_openapi_core4 = require("@cerios/openapi-core");
|
|
5720
5720
|
var DEFAULT_FORMAT_MAP = {
|
|
5721
|
-
uuid: "z.uuid()",
|
|
5722
5721
|
email: "z.email()",
|
|
5723
5722
|
uri: "z.url()",
|
|
5724
5723
|
url: "z.url()",
|
|
@@ -5745,6 +5744,16 @@ var DEFAULT_FORMAT_MAP = {
|
|
|
5745
5744
|
"json-pointer": 'z.string().refine((val) => val === "" || /^(\\/([^~/]|~0|~1)+)+$/.test(val), { message: "Must be a valid JSON Pointer (RFC 6901)" })',
|
|
5746
5745
|
"relative-json-pointer": 'z.string().refine((val) => /^(0|[1-9]\\d*)(#|(\\/([^~/]|~0|~1)+)*)$/.test(val), { message: "Must be a valid relative JSON Pointer" })'
|
|
5747
5746
|
};
|
|
5747
|
+
function buildUuidValidation(format) {
|
|
5748
|
+
if (!format || format === "uuid") {
|
|
5749
|
+
return "z.uuid()";
|
|
5750
|
+
}
|
|
5751
|
+
if (format === "guid") {
|
|
5752
|
+
return "z.guid()";
|
|
5753
|
+
}
|
|
5754
|
+
const version = format.replace("uuid", "");
|
|
5755
|
+
return `z.uuid({ version: "${version}" })`;
|
|
5756
|
+
}
|
|
5748
5757
|
function buildDateTimeValidation(pattern) {
|
|
5749
5758
|
if (!pattern) {
|
|
5750
5759
|
return "z.iso.datetime()";
|
|
@@ -5768,6 +5777,8 @@ function generateStringValidation(schema, useDescribe, context) {
|
|
|
5768
5777
|
const format = schema.format || "";
|
|
5769
5778
|
if (format === "date-time") {
|
|
5770
5779
|
validation = context.dateTimeValidation;
|
|
5780
|
+
} else if (format === "uuid" || format === "guid") {
|
|
5781
|
+
validation = context.uuidValidation;
|
|
5771
5782
|
} else {
|
|
5772
5783
|
validation = DEFAULT_FORMAT_MAP[format] || "z.string()";
|
|
5773
5784
|
}
|
|
@@ -6247,6 +6258,7 @@ var _PropertyGenerator = class _PropertyGenerator {
|
|
|
6247
6258
|
case "string":
|
|
6248
6259
|
validation = generateStringValidation(schema, this.context.useDescribe, {
|
|
6249
6260
|
dateTimeValidation: this.context.dateTimeValidation,
|
|
6261
|
+
uuidValidation: this.context.uuidValidation,
|
|
6250
6262
|
patternCache: this.context.patternCache
|
|
6251
6263
|
});
|
|
6252
6264
|
break;
|
|
@@ -6409,11 +6421,13 @@ var OpenApiGenerator = class {
|
|
|
6409
6421
|
cacheSize: (_h = options.cacheSize) != null ? _h : 1e3,
|
|
6410
6422
|
batchSize: (_i = options.batchSize) != null ? _i : 10,
|
|
6411
6423
|
customDateTimeFormatRegex: options.customDateTimeFormatRegex,
|
|
6424
|
+
uuidFormat: options.uuidFormat,
|
|
6412
6425
|
includeHeader: options.includeHeader,
|
|
6413
6426
|
fileHeader: options.fileHeader
|
|
6414
6427
|
};
|
|
6415
6428
|
this.patternCache = new import_openapi_core6.LRUCache((_j = this.options.cacheSize) != null ? _j : 1e3);
|
|
6416
6429
|
this.dateTimeValidation = buildDateTimeValidation(this.options.customDateTimeFormatRegex);
|
|
6430
|
+
this.uuidValidation = buildUuidValidation(this.options.uuidFormat);
|
|
6417
6431
|
this.spec = (0, import_openapi_core6.loadOpenAPISpec)(this.options.input);
|
|
6418
6432
|
this.validateSpec();
|
|
6419
6433
|
this.requestOptions = this.resolveOptionsForContext("request");
|
|
@@ -6434,6 +6448,7 @@ var OpenApiGenerator = class {
|
|
|
6434
6448
|
},
|
|
6435
6449
|
stripSchemaPrefix: this.options.stripSchemaPrefix,
|
|
6436
6450
|
dateTimeValidation: this.dateTimeValidation,
|
|
6451
|
+
uuidValidation: this.uuidValidation,
|
|
6437
6452
|
patternCache: this.patternCache,
|
|
6438
6453
|
separateTypesFile: this.separateSchemasMode,
|
|
6439
6454
|
warn: (msg) => {
|
|
@@ -6975,6 +6990,7 @@ ${typeCode}`;
|
|
|
6975
6990
|
},
|
|
6976
6991
|
stripSchemaPrefix: this.options.stripSchemaPrefix,
|
|
6977
6992
|
dateTimeValidation: this.dateTimeValidation,
|
|
6993
|
+
uuidValidation: this.uuidValidation,
|
|
6978
6994
|
patternCache: this.patternCache,
|
|
6979
6995
|
separateTypesFile: this.separateSchemasMode,
|
|
6980
6996
|
warn: (msg) => {
|
|
@@ -7227,7 +7243,8 @@ ${propsCode}
|
|
|
7227
7243
|
email: "z.email()",
|
|
7228
7244
|
uri: "z.url()",
|
|
7229
7245
|
url: "z.url()",
|
|
7230
|
-
uuid:
|
|
7246
|
+
uuid: this.uuidValidation,
|
|
7247
|
+
guid: this.uuidValidation
|
|
7231
7248
|
};
|
|
7232
7249
|
if (schema.format && formatMap[schema.format]) {
|
|
7233
7250
|
let zodType2 = formatMap[schema.format];
|
|
@@ -7475,6 +7492,7 @@ var ZodSpecificOptionsSchema = import_zod.z.strictObject({
|
|
|
7475
7492
|
request: import_openapi_core7.RequestResponseOptionsSchema.optional(),
|
|
7476
7493
|
response: import_openapi_core7.RequestResponseOptionsSchema.optional(),
|
|
7477
7494
|
customDateTimeFormatRegex: import_openapi_core7.RegexPatternSchema.optional(),
|
|
7495
|
+
uuidFormat: import_zod.z.enum(["uuid", "guid", "uuidv1", "uuidv2", "uuidv3", "uuidv4", "uuidv5", "uuidv6", "uuidv7", "uuidv8"]).optional(),
|
|
7478
7496
|
outputZodSchemas: import_zod.z.string().optional(),
|
|
7479
7497
|
enumFormat: import_zod.z.enum(["union", "const-object"]).optional(),
|
|
7480
7498
|
typeAssertionThreshold: import_zod.z.number().int().gte(0).optional()
|
|
@@ -7580,6 +7598,7 @@ function mergeConfigWithDefaults(config) {
|
|
|
7580
7598
|
suffix: defaults.suffix,
|
|
7581
7599
|
showStats: defaults.showStats,
|
|
7582
7600
|
customDateTimeFormatRegex: defaults.customDateTimeFormatRegex,
|
|
7601
|
+
uuidFormat: defaults.uuidFormat,
|
|
7583
7602
|
enumFormat: defaults.enumFormat,
|
|
7584
7603
|
fileHeader: defaults.fileHeader,
|
|
7585
7604
|
// Override with spec-specific values
|