@kubb/plugin-zod 5.0.0-beta.80 → 5.0.0-beta.81
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 +136 -85
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +30 -36
- package/dist/index.js +136 -85
- package/dist/index.js.map +1 -1
- package/package.json +5 -5
package/dist/index.cjs
CHANGED
|
@@ -420,6 +420,46 @@ function collectCodecRefNames(node) {
|
|
|
420
420
|
return _kubb_core.ast.collect(node, { schema: (n) => n.type === "ref" && n.ref && containsCodec(n) ? (0, _kubb_ast_utils.extractRefName)(n.ref) ?? void 0 : void 0 });
|
|
421
421
|
}
|
|
422
422
|
/**
|
|
423
|
+
* Whether the node is a plain inline object whose shape can be lifted into an `.extend({ … })`
|
|
424
|
+
* argument. A catchall, `patternProperties`, or a nullable/optional wrapper cannot, so those stay
|
|
425
|
+
* on `.and(…)`.
|
|
426
|
+
*/
|
|
427
|
+
function isPlainInlineObject(node) {
|
|
428
|
+
return node.type === "object" && !node.nullable && !node.optional && !node.nullish && node.additionalProperties === void 0 && !node.patternProperties;
|
|
429
|
+
}
|
|
430
|
+
/**
|
|
431
|
+
* Whether a node renders as a bare Zod object — one that accepts `.extend(…)` and can be a
|
|
432
|
+
* `z.discriminatedUnion` option. Covers object nodes, `$ref`s that resolve to (or are still
|
|
433
|
+
* unresolved) objects, single-member unions of an object, and object-composable `allOf`.
|
|
434
|
+
*
|
|
435
|
+
* `cyclicSchemas` bounds the recursion: a ref into a cycle renders as `z.lazy(…)`, not an object.
|
|
436
|
+
*/
|
|
437
|
+
function isObjectSchemaNode(node, cyclicSchemas) {
|
|
438
|
+
if (node.nullable || node.optional || node.nullish) return false;
|
|
439
|
+
if (node.type === "object") return true;
|
|
440
|
+
if (node.type === "ref") {
|
|
441
|
+
const refName = (node.ref ? (0, _kubb_ast_utils.extractRefName)(node.ref) : void 0) ?? node.name;
|
|
442
|
+
if (refName && cyclicSchemas?.has(refName)) return false;
|
|
443
|
+
const resolved = (0, _kubb_ast_utils.syncSchemaRef)(node);
|
|
444
|
+
return resolved.type === "ref" || isObjectSchemaNode(resolved, cyclicSchemas);
|
|
445
|
+
}
|
|
446
|
+
if (node.type === "union") {
|
|
447
|
+
const members = node.members ?? [];
|
|
448
|
+
return members.length === 1 && isObjectSchemaNode(members[0], cyclicSchemas);
|
|
449
|
+
}
|
|
450
|
+
return isObjectComposableIntersection(node, cyclicSchemas);
|
|
451
|
+
}
|
|
452
|
+
/**
|
|
453
|
+
* Whether an `allOf` is a pure object composition — an object base plus inline object members whose
|
|
454
|
+
* shapes merge with `.extend(…)`. These stay a Zod object instead of a `ZodIntersection`, which
|
|
455
|
+
* `z.discriminatedUnion` rejects.
|
|
456
|
+
*/
|
|
457
|
+
function isObjectComposableIntersection(node, cyclicSchemas) {
|
|
458
|
+
if (node.type !== "intersection") return false;
|
|
459
|
+
const [first, ...rest] = node.members ?? [];
|
|
460
|
+
return !!first && isObjectSchemaNode(first, cyclicSchemas) && rest.every(isPlainInlineObject);
|
|
461
|
+
}
|
|
462
|
+
/**
|
|
423
463
|
* Format a default value as a code-level literal.
|
|
424
464
|
* Objects become `{}`, primitives become their string representation, strings are quoted.
|
|
425
465
|
*/
|
|
@@ -627,6 +667,41 @@ function getMemberConstraint({ member, regexType }) {
|
|
|
627
667
|
}) || void 0;
|
|
628
668
|
}
|
|
629
669
|
/**
|
|
670
|
+
* Builds the `{ key: value, … }` shape for an object node, shared by the `z.object(...)` and
|
|
671
|
+
* `.extend(...)` renderings so they stay in lockstep.
|
|
672
|
+
*/
|
|
673
|
+
function buildZodObjectShape(ctx, node) {
|
|
674
|
+
const objectNode = _kubb_core.ast.narrowSchema(node, "object");
|
|
675
|
+
if (!objectNode) return "{}";
|
|
676
|
+
const isCyclic = (schema) => ctx.options.cyclicSchemas != null && (0, _kubb_ast_utils.containsCircularRef)(schema, { circularSchemas: ctx.options.cyclicSchemas });
|
|
677
|
+
return (0, _kubb_ast_utils.buildObject)((0, _kubb_ast_utils.mapSchemaProperties)(objectNode, (schema) => {
|
|
678
|
+
const hasSelfRef = isCyclic(schema);
|
|
679
|
+
const savedCyclicSchemas = ctx.options.cyclicSchemas;
|
|
680
|
+
if (hasSelfRef) ctx.options.cyclicSchemas = void 0;
|
|
681
|
+
const baseOutput = ctx.transform(schema) ?? ctx.transform(_kubb_core.ast.factory.createSchema({ type: "unknown" }));
|
|
682
|
+
if (hasSelfRef) ctx.options.cyclicSchemas = savedCyclicSchemas;
|
|
683
|
+
return baseOutput;
|
|
684
|
+
}).map(({ name: propName, property, output: baseOutput }) => {
|
|
685
|
+
const { schema } = property;
|
|
686
|
+
const meta = (0, _kubb_ast_utils.syncSchemaRef)(schema);
|
|
687
|
+
const descriptionToApply = schema.type !== "ref" && meta.type === "ref" ? void 0 : meta.description;
|
|
688
|
+
const value = applyModifiers({
|
|
689
|
+
value: baseOutput,
|
|
690
|
+
schema,
|
|
691
|
+
nullable: meta.nullable,
|
|
692
|
+
optional: schema.optional || property.required === false,
|
|
693
|
+
nullish: schema.nullish,
|
|
694
|
+
defaultValue: meta.default,
|
|
695
|
+
description: descriptionToApply,
|
|
696
|
+
examples: meta.examples
|
|
697
|
+
});
|
|
698
|
+
return isCyclic(schema) ? (0, _kubb_ast_utils.lazyGetter)({
|
|
699
|
+
name: propName,
|
|
700
|
+
body: value
|
|
701
|
+
}) : `${(0, _kubb_ast_utils.objectKey)(propName)}: ${value}`;
|
|
702
|
+
}));
|
|
703
|
+
}
|
|
704
|
+
/**
|
|
630
705
|
* Zod v4 printer built with `definePrinter`.
|
|
631
706
|
*
|
|
632
707
|
* Converts a `SchemaNode` AST into a Zod v4 code string using the chainable API
|
|
@@ -667,7 +742,10 @@ const printerZod = _kubb_core.ast.createPrinter((options) => {
|
|
|
667
742
|
},
|
|
668
743
|
date(node) {
|
|
669
744
|
const codec = getCodec(node);
|
|
670
|
-
if (codec)
|
|
745
|
+
if (codec) {
|
|
746
|
+
if (this.options.direction === "input") return codec.encode(node);
|
|
747
|
+
return shouldCoerce(this.options.coercion, "dates") ? "z.coerce.date()" : codec.decode(node);
|
|
748
|
+
}
|
|
671
749
|
return "z.iso.date()";
|
|
672
750
|
},
|
|
673
751
|
datetime(node) {
|
|
@@ -720,38 +798,8 @@ const printerZod = _kubb_core.ast.createPrinter((options) => {
|
|
|
720
798
|
return resolvedName;
|
|
721
799
|
},
|
|
722
800
|
object(node) {
|
|
723
|
-
const
|
|
724
|
-
const
|
|
725
|
-
const hasSelfRef = isCyclic(schema);
|
|
726
|
-
const savedCyclicSchemas = this.options.cyclicSchemas;
|
|
727
|
-
if (hasSelfRef) this.options.cyclicSchemas = void 0;
|
|
728
|
-
const baseOutput = this.transform(schema) ?? this.transform(_kubb_core.ast.factory.createSchema({ type: "unknown" }));
|
|
729
|
-
if (hasSelfRef) this.options.cyclicSchemas = savedCyclicSchemas;
|
|
730
|
-
return baseOutput;
|
|
731
|
-
}).map(({ name: propName, property, output: baseOutput }) => {
|
|
732
|
-
const { schema } = property;
|
|
733
|
-
const meta = (0, _kubb_ast_utils.syncSchemaRef)(schema);
|
|
734
|
-
const wrappedOutput = this.options.wrapOutput ? this.options.wrapOutput({
|
|
735
|
-
output: baseOutput,
|
|
736
|
-
schema
|
|
737
|
-
}) || baseOutput : baseOutput;
|
|
738
|
-
const descriptionToApply = schema.type !== "ref" && meta.type === "ref" ? void 0 : meta.description;
|
|
739
|
-
const value = applyModifiers({
|
|
740
|
-
value: wrappedOutput,
|
|
741
|
-
schema,
|
|
742
|
-
nullable: meta.nullable,
|
|
743
|
-
optional: schema.optional || property.required === false,
|
|
744
|
-
nullish: schema.nullish,
|
|
745
|
-
defaultValue: meta.default,
|
|
746
|
-
description: descriptionToApply,
|
|
747
|
-
examples: meta.examples
|
|
748
|
-
});
|
|
749
|
-
return isCyclic(schema) ? (0, _kubb_ast_utils.lazyGetter)({
|
|
750
|
-
name: propName,
|
|
751
|
-
body: value
|
|
752
|
-
}) : `${(0, _kubb_ast_utils.objectKey)(propName)}: ${value}`;
|
|
753
|
-
});
|
|
754
|
-
const objectBase = `z.object(${(0, _kubb_ast_utils.buildObject)(entries)})`;
|
|
801
|
+
const entries = node.properties ?? [];
|
|
802
|
+
const objectBase = `z.object(${buildZodObjectShape(this, node)})`;
|
|
755
803
|
return (() => {
|
|
756
804
|
const patterns = node.patternProperties ? Object.entries(node.patternProperties) : [];
|
|
757
805
|
if (node.additionalProperties && node.additionalProperties !== true) {
|
|
@@ -791,7 +839,7 @@ const printerZod = _kubb_core.ast.createPrinter((options) => {
|
|
|
791
839
|
const members = (0, _kubb_ast_utils.mapSchemaMembers)(node, (memberNode) => this.transform(memberNode)).map(({ schema, output }) => output && node.strategy === "one" ? strictOneOfMember$1(output, schema, cyclicSchemaNames) : output).filter(Boolean);
|
|
792
840
|
if (members.length === 0) return "";
|
|
793
841
|
if (members.length === 1) return members[0];
|
|
794
|
-
const allDiscriminable = nodeMembers.every((m) => (m
|
|
842
|
+
const allDiscriminable = nodeMembers.every((m) => isObjectSchemaNode(m, cyclicSchemaNames));
|
|
795
843
|
if (node.discriminatorPropertyName && allDiscriminable) return `z.discriminatedUnion(${(0, _kubb_ast_utils.stringify)(node.discriminatorPropertyName)}, ${(0, _kubb_ast_utils.buildList)(members)})`;
|
|
796
844
|
return `z.union(${(0, _kubb_ast_utils.buildList)(members)})`;
|
|
797
845
|
},
|
|
@@ -802,6 +850,7 @@ const printerZod = _kubb_core.ast.createPrinter((options) => {
|
|
|
802
850
|
if (!first) return "";
|
|
803
851
|
const firstBase = this.transform(first);
|
|
804
852
|
if (!firstBase) return "";
|
|
853
|
+
if (rest.length > 0 && isObjectComposableIntersection(node, cyclicSchemaNames)) return rest.reduce((acc, member) => `${acc}.extend(${buildZodObjectShape(this, member)})`, firstBase);
|
|
805
854
|
return rest.reduce((acc, member) => {
|
|
806
855
|
const constraint = getMemberConstraint({
|
|
807
856
|
member,
|
|
@@ -811,9 +860,9 @@ const printerZod = _kubb_core.ast.createPrinter((options) => {
|
|
|
811
860
|
const transformed = this.transform(member);
|
|
812
861
|
return transformed ? `${acc}.and(${transformed})` : acc;
|
|
813
862
|
}, firstBase);
|
|
814
|
-
}
|
|
815
|
-
...options.nodes
|
|
863
|
+
}
|
|
816
864
|
},
|
|
865
|
+
overrides: options.nodes,
|
|
817
866
|
print(node) {
|
|
818
867
|
const { keysToOmit } = this.options;
|
|
819
868
|
const transformed = this.transform(node);
|
|
@@ -857,7 +906,39 @@ function getMemberConstraintMini({ member, regexType }) {
|
|
|
857
906
|
}) || void 0;
|
|
858
907
|
}
|
|
859
908
|
/**
|
|
860
|
-
*
|
|
909
|
+
* Builds the `{ key: value, … }` shape for an object node with the functional `zod/mini` modifiers,
|
|
910
|
+
* shared by the `z.object(...)` and `z.extend(...)` renderings so they stay in lockstep.
|
|
911
|
+
*/
|
|
912
|
+
function buildZodMiniObjectShape(ctx, node) {
|
|
913
|
+
const objectNode = _kubb_core.ast.narrowSchema(node, "object");
|
|
914
|
+
if (!objectNode) return "{}";
|
|
915
|
+
const isCyclic = (schema) => ctx.options.cyclicSchemas != null && (0, _kubb_ast_utils.containsCircularRef)(schema, { circularSchemas: ctx.options.cyclicSchemas });
|
|
916
|
+
return (0, _kubb_ast_utils.buildObject)((0, _kubb_ast_utils.mapSchemaProperties)(objectNode, (schema) => {
|
|
917
|
+
const hasSelfRef = isCyclic(schema);
|
|
918
|
+
const savedCyclicSchemas = ctx.options.cyclicSchemas;
|
|
919
|
+
if (hasSelfRef) ctx.options.cyclicSchemas = void 0;
|
|
920
|
+
const baseOutput = ctx.transform(schema) ?? ctx.transform(_kubb_core.ast.factory.createSchema({ type: "unknown" }));
|
|
921
|
+
if (hasSelfRef) ctx.options.cyclicSchemas = savedCyclicSchemas;
|
|
922
|
+
return baseOutput;
|
|
923
|
+
}).map(({ name: propName, property, output: baseOutput }) => {
|
|
924
|
+
const { schema } = property;
|
|
925
|
+
const meta = (0, _kubb_ast_utils.syncSchemaRef)(schema);
|
|
926
|
+
const value = applyMiniModifiers({
|
|
927
|
+
value: baseOutput,
|
|
928
|
+
schema,
|
|
929
|
+
nullable: meta.nullable,
|
|
930
|
+
optional: schema.optional || property.required === false,
|
|
931
|
+
nullish: schema.nullish,
|
|
932
|
+
defaultValue: meta.default
|
|
933
|
+
});
|
|
934
|
+
return isCyclic(schema) ? (0, _kubb_ast_utils.lazyGetter)({
|
|
935
|
+
name: propName,
|
|
936
|
+
body: value
|
|
937
|
+
}) : `${(0, _kubb_ast_utils.objectKey)(propName)}: ${value}`;
|
|
938
|
+
}));
|
|
939
|
+
}
|
|
940
|
+
/**
|
|
941
|
+
* Zod v4 Mini printer built with `definePrinter`.
|
|
861
942
|
*
|
|
862
943
|
* Converts a `SchemaNode` AST into a Zod v4 code string using the functional API
|
|
863
944
|
* (`z.optional(z.string())`) for improved tree-shaking. See {@link printerZod} for the chainable API.
|
|
@@ -869,6 +950,7 @@ function getMemberConstraintMini({ member, regexType }) {
|
|
|
869
950
|
* ```
|
|
870
951
|
*/
|
|
871
952
|
const printerZodMini = _kubb_core.ast.createPrinter((options) => {
|
|
953
|
+
const cyclicSchemaNames = options.cyclicSchemas;
|
|
872
954
|
return {
|
|
873
955
|
name: "zod-mini",
|
|
874
956
|
options,
|
|
@@ -943,34 +1025,8 @@ const printerZodMini = _kubb_core.ast.createPrinter((options) => {
|
|
|
943
1025
|
return resolvedName;
|
|
944
1026
|
},
|
|
945
1027
|
object(node) {
|
|
946
|
-
const
|
|
947
|
-
const
|
|
948
|
-
const hasSelfRef = isCyclic(schema);
|
|
949
|
-
const savedCyclicSchemas = this.options.cyclicSchemas;
|
|
950
|
-
if (hasSelfRef) this.options.cyclicSchemas = void 0;
|
|
951
|
-
const baseOutput = this.transform(schema) ?? this.transform(_kubb_core.ast.factory.createSchema({ type: "unknown" }));
|
|
952
|
-
if (hasSelfRef) this.options.cyclicSchemas = savedCyclicSchemas;
|
|
953
|
-
return baseOutput;
|
|
954
|
-
}).map(({ name: propName, property, output: baseOutput }) => {
|
|
955
|
-
const { schema } = property;
|
|
956
|
-
const meta = (0, _kubb_ast_utils.syncSchemaRef)(schema);
|
|
957
|
-
const value = applyMiniModifiers({
|
|
958
|
-
value: this.options.wrapOutput ? this.options.wrapOutput({
|
|
959
|
-
output: baseOutput,
|
|
960
|
-
schema
|
|
961
|
-
}) || baseOutput : baseOutput,
|
|
962
|
-
schema,
|
|
963
|
-
nullable: meta.nullable,
|
|
964
|
-
optional: schema.optional || property.required === false,
|
|
965
|
-
nullish: schema.nullish,
|
|
966
|
-
defaultValue: meta.default
|
|
967
|
-
});
|
|
968
|
-
return isCyclic(schema) ? (0, _kubb_ast_utils.lazyGetter)({
|
|
969
|
-
name: propName,
|
|
970
|
-
body: value
|
|
971
|
-
}) : `${(0, _kubb_ast_utils.objectKey)(propName)}: ${value}`;
|
|
972
|
-
});
|
|
973
|
-
const objectBase = `z.object(${(0, _kubb_ast_utils.buildObject)(entries)})`;
|
|
1028
|
+
const entries = node.properties ?? [];
|
|
1029
|
+
const objectBase = `z.object(${buildZodMiniObjectShape(this, node)})`;
|
|
974
1030
|
const patterns = node.patternProperties ? Object.entries(node.patternProperties) : [];
|
|
975
1031
|
if (node.additionalProperties && node.additionalProperties !== true) {
|
|
976
1032
|
const catchallType = this.transform(node.additionalProperties);
|
|
@@ -1008,7 +1064,7 @@ const printerZodMini = _kubb_core.ast.createPrinter((options) => {
|
|
|
1008
1064
|
const members = (0, _kubb_ast_utils.mapSchemaMembers)(node, (memberNode) => this.transform(memberNode)).map(({ schema, output }) => output && node.strategy === "one" ? strictOneOfMember(output, schema) : output).filter(Boolean);
|
|
1009
1065
|
if (members.length === 0) return "";
|
|
1010
1066
|
if (members.length === 1) return members[0];
|
|
1011
|
-
const allDiscriminable = nodeMembers.every((m) => (m
|
|
1067
|
+
const allDiscriminable = nodeMembers.every((m) => isObjectSchemaNode(m, cyclicSchemaNames));
|
|
1012
1068
|
if (node.discriminatorPropertyName && allDiscriminable) return `z.discriminatedUnion(${(0, _kubb_ast_utils.stringify)(node.discriminatorPropertyName)}, ${(0, _kubb_ast_utils.buildList)(members)})`;
|
|
1013
1069
|
return `z.union(${(0, _kubb_ast_utils.buildList)(members)})`;
|
|
1014
1070
|
},
|
|
@@ -1019,6 +1075,7 @@ const printerZodMini = _kubb_core.ast.createPrinter((options) => {
|
|
|
1019
1075
|
if (!first) return "";
|
|
1020
1076
|
const firstBase = this.transform(first);
|
|
1021
1077
|
if (!firstBase) return "";
|
|
1078
|
+
if (rest.length > 0 && isObjectComposableIntersection(node, cyclicSchemaNames)) return rest.reduce((acc, member) => `z.extend(${acc}, ${buildZodMiniObjectShape(this, member)})`, firstBase);
|
|
1022
1079
|
return rest.reduce((acc, member) => {
|
|
1023
1080
|
const constraint = getMemberConstraintMini({
|
|
1024
1081
|
member,
|
|
@@ -1028,9 +1085,9 @@ const printerZodMini = _kubb_core.ast.createPrinter((options) => {
|
|
|
1028
1085
|
const transformed = this.transform(member);
|
|
1029
1086
|
return transformed ? `z.intersection(${acc}, ${transformed})` : acc;
|
|
1030
1087
|
}, firstBase);
|
|
1031
|
-
}
|
|
1032
|
-
...options.nodes
|
|
1088
|
+
}
|
|
1033
1089
|
},
|
|
1090
|
+
overrides: options.nodes,
|
|
1034
1091
|
print(node) {
|
|
1035
1092
|
const { keysToOmit } = this.options;
|
|
1036
1093
|
const transformed = this.transform(node);
|
|
@@ -1060,12 +1117,12 @@ const zodPrinterCache = /* @__PURE__ */ new WeakMap();
|
|
|
1060
1117
|
const zodMiniPrinterCache = /* @__PURE__ */ new WeakMap();
|
|
1061
1118
|
/**
|
|
1062
1119
|
* Returns the cached `output`/`input` direction printers for a resolver, building them on
|
|
1063
|
-
* first use. The `input` printer encodes `Date → string` for request bodies
|
|
1120
|
+
* first use. The `input` printer encodes `Date → string` for request bodies, and `output` decodes
|
|
1064
1121
|
* `string → Date` for responses. Schemas without `dateType: 'date'` fields print identically.
|
|
1065
1122
|
*/
|
|
1066
1123
|
function getStdPrinters(resolver, params) {
|
|
1067
1124
|
const cached = zodPrinterCache.get(resolver);
|
|
1068
|
-
if (cached && cached.coercion === params.coercion && cached.guidType === params.guidType && cached.regexType === params.regexType && cached.dateType === params.dateType) return {
|
|
1125
|
+
if (cached && cached.coercion === params.coercion && cached.guidType === params.guidType && cached.regexType === params.regexType && cached.dateType === params.dateType && cached.nodes === params.nodes) return {
|
|
1069
1126
|
output: cached.output,
|
|
1070
1127
|
input: cached.input
|
|
1071
1128
|
};
|
|
@@ -1087,7 +1144,8 @@ function getStdPrinters(resolver, params) {
|
|
|
1087
1144
|
coercion: params.coercion,
|
|
1088
1145
|
guidType: params.guidType,
|
|
1089
1146
|
regexType: params.regexType,
|
|
1090
|
-
dateType: params.dateType
|
|
1147
|
+
dateType: params.dateType,
|
|
1148
|
+
nodes: params.nodes
|
|
1091
1149
|
});
|
|
1092
1150
|
return {
|
|
1093
1151
|
output,
|
|
@@ -1096,7 +1154,7 @@ function getStdPrinters(resolver, params) {
|
|
|
1096
1154
|
}
|
|
1097
1155
|
function getMiniPrinter(resolver, params) {
|
|
1098
1156
|
const cached = zodMiniPrinterCache.get(resolver);
|
|
1099
|
-
if (cached && cached.guidType === params.guidType && cached.regexType === params.regexType) return cached.printer;
|
|
1157
|
+
if (cached && cached.guidType === params.guidType && cached.regexType === params.regexType && cached.nodes === params.nodes) return cached.printer;
|
|
1100
1158
|
const p = printerZodMini({
|
|
1101
1159
|
...params,
|
|
1102
1160
|
resolver
|
|
@@ -1104,7 +1162,8 @@ function getMiniPrinter(resolver, params) {
|
|
|
1104
1162
|
zodMiniPrinterCache.set(resolver, {
|
|
1105
1163
|
printer: p,
|
|
1106
1164
|
guidType: params.guidType,
|
|
1107
|
-
regexType: params.regexType
|
|
1165
|
+
regexType: params.regexType,
|
|
1166
|
+
nodes: params.nodes
|
|
1108
1167
|
});
|
|
1109
1168
|
return p;
|
|
1110
1169
|
}
|
|
@@ -1119,7 +1178,7 @@ const zodGenerator = (0, _kubb_core.defineGenerator)({
|
|
|
1119
1178
|
renderer: _kubb_renderer_jsx.jsxRenderer,
|
|
1120
1179
|
schema(node, ctx) {
|
|
1121
1180
|
const { adapter, config, resolver, root } = ctx;
|
|
1122
|
-
const { output, coercion, guidType, regexType, mini,
|
|
1181
|
+
const { output, coercion, guidType, regexType, mini, inferred, importPath, group, printer } = ctx.options;
|
|
1123
1182
|
const dateType = adapter.options.dateType;
|
|
1124
1183
|
if (!node.name) return;
|
|
1125
1184
|
const isZodImport = ZOD_NAMESPACE_IMPORTS.has(importPath);
|
|
@@ -1173,7 +1232,6 @@ const zodGenerator = (0, _kubb_core.defineGenerator)({
|
|
|
1173
1232
|
guidType,
|
|
1174
1233
|
regexType,
|
|
1175
1234
|
dateType,
|
|
1176
|
-
wrapOutput,
|
|
1177
1235
|
cyclicSchemas,
|
|
1178
1236
|
nameMapping,
|
|
1179
1237
|
nodes: printer?.nodes
|
|
@@ -1181,7 +1239,6 @@ const zodGenerator = (0, _kubb_core.defineGenerator)({
|
|
|
1181
1239
|
const schemaPrinter = mini ? getMiniPrinter(resolver, {
|
|
1182
1240
|
guidType,
|
|
1183
1241
|
regexType,
|
|
1184
|
-
wrapOutput,
|
|
1185
1242
|
cyclicSchemas,
|
|
1186
1243
|
nameMapping,
|
|
1187
1244
|
nodes: printer?.nodes
|
|
@@ -1241,7 +1298,7 @@ const zodGenerator = (0, _kubb_core.defineGenerator)({
|
|
|
1241
1298
|
operation(node, ctx) {
|
|
1242
1299
|
if (!_kubb_core.ast.isHttpOperationNode(node)) return null;
|
|
1243
1300
|
const { adapter, config, resolver, root } = ctx;
|
|
1244
|
-
const { output, coercion, guidType, regexType, mini,
|
|
1301
|
+
const { output, coercion, guidType, regexType, mini, inferred, importPath, group, printer } = ctx.options;
|
|
1245
1302
|
const dateType = adapter.options.dateType;
|
|
1246
1303
|
const isZodImport = ZOD_NAMESPACE_IMPORTS.has(importPath);
|
|
1247
1304
|
const params = caseParams(node.parameters, "camelcase");
|
|
@@ -1275,7 +1332,6 @@ const zodGenerator = (0, _kubb_core.defineGenerator)({
|
|
|
1275
1332
|
const schemaPrinter = mini ? keysToOmit?.length ? printerZodMini({
|
|
1276
1333
|
guidType,
|
|
1277
1334
|
regexType,
|
|
1278
|
-
wrapOutput,
|
|
1279
1335
|
resolver,
|
|
1280
1336
|
keysToOmit,
|
|
1281
1337
|
cyclicSchemas,
|
|
@@ -1284,7 +1340,6 @@ const zodGenerator = (0, _kubb_core.defineGenerator)({
|
|
|
1284
1340
|
}) : getMiniPrinter(resolver, {
|
|
1285
1341
|
guidType,
|
|
1286
1342
|
regexType,
|
|
1287
|
-
wrapOutput,
|
|
1288
1343
|
cyclicSchemas,
|
|
1289
1344
|
nameMapping,
|
|
1290
1345
|
nodes: printer?.nodes
|
|
@@ -1293,7 +1348,6 @@ const zodGenerator = (0, _kubb_core.defineGenerator)({
|
|
|
1293
1348
|
guidType,
|
|
1294
1349
|
regexType,
|
|
1295
1350
|
dateType,
|
|
1296
|
-
wrapOutput,
|
|
1297
1351
|
resolver,
|
|
1298
1352
|
keysToOmit,
|
|
1299
1353
|
cyclicSchemas,
|
|
@@ -1305,7 +1359,6 @@ const zodGenerator = (0, _kubb_core.defineGenerator)({
|
|
|
1305
1359
|
guidType,
|
|
1306
1360
|
regexType,
|
|
1307
1361
|
dateType,
|
|
1308
|
-
wrapOutput,
|
|
1309
1362
|
cyclicSchemas,
|
|
1310
1363
|
nameMapping,
|
|
1311
1364
|
nodes: printer?.nodes
|
|
@@ -1559,7 +1612,7 @@ const pluginZodName = "plugin-zod";
|
|
|
1559
1612
|
* pluginTs(),
|
|
1560
1613
|
* pluginZod({
|
|
1561
1614
|
* output: { path: './zod' },
|
|
1562
|
-
*
|
|
1615
|
+
* inferred: true,
|
|
1563
1616
|
* }),
|
|
1564
1617
|
* ],
|
|
1565
1618
|
* })
|
|
@@ -1569,7 +1622,7 @@ const pluginZod = (0, _kubb_core.definePlugin)((options) => {
|
|
|
1569
1622
|
const { output = {
|
|
1570
1623
|
path: "zod",
|
|
1571
1624
|
barrel: { type: "named" }
|
|
1572
|
-
}, group, exclude = [], include, override = [],
|
|
1625
|
+
}, group, exclude = [], include, override = [], mini = false, guidType = "uuid", regexType = "literal", importPath = mini ? "zod/mini" : "zod", coercion = false, inferred = false, printer, resolver: userResolver, macros: userMacros } = options;
|
|
1573
1626
|
const groupConfig = createGroupConfig(group);
|
|
1574
1627
|
return {
|
|
1575
1628
|
name: pluginZodName,
|
|
@@ -1581,14 +1634,12 @@ const pluginZod = (0, _kubb_core.definePlugin)((options) => {
|
|
|
1581
1634
|
include,
|
|
1582
1635
|
override,
|
|
1583
1636
|
group: groupConfig,
|
|
1584
|
-
typed,
|
|
1585
1637
|
importPath,
|
|
1586
1638
|
coercion,
|
|
1587
1639
|
inferred,
|
|
1588
1640
|
guidType,
|
|
1589
1641
|
regexType,
|
|
1590
1642
|
mini,
|
|
1591
|
-
wrapOutput,
|
|
1592
1643
|
printer
|
|
1593
1644
|
});
|
|
1594
1645
|
ctx.setResolver(userResolver ? {
|