@kubb/plugin-zod 5.0.0-beta.10 → 5.0.0-beta.22
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.cjs +142 -127
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +143 -128
- package/dist/index.js.map +1 -1
- package/extension.yaml +21 -1
- package/package.json +5 -5
- package/src/generators/zodGenerator.tsx +51 -18
- package/src/printers/printerZod.ts +40 -62
- package/src/printers/printerZodMini.ts +30 -48
- package/src/utils.ts +14 -30
package/dist/index.cjs
CHANGED
|
@@ -349,27 +349,26 @@ function lengthChecksMini({ min, max, pattern }) {
|
|
|
349
349
|
* to a schema value string using the chainable Zod v4 API.
|
|
350
350
|
*/
|
|
351
351
|
function applyModifiers({ value, nullable, optional, nullish, defaultValue, description }) {
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
352
|
+
const withModifier = (() => {
|
|
353
|
+
if (nullish || nullable && optional) return `${value}.nullish()`;
|
|
354
|
+
if (optional) return `${value}.optional()`;
|
|
355
|
+
if (nullable) return `${value}.nullable()`;
|
|
356
|
+
return value;
|
|
357
|
+
})();
|
|
358
|
+
const withDefault = defaultValue !== void 0 ? `${withModifier}.default(${formatDefault(defaultValue)})` : withModifier;
|
|
359
|
+
return description ? `${withDefault}.describe(${stringify(description)})` : withDefault;
|
|
359
360
|
}
|
|
360
361
|
/**
|
|
361
362
|
* Apply nullable / optional / nullish modifiers using the functional `zod/mini` API
|
|
362
363
|
* (`z.nullable()`, `z.optional()`, `z.nullish()`).
|
|
363
364
|
*/
|
|
364
365
|
function applyMiniModifiers({ value, nullable, optional, nullish, defaultValue }) {
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
}
|
|
371
|
-
if (defaultValue !== void 0) result = `z._default(${result}, ${formatDefault(defaultValue)})`;
|
|
372
|
-
return result;
|
|
366
|
+
const withModifier = (() => {
|
|
367
|
+
if (nullish) return `z.nullish(${value})`;
|
|
368
|
+
const withNullable = nullable ? `z.nullable(${value})` : value;
|
|
369
|
+
return optional ? `z.optional(${withNullable})` : withNullable;
|
|
370
|
+
})();
|
|
371
|
+
return defaultValue !== void 0 ? `z._default(${withModifier}, ${formatDefault(defaultValue)})` : withModifier;
|
|
373
372
|
}
|
|
374
373
|
//#endregion
|
|
375
374
|
//#region src/printers/printerZod.ts
|
|
@@ -383,6 +382,11 @@ function strictOneOfMember$1(member, node) {
|
|
|
383
382
|
return member;
|
|
384
383
|
}
|
|
385
384
|
__name(strictOneOfMember$1, "strictOneOfMember");
|
|
385
|
+
function getMemberConstraint(member) {
|
|
386
|
+
if (member.primitive === "string") return lengthConstraints(_kubb_core.ast.narrowSchema(member, "string") ?? {}) || void 0;
|
|
387
|
+
if (member.primitive === "number" || member.primitive === "integer") return numberConstraints(_kubb_core.ast.narrowSchema(member, "number") ?? _kubb_core.ast.narrowSchema(member, "integer") ?? {}) || void 0;
|
|
388
|
+
if (member.primitive === "array") return lengthConstraints(_kubb_core.ast.narrowSchema(member, "array") ?? {}) || void 0;
|
|
389
|
+
}
|
|
386
390
|
/**
|
|
387
391
|
* Zod v4 printer built with `definePrinter`.
|
|
388
392
|
*
|
|
@@ -455,29 +459,29 @@ const printerZod = _kubb_core.ast.definePrinter((options) => {
|
|
|
455
459
|
return `z.enum([${nonNullValues.map(formatLiteral).join(", ")}])`;
|
|
456
460
|
},
|
|
457
461
|
ref(node) {
|
|
458
|
-
if (!node.name) return
|
|
462
|
+
if (!node.name) return null;
|
|
459
463
|
const refName = node.ref ? _kubb_core.ast.extractRefName(node.ref) ?? node.name : node.name;
|
|
460
464
|
const resolvedName = node.ref ? this.options.resolver?.default(refName, "function") ?? refName : node.name;
|
|
461
465
|
if (node.ref && this.options.cyclicSchemas?.has(refName)) return `z.lazy(() => ${resolvedName})`;
|
|
462
466
|
return resolvedName;
|
|
463
467
|
},
|
|
464
468
|
object(node) {
|
|
465
|
-
|
|
469
|
+
const objectBase = `z.object({\n ${node.properties.map((prop) => {
|
|
466
470
|
const { name: propName, schema } = prop;
|
|
467
471
|
const meta = _kubb_core.ast.syncSchemaRef(schema);
|
|
468
472
|
const isNullable = meta.nullable;
|
|
469
473
|
const isOptional = schema.optional;
|
|
470
474
|
const isNullish = schema.nullish;
|
|
471
475
|
const hasSelfRef = this.options.cyclicSchemas != null && _kubb_core.ast.containsCircularRef(schema, { circularSchemas: this.options.cyclicSchemas });
|
|
476
|
+
const savedCyclicSchemas = this.options.cyclicSchemas;
|
|
472
477
|
if (hasSelfRef) this.options.cyclicSchemas = void 0;
|
|
473
478
|
const baseOutput = this.transform(schema) ?? this.transform(_kubb_core.ast.createSchema({ type: "unknown" }));
|
|
474
|
-
if (hasSelfRef) this.options.cyclicSchemas =
|
|
479
|
+
if (hasSelfRef) this.options.cyclicSchemas = savedCyclicSchemas;
|
|
475
480
|
const wrappedOutput = this.options.wrapOutput ? this.options.wrapOutput({
|
|
476
481
|
output: baseOutput,
|
|
477
482
|
schema
|
|
478
483
|
}) || baseOutput : baseOutput;
|
|
479
|
-
|
|
480
|
-
if (schema.type !== "ref" && meta.type === "ref") descriptionToApply = void 0;
|
|
484
|
+
const descriptionToApply = schema.type !== "ref" && meta.type === "ref" ? void 0 : meta.description;
|
|
481
485
|
const value = applyModifiers({
|
|
482
486
|
value: wrappedOutput,
|
|
483
487
|
nullable: isNullable,
|
|
@@ -489,17 +493,19 @@ const printerZod = _kubb_core.ast.definePrinter((options) => {
|
|
|
489
493
|
if (hasSelfRef) return `get "${propName}"() { return ${value} }`;
|
|
490
494
|
return `"${propName}": ${value}`;
|
|
491
495
|
}).join(",\n ")}\n })`;
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
496
|
+
return (() => {
|
|
497
|
+
if (node.additionalProperties && node.additionalProperties !== true) {
|
|
498
|
+
const catchallType = this.transform(node.additionalProperties);
|
|
499
|
+
return catchallType ? `${objectBase}.catchall(${catchallType})` : objectBase;
|
|
500
|
+
}
|
|
501
|
+
if (node.additionalProperties === true) return `${objectBase}.catchall(${this.transform(_kubb_core.ast.createSchema({ type: "unknown" }))})`;
|
|
502
|
+
if (node.additionalProperties === false) return `${objectBase}.strict()`;
|
|
503
|
+
return objectBase;
|
|
504
|
+
})();
|
|
498
505
|
},
|
|
499
506
|
array(node) {
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
return result;
|
|
507
|
+
const base = `z.array(${(node.items ?? []).map((item) => this.transform(item)).filter(Boolean).join(", ") || this.transform(_kubb_core.ast.createSchema({ type: "unknown" }))})${lengthConstraints(node)}`;
|
|
508
|
+
return node.unique ? `${base}.refine(items => new Set(items).size === items.length, { message: "Array entries must be unique" })` : base;
|
|
503
509
|
},
|
|
504
510
|
tuple(node) {
|
|
505
511
|
return `z.tuple([${(node.items ?? []).map((item) => this.transform(item)).filter(Boolean).join(", ")}])`;
|
|
@@ -520,47 +526,29 @@ const printerZod = _kubb_core.ast.definePrinter((options) => {
|
|
|
520
526
|
if (members.length === 0) return "";
|
|
521
527
|
const [first, ...rest] = members;
|
|
522
528
|
if (!first) return "";
|
|
523
|
-
|
|
524
|
-
if (!
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
if (c) {
|
|
529
|
-
base += c;
|
|
530
|
-
continue;
|
|
531
|
-
}
|
|
532
|
-
} else if (member.primitive === "number" || member.primitive === "integer") {
|
|
533
|
-
const c = numberConstraints(_kubb_core.ast.narrowSchema(member, "number") ?? _kubb_core.ast.narrowSchema(member, "integer") ?? {});
|
|
534
|
-
if (c) {
|
|
535
|
-
base += c;
|
|
536
|
-
continue;
|
|
537
|
-
}
|
|
538
|
-
} else if (member.primitive === "array") {
|
|
539
|
-
const c = lengthConstraints(_kubb_core.ast.narrowSchema(member, "array") ?? {});
|
|
540
|
-
if (c) {
|
|
541
|
-
base += c;
|
|
542
|
-
continue;
|
|
543
|
-
}
|
|
544
|
-
}
|
|
529
|
+
const firstBase = this.transform(first);
|
|
530
|
+
if (!firstBase) return "";
|
|
531
|
+
return rest.reduce((acc, member) => {
|
|
532
|
+
const constraint = getMemberConstraint(member);
|
|
533
|
+
if (constraint) return acc + constraint;
|
|
545
534
|
const transformed = this.transform(member);
|
|
546
|
-
|
|
547
|
-
}
|
|
548
|
-
return base;
|
|
535
|
+
return transformed ? `${acc}.and(${transformed})` : acc;
|
|
536
|
+
}, firstBase);
|
|
549
537
|
},
|
|
550
538
|
...options.nodes
|
|
551
539
|
},
|
|
552
540
|
print(node) {
|
|
553
541
|
const { keysToOmit } = this.options;
|
|
554
|
-
|
|
555
|
-
if (!
|
|
542
|
+
const transformed = this.transform(node);
|
|
543
|
+
if (!transformed) return null;
|
|
556
544
|
const meta = _kubb_core.ast.syncSchemaRef(node);
|
|
557
|
-
if (keysToOmit?.length && meta.primitive === "object" && !(meta.type === "union" && meta.discriminatorPropertyName)) {
|
|
558
|
-
const lazyMatch = base.match(/^z\.lazy\(\(\)\s*=>\s*(.+)\)$/);
|
|
559
|
-
if (lazyMatch) base = `z.lazy(() => ${lazyMatch[1]}.omit({ ${keysToOmit.map((k) => `"${k}": true`).join(", ")} }))`;
|
|
560
|
-
else base = `${base}.omit({ ${keysToOmit.map((k) => `"${k}": true`).join(", ")} })`;
|
|
561
|
-
}
|
|
562
545
|
return applyModifiers({
|
|
563
|
-
value:
|
|
546
|
+
value: (() => {
|
|
547
|
+
if (!keysToOmit?.length || meta.primitive !== "object" || meta.type === "union" && meta.discriminatorPropertyName) return transformed;
|
|
548
|
+
const lazyMatch = transformed.match(/^z\.lazy\(\(\)\s*=>\s*(.+)\)$/);
|
|
549
|
+
if (lazyMatch) return `z.lazy(() => ${lazyMatch[1]}.omit({ ${keysToOmit.map((k) => `"${k}": true`).join(", ")} }))`;
|
|
550
|
+
return `${transformed}.omit({ ${keysToOmit.map((k) => `"${k}": true`).join(", ")} })`;
|
|
551
|
+
})(),
|
|
564
552
|
nullable: meta.nullable,
|
|
565
553
|
optional: meta.optional,
|
|
566
554
|
nullish: meta.nullish,
|
|
@@ -576,6 +564,11 @@ function strictOneOfMember(member, node) {
|
|
|
576
564
|
if (node.type === "object" && (node.additionalProperties === void 0 || node.additionalProperties === false)) return member.replace(/^z\.object\(/, "z.strictObject(");
|
|
577
565
|
return member;
|
|
578
566
|
}
|
|
567
|
+
function getMemberConstraintMini(member) {
|
|
568
|
+
if (member.primitive === "string") return lengthChecksMini(_kubb_core.ast.narrowSchema(member, "string") ?? {}) || void 0;
|
|
569
|
+
if (member.primitive === "number" || member.primitive === "integer") return numberChecksMini(_kubb_core.ast.narrowSchema(member, "number") ?? _kubb_core.ast.narrowSchema(member, "integer") ?? {}) || void 0;
|
|
570
|
+
if (member.primitive === "array") return lengthChecksMini(_kubb_core.ast.narrowSchema(member, "array") ?? {}) || void 0;
|
|
571
|
+
}
|
|
579
572
|
/**
|
|
580
573
|
* Zod v4 **Mini** printer built with `definePrinter`.
|
|
581
574
|
*
|
|
@@ -644,7 +637,7 @@ const printerZodMini = _kubb_core.ast.definePrinter((options) => {
|
|
|
644
637
|
return `z.enum([${nonNullValues.map(formatLiteral).join(", ")}])`;
|
|
645
638
|
},
|
|
646
639
|
ref(node) {
|
|
647
|
-
if (!node.name) return
|
|
640
|
+
if (!node.name) return null;
|
|
648
641
|
const refName = node.ref ? _kubb_core.ast.extractRefName(node.ref) ?? node.name : node.name;
|
|
649
642
|
const resolvedName = node.ref ? this.options.resolver?.default(refName, "function") ?? refName : node.name;
|
|
650
643
|
if (node.ref && this.options.cyclicSchemas?.has(refName)) return `z.lazy(() => ${resolvedName})`;
|
|
@@ -658,9 +651,10 @@ const printerZodMini = _kubb_core.ast.definePrinter((options) => {
|
|
|
658
651
|
const isOptional = schema.optional;
|
|
659
652
|
const isNullish = schema.nullish;
|
|
660
653
|
const hasSelfRef = this.options.cyclicSchemas != null && _kubb_core.ast.containsCircularRef(schema, { circularSchemas: this.options.cyclicSchemas });
|
|
654
|
+
const savedCyclicSchemas = this.options.cyclicSchemas;
|
|
661
655
|
if (hasSelfRef) this.options.cyclicSchemas = void 0;
|
|
662
656
|
const baseOutput = this.transform(schema) ?? this.transform(_kubb_core.ast.createSchema({ type: "unknown" }));
|
|
663
|
-
if (hasSelfRef) this.options.cyclicSchemas =
|
|
657
|
+
if (hasSelfRef) this.options.cyclicSchemas = savedCyclicSchemas;
|
|
664
658
|
const value = applyMiniModifiers({
|
|
665
659
|
value: this.options.wrapOutput ? this.options.wrapOutput({
|
|
666
660
|
output: baseOutput,
|
|
@@ -676,9 +670,8 @@ const printerZodMini = _kubb_core.ast.definePrinter((options) => {
|
|
|
676
670
|
}).join(",\n ")}\n })`;
|
|
677
671
|
},
|
|
678
672
|
array(node) {
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
return result;
|
|
673
|
+
const base = `z.array(${(node.items ?? []).map((item) => this.transform(item)).filter(Boolean).join(", ") || this.transform(_kubb_core.ast.createSchema({ type: "unknown" }))})${lengthChecksMini(node)}`;
|
|
674
|
+
return node.unique ? `${base}.refine(items => new Set(items).size === items.length, { message: "Array entries must be unique" })` : base;
|
|
682
675
|
},
|
|
683
676
|
tuple(node) {
|
|
684
677
|
return `z.tuple([${(node.items ?? []).map((item) => this.transform(item)).filter(Boolean).join(", ")}])`;
|
|
@@ -699,47 +692,29 @@ const printerZodMini = _kubb_core.ast.definePrinter((options) => {
|
|
|
699
692
|
if (members.length === 0) return "";
|
|
700
693
|
const [first, ...rest] = members;
|
|
701
694
|
if (!first) return "";
|
|
702
|
-
|
|
703
|
-
if (!
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
if (c) {
|
|
708
|
-
base += c;
|
|
709
|
-
continue;
|
|
710
|
-
}
|
|
711
|
-
} else if (member.primitive === "number" || member.primitive === "integer") {
|
|
712
|
-
const c = numberChecksMini(_kubb_core.ast.narrowSchema(member, "number") ?? _kubb_core.ast.narrowSchema(member, "integer") ?? {});
|
|
713
|
-
if (c) {
|
|
714
|
-
base += c;
|
|
715
|
-
continue;
|
|
716
|
-
}
|
|
717
|
-
} else if (member.primitive === "array") {
|
|
718
|
-
const c = lengthChecksMini(_kubb_core.ast.narrowSchema(member, "array") ?? {});
|
|
719
|
-
if (c) {
|
|
720
|
-
base += c;
|
|
721
|
-
continue;
|
|
722
|
-
}
|
|
723
|
-
}
|
|
695
|
+
const firstBase = this.transform(first);
|
|
696
|
+
if (!firstBase) return "";
|
|
697
|
+
return rest.reduce((acc, member) => {
|
|
698
|
+
const constraint = getMemberConstraintMini(member);
|
|
699
|
+
if (constraint) return acc + constraint;
|
|
724
700
|
const transformed = this.transform(member);
|
|
725
|
-
|
|
726
|
-
}
|
|
727
|
-
return base;
|
|
701
|
+
return transformed ? `z.intersection(${acc}, ${transformed})` : acc;
|
|
702
|
+
}, firstBase);
|
|
728
703
|
},
|
|
729
704
|
...options.nodes
|
|
730
705
|
},
|
|
731
706
|
print(node) {
|
|
732
707
|
const { keysToOmit } = this.options;
|
|
733
|
-
|
|
734
|
-
if (!
|
|
708
|
+
const transformed = this.transform(node);
|
|
709
|
+
if (!transformed) return null;
|
|
735
710
|
const meta = _kubb_core.ast.syncSchemaRef(node);
|
|
736
|
-
if (keysToOmit?.length && meta.primitive === "object" && !(meta.type === "union" && meta.discriminatorPropertyName)) {
|
|
737
|
-
const lazyMatch = base.match(/^z\.lazy\(\(\)\s*=>\s*(.+)\)$/);
|
|
738
|
-
if (lazyMatch) base = `z.lazy(() => ${lazyMatch[1]}.omit({ ${keysToOmit.map((k) => `"${k}": true`).join(", ")} }))`;
|
|
739
|
-
else base = `${base}.omit({ ${keysToOmit.map((k) => `"${k}": true`).join(", ")} })`;
|
|
740
|
-
}
|
|
741
711
|
return applyMiniModifiers({
|
|
742
|
-
value:
|
|
712
|
+
value: (() => {
|
|
713
|
+
if (!keysToOmit?.length || meta.primitive !== "object" || meta.type === "union" && meta.discriminatorPropertyName) return transformed;
|
|
714
|
+
const lazyMatch = transformed.match(/^z\.lazy\(\(\)\s*=>\s*(.+)\)$/);
|
|
715
|
+
if (lazyMatch) return `z.lazy(() => ${lazyMatch[1]}.omit({ ${keysToOmit.map((k) => `"${k}": true`).join(", ")} }))`;
|
|
716
|
+
return `${transformed}.omit({ ${keysToOmit.map((k) => `"${k}": true`).join(", ")} })`;
|
|
717
|
+
})(),
|
|
743
718
|
nullable: meta.nullable,
|
|
744
719
|
optional: meta.optional,
|
|
745
720
|
nullish: meta.nullish,
|
|
@@ -750,9 +725,11 @@ const printerZodMini = _kubb_core.ast.definePrinter((options) => {
|
|
|
750
725
|
});
|
|
751
726
|
//#endregion
|
|
752
727
|
//#region src/generators/zodGenerator.tsx
|
|
728
|
+
const zodPrinterCache = /* @__PURE__ */ new WeakMap();
|
|
729
|
+
const zodMiniPrinterCache = /* @__PURE__ */ new WeakMap();
|
|
753
730
|
const zodGenerator = (0, _kubb_core.defineGenerator)({
|
|
754
731
|
name: "zod",
|
|
755
|
-
renderer: _kubb_renderer_jsx.
|
|
732
|
+
renderer: _kubb_renderer_jsx.jsxRendererSync,
|
|
756
733
|
schema(node, ctx) {
|
|
757
734
|
const { adapter, config, resolver, root } = ctx;
|
|
758
735
|
const { output, coercion, guidType, mini, wrapOutput, inferred, importPath, group, printer } = ctx.options;
|
|
@@ -783,31 +760,53 @@ const zodGenerator = (0, _kubb_core.defineGenerator)({
|
|
|
783
760
|
})
|
|
784
761
|
};
|
|
785
762
|
const inferTypeName = inferred ? resolver.resolveSchemaTypeName(node.name) : void 0;
|
|
786
|
-
const cyclicSchemas =
|
|
787
|
-
const schemaPrinter = mini ?
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
763
|
+
const cyclicSchemas = new Set(ctx.meta.circularNames);
|
|
764
|
+
const schemaPrinter = mini ? getCachedMiniPrinter() : getCachedStdPrinter();
|
|
765
|
+
function getCachedStdPrinter() {
|
|
766
|
+
const cached = zodPrinterCache.get(resolver);
|
|
767
|
+
if (cached && cached.coercion === coercion && cached.guidType === guidType && cached.dateType === dateType) return cached.printer;
|
|
768
|
+
const p = printerZod({
|
|
769
|
+
coercion,
|
|
770
|
+
guidType,
|
|
771
|
+
dateType,
|
|
772
|
+
wrapOutput,
|
|
773
|
+
resolver,
|
|
774
|
+
cyclicSchemas,
|
|
775
|
+
nodes: printer?.nodes
|
|
776
|
+
});
|
|
777
|
+
zodPrinterCache.set(resolver, {
|
|
778
|
+
printer: p,
|
|
779
|
+
coercion,
|
|
780
|
+
guidType,
|
|
781
|
+
dateType
|
|
782
|
+
});
|
|
783
|
+
return p;
|
|
784
|
+
}
|
|
785
|
+
function getCachedMiniPrinter() {
|
|
786
|
+
const cached = zodMiniPrinterCache.get(resolver);
|
|
787
|
+
if (cached && cached.guidType === guidType) return cached.printer;
|
|
788
|
+
const p = printerZodMini({
|
|
789
|
+
guidType,
|
|
790
|
+
wrapOutput,
|
|
791
|
+
resolver,
|
|
792
|
+
cyclicSchemas,
|
|
793
|
+
nodes: printer?.nodes
|
|
794
|
+
});
|
|
795
|
+
zodMiniPrinterCache.set(resolver, {
|
|
796
|
+
printer: p,
|
|
797
|
+
guidType
|
|
798
|
+
});
|
|
799
|
+
return p;
|
|
800
|
+
}
|
|
802
801
|
return /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsxs)(_kubb_renderer_jsx.File, {
|
|
803
802
|
baseName: meta.file.baseName,
|
|
804
803
|
path: meta.file.path,
|
|
805
804
|
meta: meta.file.meta,
|
|
806
|
-
banner: resolver.resolveBanner(
|
|
805
|
+
banner: resolver.resolveBanner(ctx.meta, {
|
|
807
806
|
output,
|
|
808
807
|
config
|
|
809
808
|
}),
|
|
810
|
-
footer: resolver.resolveFooter(
|
|
809
|
+
footer: resolver.resolveFooter(ctx.meta, {
|
|
811
810
|
output,
|
|
812
811
|
config
|
|
813
812
|
}),
|
|
@@ -848,7 +847,7 @@ const zodGenerator = (0, _kubb_core.defineGenerator)({
|
|
|
848
847
|
output,
|
|
849
848
|
group
|
|
850
849
|
}) };
|
|
851
|
-
const cyclicSchemas =
|
|
850
|
+
const cyclicSchemas = new Set(ctx.meta.circularNames);
|
|
852
851
|
function renderSchemaEntry({ schema, name, keysToOmit }) {
|
|
853
852
|
if (!schema) return null;
|
|
854
853
|
const inferTypeName = inferred ? resolver.resolveTypeName(name) : void 0;
|
|
@@ -863,14 +862,22 @@ const zodGenerator = (0, _kubb_core.defineGenerator)({
|
|
|
863
862
|
group
|
|
864
863
|
}).path
|
|
865
864
|
}));
|
|
866
|
-
const
|
|
865
|
+
const cachedStd = zodPrinterCache.get(resolver);
|
|
866
|
+
const cachedMini = zodMiniPrinterCache.get(resolver);
|
|
867
|
+
const schemaPrinter = mini ? keysToOmit?.length ? printerZodMini({
|
|
867
868
|
guidType,
|
|
868
869
|
wrapOutput,
|
|
869
870
|
resolver,
|
|
870
871
|
keysToOmit,
|
|
871
872
|
cyclicSchemas,
|
|
872
873
|
nodes: printer?.nodes
|
|
873
|
-
}) :
|
|
874
|
+
}) : cachedMini?.guidType === guidType ? cachedMini.printer : printerZodMini({
|
|
875
|
+
guidType,
|
|
876
|
+
wrapOutput,
|
|
877
|
+
resolver,
|
|
878
|
+
cyclicSchemas,
|
|
879
|
+
nodes: printer?.nodes
|
|
880
|
+
}) : keysToOmit?.length ? printerZod({
|
|
874
881
|
coercion,
|
|
875
882
|
guidType,
|
|
876
883
|
dateType,
|
|
@@ -879,6 +886,14 @@ const zodGenerator = (0, _kubb_core.defineGenerator)({
|
|
|
879
886
|
keysToOmit,
|
|
880
887
|
cyclicSchemas,
|
|
881
888
|
nodes: printer?.nodes
|
|
889
|
+
}) : cachedStd?.coercion === coercion && cachedStd?.guidType === guidType && cachedStd?.dateType === dateType ? cachedStd.printer : printerZod({
|
|
890
|
+
coercion,
|
|
891
|
+
guidType,
|
|
892
|
+
dateType,
|
|
893
|
+
wrapOutput,
|
|
894
|
+
resolver,
|
|
895
|
+
cyclicSchemas,
|
|
896
|
+
nodes: printer?.nodes
|
|
882
897
|
});
|
|
883
898
|
return /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsxs)(_kubb_renderer_jsx_jsx_runtime.Fragment, { children: [mode === "split" && imports.map((imp) => /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Import, {
|
|
884
899
|
root: meta.file.path,
|
|
@@ -935,11 +950,11 @@ const zodGenerator = (0, _kubb_core.defineGenerator)({
|
|
|
935
950
|
baseName: meta.file.baseName,
|
|
936
951
|
path: meta.file.path,
|
|
937
952
|
meta: meta.file.meta,
|
|
938
|
-
banner: resolver.resolveBanner(
|
|
953
|
+
banner: resolver.resolveBanner(ctx.meta, {
|
|
939
954
|
output,
|
|
940
955
|
config
|
|
941
956
|
}),
|
|
942
|
-
footer: resolver.resolveFooter(
|
|
957
|
+
footer: resolver.resolveFooter(ctx.meta, {
|
|
943
958
|
output,
|
|
944
959
|
config
|
|
945
960
|
}),
|
|
@@ -957,7 +972,7 @@ const zodGenerator = (0, _kubb_core.defineGenerator)({
|
|
|
957
972
|
});
|
|
958
973
|
},
|
|
959
974
|
operations(nodes, ctx) {
|
|
960
|
-
const {
|
|
975
|
+
const { config, resolver, root } = ctx;
|
|
961
976
|
const { output, importPath, group, operations, paramsCasing } = ctx.options;
|
|
962
977
|
if (!operations) return;
|
|
963
978
|
const isZodImport = ZOD_NAMESPACE_IMPORTS.has(importPath);
|
|
@@ -1004,11 +1019,11 @@ const zodGenerator = (0, _kubb_core.defineGenerator)({
|
|
|
1004
1019
|
baseName: meta.file.baseName,
|
|
1005
1020
|
path: meta.file.path,
|
|
1006
1021
|
meta: meta.file.meta,
|
|
1007
|
-
banner: resolver.resolveBanner(
|
|
1022
|
+
banner: resolver.resolveBanner(ctx.meta, {
|
|
1008
1023
|
output,
|
|
1009
1024
|
config
|
|
1010
1025
|
}),
|
|
1011
|
-
footer: resolver.resolveFooter(
|
|
1026
|
+
footer: resolver.resolveFooter(ctx.meta, {
|
|
1012
1027
|
output,
|
|
1013
1028
|
config
|
|
1014
1029
|
}),
|