@kubb/plugin-zod 5.8.0-canary.20261029T124214 → 5.8.1
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 +167 -121
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +51 -5
- package/dist/index.js.map +1 -1
- package/docs/options.md +2 -0
- package/package.json +7 -5
package/dist/index.cjs
CHANGED
|
@@ -2,9 +2,9 @@ Object.defineProperties(exports, {
|
|
|
2
2
|
__esModule: { value: true },
|
|
3
3
|
[Symbol.toStringTag]: { value: "Module" }
|
|
4
4
|
});
|
|
5
|
-
let
|
|
6
|
-
let
|
|
7
|
-
let
|
|
5
|
+
let _kubb_kit = require("@kubb/kit");
|
|
6
|
+
let _kubb_renderer_jsx = require("@kubb/renderer-jsx");
|
|
7
|
+
let _kubb_renderer_jsx_jsx_runtime = require("@kubb/renderer-jsx/jsx-runtime");
|
|
8
8
|
// ../../internals/shared/src/operation.ts
|
|
9
9
|
/**
|
|
10
10
|
* Maps a content type to the PascalCase suffix used to name per-content-type variants
|
|
@@ -94,7 +94,7 @@ function hasRequestContentTypeChoice(node) {
|
|
|
94
94
|
function buildOptionsSchema(node, resolver, { pairContentTypes = false } = {}) {
|
|
95
95
|
const { path, query, header } = getOperationParameters(node);
|
|
96
96
|
const hasBody = Boolean(node.requestBody?.content?.[0]?.schema);
|
|
97
|
-
const createNever = () =>
|
|
97
|
+
const createNever = () => _kubb_kit.ast.factory.createSchema({
|
|
98
98
|
type: "never",
|
|
99
99
|
primitive: void 0,
|
|
100
100
|
optional: true
|
|
@@ -116,22 +116,22 @@ function buildOptionsSchema(node, resolver, { pairContentTypes = false } = {}) {
|
|
|
116
116
|
resolve: resolver.param.headers
|
|
117
117
|
}
|
|
118
118
|
];
|
|
119
|
-
const createOptions = (body, extra = []) =>
|
|
119
|
+
const createOptions = (body, extra = []) => _kubb_kit.ast.factory.createSchema({
|
|
120
120
|
type: "object",
|
|
121
121
|
primitive: "object",
|
|
122
122
|
deprecated: node.deprecated,
|
|
123
123
|
properties: [
|
|
124
|
-
|
|
124
|
+
_kubb_kit.ast.factory.createProperty({
|
|
125
125
|
name: "body",
|
|
126
126
|
required: hasBody,
|
|
127
127
|
schema: body
|
|
128
128
|
}),
|
|
129
129
|
...groups.map(({ name, params, resolve }) => {
|
|
130
130
|
const required = params.some((param) => param.required);
|
|
131
|
-
return
|
|
131
|
+
return _kubb_kit.ast.factory.createProperty({
|
|
132
132
|
name,
|
|
133
133
|
required,
|
|
134
|
-
schema: params.length > 0 ?
|
|
134
|
+
schema: params.length > 0 ? _kubb_kit.ast.factory.createSchema({
|
|
135
135
|
type: "ref",
|
|
136
136
|
name: resolve.call(resolver.param, node, params[0]),
|
|
137
137
|
optional: !required
|
|
@@ -142,25 +142,25 @@ function buildOptionsSchema(node, resolver, { pairContentTypes = false } = {}) {
|
|
|
142
142
|
]
|
|
143
143
|
});
|
|
144
144
|
const variants = pairContentTypes && hasRequestContentTypeChoice(node) ? resolveContentTypeVariants(node.requestBody?.content ?? [], resolver.response.body(node)) : [];
|
|
145
|
-
if (variants.length < 2) return createOptions(hasBody ?
|
|
145
|
+
if (variants.length < 2) return createOptions(hasBody ? _kubb_kit.ast.factory.createSchema({
|
|
146
146
|
type: "ref",
|
|
147
147
|
name: resolver.response.body(node)
|
|
148
148
|
}) : createNever());
|
|
149
|
-
return
|
|
149
|
+
return _kubb_kit.ast.factory.createSchema({
|
|
150
150
|
type: "union",
|
|
151
|
-
members: variants.map((variant, index) => createOptions(
|
|
151
|
+
members: variants.map((variant, index) => createOptions(_kubb_kit.ast.factory.createSchema({
|
|
152
152
|
type: "ref",
|
|
153
153
|
name: variant.name
|
|
154
|
-
}), [
|
|
154
|
+
}), [_kubb_kit.ast.factory.createProperty({
|
|
155
155
|
name: "contentType",
|
|
156
156
|
required: index > 0,
|
|
157
|
-
schema:
|
|
157
|
+
schema: _kubb_kit.ast.factory.createSchema({
|
|
158
158
|
type: "object",
|
|
159
159
|
primitive: "object",
|
|
160
|
-
properties: [
|
|
160
|
+
properties: [_kubb_kit.ast.factory.createProperty({
|
|
161
161
|
name: "request",
|
|
162
162
|
required: true,
|
|
163
|
-
schema:
|
|
163
|
+
schema: _kubb_kit.ast.factory.createSchema({
|
|
164
164
|
type: "enum",
|
|
165
165
|
enumValues: [variant.contentType]
|
|
166
166
|
})
|
|
@@ -178,26 +178,26 @@ function buildOptionsSchema(node, resolver, { pairContentTypes = false } = {}) {
|
|
|
178
178
|
function buildResponseRecordEntry(node, res, resolver) {
|
|
179
179
|
const statusName = resolver.response.status(node, res.statusCode);
|
|
180
180
|
const variants = (res.content ?? []).filter((entry) => entry.schema);
|
|
181
|
-
if (variants.length <= 1) return
|
|
181
|
+
if (variants.length <= 1) return _kubb_kit.ast.factory.createSchema({
|
|
182
182
|
type: "ref",
|
|
183
183
|
name: statusName
|
|
184
184
|
});
|
|
185
|
-
return
|
|
185
|
+
return _kubb_kit.ast.factory.createSchema({
|
|
186
186
|
type: "union",
|
|
187
|
-
members: resolveContentTypeVariants(variants, statusName).map((variant) =>
|
|
187
|
+
members: resolveContentTypeVariants(variants, statusName).map((variant) => _kubb_kit.ast.factory.createSchema({
|
|
188
188
|
type: "object",
|
|
189
189
|
primitive: "object",
|
|
190
|
-
properties: [
|
|
190
|
+
properties: [_kubb_kit.ast.factory.createProperty({
|
|
191
191
|
name: "contentType",
|
|
192
192
|
required: true,
|
|
193
|
-
schema:
|
|
193
|
+
schema: _kubb_kit.ast.factory.createSchema({
|
|
194
194
|
type: "enum",
|
|
195
195
|
enumValues: [variant.contentType]
|
|
196
196
|
})
|
|
197
|
-
}),
|
|
197
|
+
}), _kubb_kit.ast.factory.createProperty({
|
|
198
198
|
name: "data",
|
|
199
199
|
required: true,
|
|
200
|
-
schema:
|
|
200
|
+
schema: _kubb_kit.ast.factory.createSchema({
|
|
201
201
|
type: "ref",
|
|
202
202
|
name: variant.name
|
|
203
203
|
})
|
|
@@ -215,10 +215,10 @@ function buildResponseRecordEntry(node, res, resolver) {
|
|
|
215
215
|
* SDK's `RequestResult<XResponses>`) resolvable instead of pointing at a missing export.
|
|
216
216
|
*/
|
|
217
217
|
function buildResponses(node, resolver) {
|
|
218
|
-
return
|
|
218
|
+
return _kubb_kit.ast.factory.createSchema({
|
|
219
219
|
type: "object",
|
|
220
220
|
primitive: "object",
|
|
221
|
-
properties: node.responses.map((res) =>
|
|
221
|
+
properties: node.responses.map((res) => _kubb_kit.ast.factory.createProperty({
|
|
222
222
|
name: String(res.statusCode),
|
|
223
223
|
required: true,
|
|
224
224
|
schema: buildResponseRecordEntry(node, res, resolver)
|
|
@@ -250,8 +250,8 @@ function getSuccessResponses(responses) {
|
|
|
250
250
|
* ```
|
|
251
251
|
*/
|
|
252
252
|
function getOasAdapter(adapter) {
|
|
253
|
-
if (adapter.name !== "oas") throw new
|
|
254
|
-
code:
|
|
253
|
+
if (adapter.name !== "oas") throw new _kubb_kit.Diagnostics.Error({
|
|
254
|
+
code: _kubb_kit.Diagnostics.code.adapterRequired,
|
|
255
255
|
severity: "error",
|
|
256
256
|
message: `Expected the OpenAPI adapter (adapterOas), but received "${adapter.name}".`,
|
|
257
257
|
help: "Set `adapter: adapterOas()` in kubb.config.ts.",
|
|
@@ -584,9 +584,9 @@ function lazyGetter({ name, body }) {
|
|
|
584
584
|
* @example Suffix applied to the final segment only
|
|
585
585
|
* `toFilePath('tag.tag', (part) => camelCase(part, { suffix: 'schema' })) // 'tag/tagSchema'`
|
|
586
586
|
*/
|
|
587
|
-
function toFilePath(name, caseLast =
|
|
587
|
+
function toFilePath(name, caseLast = _kubb_kit.camelCase) {
|
|
588
588
|
const parts = name.split(/\.(?=[a-zA-Z])/);
|
|
589
|
-
return parts.map((part, i) => i === parts.length - 1 ? caseLast(part) : (0,
|
|
589
|
+
return parts.map((part, i) => i === parts.length - 1 ? caseLast(part) : (0, _kubb_kit.camelCase)(part)).filter(Boolean).join("/");
|
|
590
590
|
}
|
|
591
591
|
// ../../internals/shared/src/resolver.ts
|
|
592
592
|
/**
|
|
@@ -708,7 +708,7 @@ function createCasedFile(caseLast) {
|
|
|
708
708
|
* Names of the schemas in a circular reference chain, computed once per build.
|
|
709
709
|
*/
|
|
710
710
|
function getCircularNames(ctx) {
|
|
711
|
-
return ctx.memo("circularNames:set", () =>
|
|
711
|
+
return ctx.memo("circularNames:set", () => _kubb_kit.ast.findCircularSchemas(ctx.driver.inputNode?.schemas ?? []));
|
|
712
712
|
}
|
|
713
713
|
// ../../internals/shared/src/group.ts
|
|
714
714
|
/**
|
|
@@ -733,7 +733,7 @@ function createGroupConfig(group) {
|
|
|
733
733
|
if (!group) return null;
|
|
734
734
|
const defaultName = (ctx) => {
|
|
735
735
|
if (group.type === "path") return `${ctx.group.split("/")[1]}`;
|
|
736
|
-
return (0,
|
|
736
|
+
return (0, _kubb_kit.camelCase)(ctx.group);
|
|
737
737
|
};
|
|
738
738
|
return {
|
|
739
739
|
...group,
|
|
@@ -784,14 +784,14 @@ function Zod({ name, node, printer, inferTypeName, inferKind = "infer", typeGuar
|
|
|
784
784
|
const printerImports = printer.drainImports();
|
|
785
785
|
if (!output) return;
|
|
786
786
|
const needsAnnotation = cyclic && node.type !== "object";
|
|
787
|
-
const isBare =
|
|
788
|
-
const isCyclic = Boolean(cyclic || printer.options.cyclicSchemas && (0,
|
|
787
|
+
const isBare = _kubb_kit.ast.isBareRef(node, printer.options.keysToOmit);
|
|
788
|
+
const isCyclic = Boolean(cyclic || printer.options.cyclicSchemas && (0, _kubb_kit.containsCircularRef)(node, { circularSchemas: printer.options.cyclicSchemas }));
|
|
789
789
|
const value = Boolean(compile) && !isBare && !isCyclic ? typeof compile === "object" && compile.strict ? `z.compile(${output}, { strict: true })` : `z.compile(${output})` : output;
|
|
790
790
|
const targetType = inferTypeName ?? `z.infer<typeof ${name}>`;
|
|
791
791
|
const shouldGenerateIs = isName && (typeof typeGuards === "object" ? typeGuards.is ?? true : Boolean(typeGuards));
|
|
792
792
|
const shouldGenerateAssert = assertName && (typeof typeGuards === "object" ? typeGuards.assert ?? true : Boolean(typeGuards));
|
|
793
|
-
return /* @__PURE__ */ (0,
|
|
794
|
-
printerImports.map((imp) => /* @__PURE__ */ (0,
|
|
793
|
+
return /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsxs)(_kubb_renderer_jsx_jsx_runtime.Fragment, { children: [
|
|
794
|
+
printerImports.map((imp) => /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Import, {
|
|
795
795
|
name: imp.name,
|
|
796
796
|
path: imp.path,
|
|
797
797
|
root: imp.root,
|
|
@@ -802,44 +802,44 @@ function Zod({ name, node, printer, inferTypeName, inferKind = "infer", typeGuar
|
|
|
802
802
|
imp.path,
|
|
803
803
|
imp.name
|
|
804
804
|
].join("-"))),
|
|
805
|
-
/* @__PURE__ */ (0,
|
|
805
|
+
/* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Source, {
|
|
806
806
|
name,
|
|
807
807
|
isExportable: true,
|
|
808
808
|
isIndexable: true,
|
|
809
|
-
children: /* @__PURE__ */ (0,
|
|
809
|
+
children: /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.Const, {
|
|
810
810
|
export: true,
|
|
811
811
|
name,
|
|
812
812
|
type: needsAnnotation ? "z.ZodType" : void 0,
|
|
813
813
|
children: value
|
|
814
814
|
})
|
|
815
815
|
}),
|
|
816
|
-
inferTypeName && /* @__PURE__ */ (0,
|
|
816
|
+
inferTypeName && /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Source, {
|
|
817
817
|
name: inferTypeName,
|
|
818
818
|
isExportable: true,
|
|
819
819
|
isIndexable: true,
|
|
820
820
|
isTypeOnly: true,
|
|
821
|
-
children: /* @__PURE__ */ (0,
|
|
821
|
+
children: /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.Type, {
|
|
822
822
|
export: true,
|
|
823
823
|
name: inferTypeName,
|
|
824
824
|
children: `z.${inferKind}<typeof ${name}>`
|
|
825
825
|
})
|
|
826
826
|
}),
|
|
827
|
-
shouldGenerateIs && /* @__PURE__ */ (0,
|
|
827
|
+
shouldGenerateIs && /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Source, {
|
|
828
828
|
name: isName,
|
|
829
829
|
isExportable: true,
|
|
830
830
|
isIndexable: true,
|
|
831
|
-
children: /* @__PURE__ */ (0,
|
|
831
|
+
children: /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.Const, {
|
|
832
832
|
export: true,
|
|
833
833
|
name: isName,
|
|
834
834
|
JSDoc: { comments: [`Type guard for {@link ${name}}`] },
|
|
835
835
|
children: mini ? `(data: unknown): data is ${targetType} => z.validate(${name}, data)` : `(data: unknown): data is ${targetType} => ${name}.validate(data)`
|
|
836
836
|
})
|
|
837
837
|
}),
|
|
838
|
-
shouldGenerateAssert && /* @__PURE__ */ (0,
|
|
838
|
+
shouldGenerateAssert && /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Source, {
|
|
839
839
|
name: assertName,
|
|
840
840
|
isExportable: true,
|
|
841
841
|
isIndexable: true,
|
|
842
|
-
children: /* @__PURE__ */ (0,
|
|
842
|
+
children: /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.Function, {
|
|
843
843
|
export: true,
|
|
844
844
|
name: assertName,
|
|
845
845
|
params: "data: unknown",
|
|
@@ -869,7 +869,7 @@ function shouldCoerce(coercion, type) {
|
|
|
869
869
|
*/
|
|
870
870
|
function isClosedKeySchema(node) {
|
|
871
871
|
if (!node) return false;
|
|
872
|
-
const resolved = (0,
|
|
872
|
+
const resolved = (0, _kubb_kit.syncSchemaRef)(node);
|
|
873
873
|
if (resolved.type === "enum") return true;
|
|
874
874
|
if (resolved.type === "union") {
|
|
875
875
|
const members = resolved.members ?? [];
|
|
@@ -907,9 +907,9 @@ function isObjectSchemaNode(node, cyclicSchemas) {
|
|
|
907
907
|
return !(!hasProperties && (hasTypedAdditionalProperties || hasPatternProperties || node.propertyNames));
|
|
908
908
|
}
|
|
909
909
|
if (node.type === "ref") {
|
|
910
|
-
const refName =
|
|
910
|
+
const refName = _kubb_kit.ast.resolveRefName(node);
|
|
911
911
|
if (refName && cyclicSchemas?.has(refName)) return false;
|
|
912
|
-
const resolved = (0,
|
|
912
|
+
const resolved = (0, _kubb_kit.syncSchemaRef)(node);
|
|
913
913
|
return resolved.type === "ref" || isObjectSchemaNode(resolved, cyclicSchemas);
|
|
914
914
|
}
|
|
915
915
|
if (node.type === "union") {
|
|
@@ -932,23 +932,23 @@ function preserveRequiredProperties(members) {
|
|
|
932
932
|
const hasRequiredProperty = ({ node, propertyName, seen = /* @__PURE__ */ new Set() }) => {
|
|
933
933
|
if (seen.has(node)) return false;
|
|
934
934
|
seen.add(node);
|
|
935
|
-
const resolved = (0,
|
|
936
|
-
const composition =
|
|
935
|
+
const resolved = (0, _kubb_kit.syncSchemaRef)(node);
|
|
936
|
+
const composition = _kubb_kit.ast.narrowSchema(resolved, _kubb_kit.ast.schemaTypes.intersection) ?? _kubb_kit.ast.narrowSchema(resolved, _kubb_kit.ast.schemaTypes.union);
|
|
937
937
|
if (composition) {
|
|
938
|
-
if (composition.type ===
|
|
938
|
+
if (composition.type === _kubb_kit.ast.schemaTypes.union && composition.members?.length !== 1) return false;
|
|
939
939
|
return composition.members?.some((child) => hasRequiredProperty({
|
|
940
940
|
node: child,
|
|
941
941
|
propertyName,
|
|
942
942
|
seen
|
|
943
943
|
})) ?? false;
|
|
944
944
|
}
|
|
945
|
-
return
|
|
945
|
+
return _kubb_kit.ast.resolveSchemaProperties({
|
|
946
946
|
node: resolved,
|
|
947
947
|
propertyName
|
|
948
948
|
}).some((property) => property.required !== false && !property.schema.optional && !property.schema.nullish);
|
|
949
949
|
};
|
|
950
950
|
return members.map((member, index) => {
|
|
951
|
-
const object =
|
|
951
|
+
const object = _kubb_kit.ast.narrowSchema(member, _kubb_kit.ast.schemaTypes.object);
|
|
952
952
|
if (!object || index === 0) return member;
|
|
953
953
|
return {
|
|
954
954
|
...object,
|
|
@@ -992,14 +992,14 @@ function formatDefault(value) {
|
|
|
992
992
|
*/
|
|
993
993
|
function defaultLiteral(node, value) {
|
|
994
994
|
if (value === null) return null;
|
|
995
|
-
const resolved = node ? (0,
|
|
996
|
-
if (resolved &&
|
|
995
|
+
const resolved = node ? (0, _kubb_kit.syncSchemaRef)(node) : void 0;
|
|
996
|
+
if (resolved && _kubb_kit.ast.narrowSchema(resolved, "bigint")) {
|
|
997
997
|
if (typeof value === "bigint") return `BigInt(${value})`;
|
|
998
998
|
if (typeof value === "number" && Number.isInteger(value)) return `BigInt(${value})`;
|
|
999
999
|
return null;
|
|
1000
1000
|
}
|
|
1001
|
-
if (resolved &&
|
|
1002
|
-
const enumNode = resolved ?
|
|
1001
|
+
if (resolved && _kubb_kit.ast.narrowSchema(resolved, "array")) return Array.isArray(value) ? JSON.stringify(value) : null;
|
|
1002
|
+
const enumNode = resolved ? _kubb_kit.ast.narrowSchema(resolved, "enum") : void 0;
|
|
1003
1003
|
if (enumNode) {
|
|
1004
1004
|
const values = enumNode.namedEnumValues?.map((member) => member.value) ?? enumNode.enumValues ?? [];
|
|
1005
1005
|
if (values.length) {
|
|
@@ -1155,7 +1155,7 @@ function modifierDepth(schema) {
|
|
|
1155
1155
|
* `.unwrap()`, so its printer passes `._zod.def.innerType` as the `step`.
|
|
1156
1156
|
*/
|
|
1157
1157
|
function omitUnwrapChain(node, step = ".unwrap()") {
|
|
1158
|
-
const ref =
|
|
1158
|
+
const ref = _kubb_kit.ast.narrowSchema(node, "ref");
|
|
1159
1159
|
if (!ref) return "";
|
|
1160
1160
|
const target = ref.schema ?? ref;
|
|
1161
1161
|
const depth = modifierDepth(target) + (target.default !== void 0 ? 1 : 0);
|
|
@@ -1201,12 +1201,12 @@ function strictOneOfNode(node) {
|
|
|
1201
1201
|
*/
|
|
1202
1202
|
function getMemberConstraint({ member, regexType, lengths, numbers }) {
|
|
1203
1203
|
if (member.primitive === "string") return lengths({
|
|
1204
|
-
...
|
|
1204
|
+
..._kubb_kit.ast.narrowSchema(member, "string") ?? {},
|
|
1205
1205
|
regexType
|
|
1206
1206
|
}) || void 0;
|
|
1207
|
-
if (member.primitive === "number" || member.primitive === "integer") return numbers(
|
|
1207
|
+
if (member.primitive === "number" || member.primitive === "integer") return numbers(_kubb_kit.ast.narrowSchema(member, "number") ?? _kubb_kit.ast.narrowSchema(member, "integer") ?? {}) || void 0;
|
|
1208
1208
|
if (member.primitive === "array") return lengths({
|
|
1209
|
-
...
|
|
1209
|
+
..._kubb_kit.ast.narrowSchema(member, "array") ?? {},
|
|
1210
1210
|
regexType
|
|
1211
1211
|
}) || void 0;
|
|
1212
1212
|
}
|
|
@@ -1214,14 +1214,14 @@ function getMemberConstraint({ member, regexType, lengths, numbers }) {
|
|
|
1214
1214
|
* Builds the `{ key: value, … }` shape shared by the `z.object(...)` and `.extend(...)` renderings.
|
|
1215
1215
|
*/
|
|
1216
1216
|
function buildObjectShape(ctx, node, renderProperty) {
|
|
1217
|
-
const objectNode =
|
|
1217
|
+
const objectNode = _kubb_kit.ast.narrowSchema(node, "object");
|
|
1218
1218
|
if (!objectNode) return "{}";
|
|
1219
|
-
const isCyclic = (schema) => ctx.options.cyclicSchemas != null && (0,
|
|
1219
|
+
const isCyclic = (schema) => ctx.options.cyclicSchemas != null && (0, _kubb_kit.containsCircularRef)(schema, { circularSchemas: ctx.options.cyclicSchemas });
|
|
1220
1220
|
return buildObject(mapSchemaProperties(objectNode, (schema) => {
|
|
1221
1221
|
const hasSelfRef = isCyclic(schema);
|
|
1222
1222
|
const savedCyclicSchemas = ctx.options.cyclicSchemas;
|
|
1223
1223
|
if (hasSelfRef) ctx.options.cyclicSchemas = void 0;
|
|
1224
|
-
const baseOutput = ctx.transform(schema) ?? ctx.transform(
|
|
1224
|
+
const baseOutput = ctx.transform(schema) ?? ctx.transform(_kubb_kit.ast.factory.createSchema({ type: "unknown" }));
|
|
1225
1225
|
if (hasSelfRef) ctx.options.cyclicSchemas = savedCyclicSchemas;
|
|
1226
1226
|
return baseOutput;
|
|
1227
1227
|
}).map(({ name, property, output: value }) => {
|
|
@@ -1231,7 +1231,7 @@ function buildObjectShape(ctx, node, renderProperty) {
|
|
|
1231
1231
|
value,
|
|
1232
1232
|
schema,
|
|
1233
1233
|
required: property.required,
|
|
1234
|
-
meta: (0,
|
|
1234
|
+
meta: (0, _kubb_kit.syncSchemaRef)(schema),
|
|
1235
1235
|
cyclic: isCyclic(schema)
|
|
1236
1236
|
});
|
|
1237
1237
|
}));
|
|
@@ -1243,7 +1243,7 @@ function printWithOmit(ctx, node, modify, mini = false) {
|
|
|
1243
1243
|
const { keysToOmit } = ctx.options;
|
|
1244
1244
|
const transformed = ctx.transform(node);
|
|
1245
1245
|
if (!transformed) return null;
|
|
1246
|
-
const meta = (0,
|
|
1246
|
+
const meta = (0, _kubb_kit.syncSchemaRef)(node);
|
|
1247
1247
|
return modify((() => {
|
|
1248
1248
|
if (!keysToOmit?.length || meta.primitive !== "object" || meta.type === "union" && meta.discriminatorPropertyName) return transformed;
|
|
1249
1249
|
const unwrap = omitUnwrapChain(node, mini ? "._zod.def.innerType" : ".unwrap()");
|
|
@@ -1263,6 +1263,37 @@ function printWithOmit(ctx, node, modify, mini = false) {
|
|
|
1263
1263
|
}
|
|
1264
1264
|
// src/printers/zodNodes.ts
|
|
1265
1265
|
/**
|
|
1266
|
+
* Reads a union of bare single-value enums as one enum, except under `xor` or an enum override, which need each member.
|
|
1267
|
+
* Only a numeric union with a `format` coerces, because it printed as `z.coerce.number()` before the adapter kept its values.
|
|
1268
|
+
*/
|
|
1269
|
+
function getLiteralUnion({ node, options }) {
|
|
1270
|
+
if (node.strategy === "one" && options.oneOfType === "xor" || options.nodes?.enum) return void 0;
|
|
1271
|
+
const values = (node.members ?? []).map((member) => {
|
|
1272
|
+
const enumNode = _kubb_kit.ast.narrowSchema(member, _kubb_kit.ast.schemaTypes.enum);
|
|
1273
|
+
return enumNode && !enumNode.name && !enumNode.nullable && !enumNode.namedEnumValues && enumNode.enumValues?.length === 1 ? enumNode.enumValues[0] : void 0;
|
|
1274
|
+
});
|
|
1275
|
+
if (!values.length || !values.every((value) => value !== void 0 && value !== null)) return void 0;
|
|
1276
|
+
return {
|
|
1277
|
+
values,
|
|
1278
|
+
coerce: !!node.format && values.every((value) => typeof value === "number") && shouldCoerce(options.coercion, "numbers")
|
|
1279
|
+
};
|
|
1280
|
+
}
|
|
1281
|
+
/**
|
|
1282
|
+
* Whether a discriminated union member's discriminator property prints as a coerced literal union.
|
|
1283
|
+
*/
|
|
1284
|
+
function hasCoercedDiscriminator({ member, propertyName, options }) {
|
|
1285
|
+
return _kubb_kit.ast.resolveSchemaProperties({
|
|
1286
|
+
node: member,
|
|
1287
|
+
propertyName
|
|
1288
|
+
}).some(({ schema }) => {
|
|
1289
|
+
const resolved = (0, _kubb_kit.syncSchemaRef)(schema);
|
|
1290
|
+
return resolved.type === "union" && !!getLiteralUnion({
|
|
1291
|
+
node: resolved,
|
|
1292
|
+
options
|
|
1293
|
+
})?.coerce;
|
|
1294
|
+
});
|
|
1295
|
+
}
|
|
1296
|
+
/**
|
|
1266
1297
|
* Builds the scalar handlers both dialects share. They never recurse into children. The temporal
|
|
1267
1298
|
* scalars and `bigint` differ per dialect, so each printer adds its own.
|
|
1268
1299
|
*/
|
|
@@ -1343,7 +1374,7 @@ function buildZodNodes(dialect, cyclicSchemas) {
|
|
|
1343
1374
|
...buildScalarNodes(dialect),
|
|
1344
1375
|
ref(node) {
|
|
1345
1376
|
if (!node.name) return null;
|
|
1346
|
-
const refName =
|
|
1377
|
+
const refName = _kubb_kit.ast.resolveRefName(node);
|
|
1347
1378
|
if (!refName) return null;
|
|
1348
1379
|
const useInputVariant = node.ref != null && (dialect.useInputVariant?.(node, this.options) ?? false);
|
|
1349
1380
|
const resolvedName = node.ref ? useInputVariant ? this.options.resolver?.schema.inputName(refName) ?? refName : this.options.resolver?.name(refName) ?? refName : node.name;
|
|
@@ -1367,14 +1398,14 @@ function buildZodNodes(dialect, cyclicSchemas) {
|
|
|
1367
1398
|
return catchallType ? dialect.catchall(objectBase, catchallType) : objectBase;
|
|
1368
1399
|
}
|
|
1369
1400
|
if (entries.length === 0 && patterns.length === 0 && propertyNamesKeySchema && !isStrict) {
|
|
1370
|
-
const unknownType = this.transform(
|
|
1401
|
+
const unknownType = this.transform(_kubb_kit.ast.factory.createSchema({ type: _kubb_kit.ast.schemaTypes.unknown }));
|
|
1371
1402
|
return `${recordFn}(${propertyNamesKeySchema}, ${unknownType})`;
|
|
1372
1403
|
}
|
|
1373
1404
|
if (node.additionalProperties === true) return objectBase;
|
|
1374
1405
|
if (isStrict) return objectBase;
|
|
1375
1406
|
if (patterns.length > 0) {
|
|
1376
1407
|
const values = patterns.map(([, valueSchema]) => {
|
|
1377
|
-
const valueType = this.transform(valueSchema) ?? this.transform(
|
|
1408
|
+
const valueType = this.transform(valueSchema) ?? this.transform(_kubb_kit.ast.factory.createSchema({ type: _kubb_kit.ast.schemaTypes.unknown }));
|
|
1378
1409
|
return valueSchema.nullable ? dialect.nullable(valueType) : valueType;
|
|
1379
1410
|
});
|
|
1380
1411
|
const distinct = [...new Set(values)];
|
|
@@ -1391,7 +1422,7 @@ function buildZodNodes(dialect, cyclicSchemas) {
|
|
|
1391
1422
|
});
|
|
1392
1423
|
},
|
|
1393
1424
|
array(node) {
|
|
1394
|
-
const base = `z.array(${mapSchemaItems(node, (item) => this.transform(item)).map(({ output }) => output).filter(Boolean).join(", ") || this.transform(
|
|
1425
|
+
const base = `z.array(${mapSchemaItems(node, (item) => this.transform(item)).map(({ output }) => output).filter(Boolean).join(", ") || this.transform(_kubb_kit.ast.factory.createSchema({ type: _kubb_kit.ast.schemaTypes.unknown }))})${dialect.lengths({
|
|
1395
1426
|
...node,
|
|
1396
1427
|
regexType: this.options.regexType
|
|
1397
1428
|
})}`;
|
|
@@ -1401,8 +1432,21 @@ function buildZodNodes(dialect, cyclicSchemas) {
|
|
|
1401
1432
|
return `z.tuple(${buildList(mapSchemaItems(node, (item) => this.transform(item)).map(({ output }) => output).filter(Boolean))})`;
|
|
1402
1433
|
},
|
|
1403
1434
|
union(node) {
|
|
1435
|
+
const literalUnion = getLiteralUnion({
|
|
1436
|
+
node,
|
|
1437
|
+
options: this.options
|
|
1438
|
+
});
|
|
1439
|
+
if (literalUnion) {
|
|
1440
|
+
const schema = buildEnum(literalUnion.values);
|
|
1441
|
+
return literalUnion.coerce ? dialect.coercedNumber(schema) : schema;
|
|
1442
|
+
}
|
|
1404
1443
|
const nodeMembers = node.members ?? [];
|
|
1405
|
-
const
|
|
1444
|
+
const { discriminatorPropertyName } = node;
|
|
1445
|
+
const isDiscriminated = !!discriminatorPropertyName && nodeMembers.every((m) => isObjectSchemaNode(m, cyclicSchemas)) && !nodeMembers.some((m) => hasCoercedDiscriminator({
|
|
1446
|
+
member: m,
|
|
1447
|
+
propertyName: discriminatorPropertyName,
|
|
1448
|
+
options: this.options
|
|
1449
|
+
}));
|
|
1406
1450
|
const isXor = node.strategy === "one" && !isDiscriminated && this.options.oneOfType === "xor";
|
|
1407
1451
|
const isStrict = node.strategy === "one" && !isXor && !unionsWithSiblings.has(node);
|
|
1408
1452
|
const members = mapSchemaMembers(node, (memberNode) => this.transform(isStrict ? strictOneOfNode(memberNode) : memberNode)).map(({ schema, output }) => output && isStrict && dialect.strictMember ? dialect.strictMember(output, schema, cyclicSchemas) : output).filter(Boolean);
|
|
@@ -1415,7 +1459,7 @@ function buildZodNodes(dialect, cyclicSchemas) {
|
|
|
1415
1459
|
intersection(node) {
|
|
1416
1460
|
const members = node.members ?? [];
|
|
1417
1461
|
if (members.length === 0) return "";
|
|
1418
|
-
const hasSiblingProperties = members.some((member) => member.type ===
|
|
1462
|
+
const hasSiblingProperties = members.some((member) => member.type === _kubb_kit.ast.schemaTypes.object && member.properties.length > 0);
|
|
1419
1463
|
const transform = (member) => {
|
|
1420
1464
|
if (!hasSiblingProperties) return this.transform(member);
|
|
1421
1465
|
unionsWithSiblings.add(member);
|
|
@@ -1446,13 +1490,13 @@ function buildZodNodes(dialect, cyclicSchemas) {
|
|
|
1446
1490
|
}
|
|
1447
1491
|
// src/printers/printerZod.ts
|
|
1448
1492
|
function strictOneOfMember(member, node, cyclicSchemas) {
|
|
1449
|
-
if (node.type ===
|
|
1493
|
+
if (node.type === _kubb_kit.ast.schemaTypes.ref) {
|
|
1450
1494
|
if (member.startsWith("z.lazy(")) return member;
|
|
1451
|
-
const refName =
|
|
1495
|
+
const refName = _kubb_kit.ast.resolveRefName(node);
|
|
1452
1496
|
if (refName && cyclicSchemas?.has(refName)) return member;
|
|
1453
|
-
const schema = (0,
|
|
1497
|
+
const schema = (0, _kubb_kit.syncSchemaRef)(node);
|
|
1454
1498
|
if (schema.nullable || schema.optional || node.nullable || node.optional) return member;
|
|
1455
|
-
if (schema.type ===
|
|
1499
|
+
if (schema.type === _kubb_kit.ast.schemaTypes.object && (schema.additionalProperties === void 0 || schema.additionalProperties === false)) return `${member}.strict()`;
|
|
1456
1500
|
}
|
|
1457
1501
|
return member;
|
|
1458
1502
|
}
|
|
@@ -1468,7 +1512,7 @@ function buildZodObjectShape(ctx, node) {
|
|
|
1468
1512
|
optional: schema.optional || required === false,
|
|
1469
1513
|
nullish: schema.nullish,
|
|
1470
1514
|
defaultValue: meta.default,
|
|
1471
|
-
description: schema.type !==
|
|
1515
|
+
description: schema.type !== _kubb_kit.ast.schemaTypes.ref && meta.type === _kubb_kit.ast.schemaTypes.ref ? void 0 : meta.description,
|
|
1472
1516
|
examples: meta.examples
|
|
1473
1517
|
});
|
|
1474
1518
|
if (!cyclic) return `${objectKey(name)}: ${body}`;
|
|
@@ -1489,21 +1533,21 @@ function buildZodObjectShape(ctx, node) {
|
|
|
1489
1533
|
function recursiveGetterType({ ctx, schema, required }) {
|
|
1490
1534
|
function baseType(schema) {
|
|
1491
1535
|
if (ctx.options.nodes?.[schema.type]) return void 0;
|
|
1492
|
-
if (schema.type ===
|
|
1536
|
+
if (schema.type === _kubb_kit.ast.schemaTypes.ref) {
|
|
1493
1537
|
const saved = ctx.options.cyclicSchemas;
|
|
1494
1538
|
ctx.options.cyclicSchemas = void 0;
|
|
1495
1539
|
const name = ctx.transform(schema);
|
|
1496
1540
|
ctx.options.cyclicSchemas = saved;
|
|
1497
1541
|
return name ? `typeof ${name}` : void 0;
|
|
1498
1542
|
}
|
|
1499
|
-
if (schema.type ===
|
|
1543
|
+
if (schema.type === _kubb_kit.ast.schemaTypes.array && schema.items?.length === 1) {
|
|
1500
1544
|
const item = baseType(schema.items[0]);
|
|
1501
1545
|
return item ? `z.ZodArray<${item}>` : void 0;
|
|
1502
1546
|
}
|
|
1503
1547
|
}
|
|
1504
1548
|
const base = baseType(schema);
|
|
1505
1549
|
if (!base) return void 0;
|
|
1506
|
-
const meta = (0,
|
|
1550
|
+
const meta = (0, _kubb_kit.syncSchemaRef)(schema);
|
|
1507
1551
|
const optional = schema.optional || required === false;
|
|
1508
1552
|
const wrapped = (() => {
|
|
1509
1553
|
if (schema.nullish || meta.nullable && optional) return `z.ZodOptional<z.ZodNullable<${base}>>`;
|
|
@@ -1518,12 +1562,12 @@ function recursiveGetterType({ ctx, schema, required }) {
|
|
|
1518
1562
|
* `direction` themselves, so {@link containsDirectionalNode} probes their children instead.
|
|
1519
1563
|
*/
|
|
1520
1564
|
const CONTAINER_TYPES = /* @__PURE__ */ new Set([
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1565
|
+
_kubb_kit.ast.schemaTypes.object,
|
|
1566
|
+
_kubb_kit.ast.schemaTypes.array,
|
|
1567
|
+
_kubb_kit.ast.schemaTypes.tuple,
|
|
1568
|
+
_kubb_kit.ast.schemaTypes.union,
|
|
1569
|
+
_kubb_kit.ast.schemaTypes.intersection,
|
|
1570
|
+
_kubb_kit.ast.schemaTypes.ref
|
|
1527
1571
|
]);
|
|
1528
1572
|
/**
|
|
1529
1573
|
* Runs the node's effective handler (a `printer.nodes` override, else the built-in) once per
|
|
@@ -1554,7 +1598,7 @@ function variesByDirection({ node, printerOptions }) {
|
|
|
1554
1598
|
*/
|
|
1555
1599
|
function containsDirectionalNode({ node, printerOptions }) {
|
|
1556
1600
|
if (!node) return false;
|
|
1557
|
-
return
|
|
1601
|
+
return _kubb_kit.ast.findSchema(node, {
|
|
1558
1602
|
predicate: (schema) => variesByDirection({
|
|
1559
1603
|
node: schema,
|
|
1560
1604
|
printerOptions
|
|
@@ -1566,10 +1610,10 @@ function containsDirectionalNode({ node, printerOptions }) {
|
|
|
1566
1610
|
* Names of the `$ref` schemas the generator should route to their input (encode) variant.
|
|
1567
1611
|
*/
|
|
1568
1612
|
function collectDirectionalRefNames({ node, printerOptions }) {
|
|
1569
|
-
return
|
|
1613
|
+
return _kubb_kit.ast.collectSync(node, { schema: (n) => n.type === _kubb_kit.ast.schemaTypes.ref && n.ref && containsDirectionalNode({
|
|
1570
1614
|
node: n,
|
|
1571
1615
|
printerOptions
|
|
1572
|
-
}) ?
|
|
1616
|
+
}) ? _kubb_kit.ast.resolveRefName(n) ?? void 0 : void 0 });
|
|
1573
1617
|
}
|
|
1574
1618
|
/**
|
|
1575
1619
|
* Handlers that never recurse into children, so {@link variesByDirection} can call one directly
|
|
@@ -1588,6 +1632,7 @@ const standardDialect = {
|
|
|
1588
1632
|
patternKey: patternKeySchema,
|
|
1589
1633
|
objectShape: buildZodObjectShape,
|
|
1590
1634
|
coercedInt: "z.coerce.number().int()",
|
|
1635
|
+
coercedNumber: (schema) => `z.coerce.number().pipe(${schema})`,
|
|
1591
1636
|
catchall: (object, value) => `${object}.catchall(${value})`,
|
|
1592
1637
|
nullable: (value) => `${value}.nullable()`,
|
|
1593
1638
|
unique: (array) => `${array}.refine(items => new Set(items).size === items.length, { message: "Array entries must be unique" })`,
|
|
@@ -1635,7 +1680,7 @@ const scalarNodes = {
|
|
|
1635
1680
|
* const code = printer.print(stringNode) // "z.string()"
|
|
1636
1681
|
* ```
|
|
1637
1682
|
*/
|
|
1638
|
-
const printerZod =
|
|
1683
|
+
const printerZod = _kubb_kit.ast.createPrinter((options) => {
|
|
1639
1684
|
return {
|
|
1640
1685
|
name: "zod",
|
|
1641
1686
|
options,
|
|
@@ -1696,13 +1741,14 @@ const miniDialect = {
|
|
|
1696
1741
|
patternKey: patternKeySchemaMini,
|
|
1697
1742
|
objectShape: buildZodMiniObjectShape,
|
|
1698
1743
|
coercedInt: "z.coerce.number().check(z.int())",
|
|
1744
|
+
coercedNumber: (schema) => `z.pipe(z.coerce.number(), ${schema})`,
|
|
1699
1745
|
catchall: (object, value) => `z.catchall(${object}, ${value})`,
|
|
1700
1746
|
nullable: (value) => `z.nullable(${value})`,
|
|
1701
1747
|
unique: (array) => `${array}.check(z.refine(items => new Set(items).size === items.length, { message: "Array entries must be unique" }))`,
|
|
1702
1748
|
extend: (base, shape) => `z.extend(${base}, ${shape})`,
|
|
1703
1749
|
intersection: (left, right) => `z.intersection(${left}, ${right})`
|
|
1704
1750
|
};
|
|
1705
|
-
const printerZodMini =
|
|
1751
|
+
const printerZodMini = _kubb_kit.ast.createPrinter((options) => {
|
|
1706
1752
|
return {
|
|
1707
1753
|
name: "zod-mini",
|
|
1708
1754
|
options,
|
|
@@ -1777,9 +1823,9 @@ function getPrinter(resolver, options, mini, direction) {
|
|
|
1777
1823
|
* When `mini: true`, schemas use the Zod Mini functional API instead of
|
|
1778
1824
|
* chainable methods.
|
|
1779
1825
|
*/
|
|
1780
|
-
const zodGenerator = (0,
|
|
1826
|
+
const zodGenerator = (0, _kubb_kit.defineGenerator)({
|
|
1781
1827
|
name: "zod",
|
|
1782
|
-
renderer:
|
|
1828
|
+
renderer: _kubb_renderer_jsx.jsxRenderer,
|
|
1783
1829
|
schema(node, ctx) {
|
|
1784
1830
|
const { adapter, config, resolver, root } = ctx;
|
|
1785
1831
|
const { output, coercion, guidType, regexType, oneOfType, compile, mini, inferred, typeGuards, importPath, group, printer } = ctx.options;
|
|
@@ -1835,7 +1881,7 @@ const zodGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
1835
1881
|
const isName = typeGuards ? resolver.schema.isName(node.name) : null;
|
|
1836
1882
|
const assertName = typeGuards ? resolver.schema.assertName(node.name) : null;
|
|
1837
1883
|
const schemaPrinter = getPrinter(resolver, printerOptions, mini, "decode");
|
|
1838
|
-
return /* @__PURE__ */ (0,
|
|
1884
|
+
return /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsxs)(_kubb_renderer_jsx.File, {
|
|
1839
1885
|
baseName: meta.file.baseName,
|
|
1840
1886
|
path: meta.file.path,
|
|
1841
1887
|
meta: meta.file.meta,
|
|
@@ -1856,12 +1902,12 @@ const zodGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
1856
1902
|
}
|
|
1857
1903
|
}),
|
|
1858
1904
|
children: [
|
|
1859
|
-
/* @__PURE__ */ (0,
|
|
1905
|
+
/* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Import, {
|
|
1860
1906
|
name: isZodImport ? "z" : ["z"],
|
|
1861
1907
|
path: importPath,
|
|
1862
1908
|
isNameSpace: isZodImport
|
|
1863
1909
|
}),
|
|
1864
|
-
imports.map((imp) => /* @__PURE__ */ (0,
|
|
1910
|
+
imports.map((imp) => /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Import, {
|
|
1865
1911
|
root: meta.file.path,
|
|
1866
1912
|
path: imp.path,
|
|
1867
1913
|
name: imp.name
|
|
@@ -1870,7 +1916,7 @@ const zodGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
1870
1916
|
imp.path,
|
|
1871
1917
|
imp.name
|
|
1872
1918
|
].join("-"))),
|
|
1873
|
-
/* @__PURE__ */ (0,
|
|
1919
|
+
/* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(Zod, {
|
|
1874
1920
|
name: meta.name,
|
|
1875
1921
|
node,
|
|
1876
1922
|
printer: schemaPrinter,
|
|
@@ -1883,7 +1929,7 @@ const zodGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
1883
1929
|
cyclic: cyclicSchemas.has(node.name),
|
|
1884
1930
|
compile
|
|
1885
1931
|
}),
|
|
1886
|
-
hasDirectionalNode && /* @__PURE__ */ (0,
|
|
1932
|
+
hasDirectionalNode && /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(Zod, {
|
|
1887
1933
|
name: resolver.schema.inputName(node.name),
|
|
1888
1934
|
node,
|
|
1889
1935
|
printer: getPrinter(resolver, printerOptions, mini, "encode"),
|
|
@@ -1900,7 +1946,7 @@ const zodGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
1900
1946
|
});
|
|
1901
1947
|
},
|
|
1902
1948
|
operation(node, ctx) {
|
|
1903
|
-
if (!
|
|
1949
|
+
if (!_kubb_kit.ast.isHttpOperationNode(node)) return null;
|
|
1904
1950
|
const { adapter, config, resolver, root } = ctx;
|
|
1905
1951
|
const { output, coercion, guidType, regexType, oneOfType, compile, mini, inferred, importPath, group, printer } = ctx.options;
|
|
1906
1952
|
const dateType = getOasAdapter(adapter).options.dateType;
|
|
@@ -1941,7 +1987,7 @@ const zodGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
1941
1987
|
...printerOptions,
|
|
1942
1988
|
keysToOmit
|
|
1943
1989
|
}, mini, direction);
|
|
1944
|
-
return /* @__PURE__ */ (0,
|
|
1990
|
+
return /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsxs)(_kubb_renderer_jsx_jsx_runtime.Fragment, { children: [imports.map((imp) => /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Import, {
|
|
1945
1991
|
root: meta.file.path,
|
|
1946
1992
|
path: imp.path,
|
|
1947
1993
|
name: imp.name
|
|
@@ -1949,7 +1995,7 @@ const zodGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
1949
1995
|
name,
|
|
1950
1996
|
imp.path,
|
|
1951
1997
|
imp.name
|
|
1952
|
-
].join("-"))), /* @__PURE__ */ (0,
|
|
1998
|
+
].join("-"))), /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(Zod, {
|
|
1953
1999
|
name,
|
|
1954
2000
|
node: schema,
|
|
1955
2001
|
printer: schemaPrinter,
|
|
@@ -1961,14 +2007,14 @@ const zodGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
1961
2007
|
}
|
|
1962
2008
|
function buildContentTypeVariants(entries, baseName, decorate, direction) {
|
|
1963
2009
|
const variants = resolveContentTypeVariants(entries, baseName);
|
|
1964
|
-
const unionSchema =
|
|
2010
|
+
const unionSchema = _kubb_kit.ast.factory.createSchema({
|
|
1965
2011
|
type: "union",
|
|
1966
|
-
members: variants.map((variant) =>
|
|
2012
|
+
members: variants.map((variant) => _kubb_kit.ast.factory.createSchema({
|
|
1967
2013
|
type: "ref",
|
|
1968
2014
|
name: variant.name
|
|
1969
2015
|
}))
|
|
1970
2016
|
});
|
|
1971
|
-
return /* @__PURE__ */ (0,
|
|
2017
|
+
return /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsxs)(_kubb_renderer_jsx_jsx_runtime.Fragment, { children: [variants.map((variant) => renderSchemaEntry({
|
|
1972
2018
|
schema: decorate ? decorate(variant.schema) : variant.schema,
|
|
1973
2019
|
name: variant.name,
|
|
1974
2020
|
keysToOmit: variant.keysToOmit,
|
|
@@ -1980,17 +2026,17 @@ const zodGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
1980
2026
|
})] });
|
|
1981
2027
|
}
|
|
1982
2028
|
function buildResponseUnion({ responses, name, fallbackUnknown }) {
|
|
1983
|
-
if (new Set(responses.flatMap((res) => (res.content ?? []).flatMap((entry) => entry.schema ?
|
|
1984
|
-
const members = responses.map((res) =>
|
|
2029
|
+
if (new Set(responses.flatMap((res) => (res.content ?? []).flatMap((entry) => entry.schema ? _kubb_kit.ast.collectImportedRefNames(entry.schema).map((refName) => resolver.name(refName)) : []))).has(name)) return null;
|
|
2030
|
+
const members = responses.map((res) => _kubb_kit.ast.factory.createSchema({
|
|
1985
2031
|
type: "ref",
|
|
1986
2032
|
name: resolver.response.status(node, res.statusCode)
|
|
1987
2033
|
}));
|
|
1988
2034
|
if (fallbackUnknown && members.length === 0) return renderSchemaEntry({
|
|
1989
|
-
schema:
|
|
2035
|
+
schema: _kubb_kit.ast.factory.createSchema({ type: "unknown" }),
|
|
1990
2036
|
name
|
|
1991
2037
|
});
|
|
1992
2038
|
return renderSchemaEntry({
|
|
1993
|
-
schema: members.length === 1 ? members[0] :
|
|
2039
|
+
schema: members.length === 1 ? members[0] : _kubb_kit.ast.factory.createSchema({
|
|
1994
2040
|
type: "union",
|
|
1995
2041
|
members
|
|
1996
2042
|
}),
|
|
@@ -2061,10 +2107,10 @@ const zodGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
2061
2107
|
params: header
|
|
2062
2108
|
}
|
|
2063
2109
|
].filter(({ params }) => params.length > 0).map(({ kind, params }) => renderSchemaEntry({
|
|
2064
|
-
schema:
|
|
2110
|
+
schema: _kubb_kit.ast.factory.createSchema({
|
|
2065
2111
|
type: "object",
|
|
2066
2112
|
primitive: "object",
|
|
2067
|
-
properties: params.map((param) =>
|
|
2113
|
+
properties: params.map((param) => _kubb_kit.ast.factory.createProperty({
|
|
2068
2114
|
name: param.name,
|
|
2069
2115
|
required: param.required,
|
|
2070
2116
|
schema: param.schema
|
|
@@ -2082,7 +2128,7 @@ const zodGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
2082
2128
|
schema: buildResponses(node, resolver),
|
|
2083
2129
|
name: resolver.response.responses(node)
|
|
2084
2130
|
}) : null;
|
|
2085
|
-
return /* @__PURE__ */ (0,
|
|
2131
|
+
return /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsxs)(_kubb_renderer_jsx.File, {
|
|
2086
2132
|
baseName: meta.file.baseName,
|
|
2087
2133
|
path: meta.file.path,
|
|
2088
2134
|
meta: meta.file.meta,
|
|
@@ -2103,7 +2149,7 @@ const zodGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
2103
2149
|
}
|
|
2104
2150
|
}),
|
|
2105
2151
|
children: [
|
|
2106
|
-
/* @__PURE__ */ (0,
|
|
2152
|
+
/* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Import, {
|
|
2107
2153
|
name: isZodImport ? "z" : ["z"],
|
|
2108
2154
|
path: importPath,
|
|
2109
2155
|
isNameSpace: isZodImport
|
|
@@ -2126,7 +2172,7 @@ var compatibility = {
|
|
|
2126
2172
|
"node": ">=22.22"
|
|
2127
2173
|
};
|
|
2128
2174
|
// package.json
|
|
2129
|
-
var version = "5.8.
|
|
2175
|
+
var version = "5.8.1";
|
|
2130
2176
|
// src/resolvers/resolverZod.ts
|
|
2131
2177
|
/**
|
|
2132
2178
|
* Default resolver used by `@kubb/plugin-zod`. Decides the names and file
|
|
@@ -2143,18 +2189,18 @@ var version = "5.8.0-canary.20261029T124214";
|
|
|
2143
2189
|
* resolverZod.schema.typeName('pet') // 'PetSchemaType'
|
|
2144
2190
|
* ```
|
|
2145
2191
|
*/
|
|
2146
|
-
const resolverZod = (0,
|
|
2192
|
+
const resolverZod = (0, _kubb_kit.createResolver)({
|
|
2147
2193
|
pluginName: "plugin-zod",
|
|
2148
2194
|
name(name) {
|
|
2149
|
-
return this.memo(`name:${name}`, () => ensureValidVarName((0,
|
|
2195
|
+
return this.memo(`name:${name}`, () => ensureValidVarName((0, _kubb_kit.camelCase)(name, { suffix: "schema" })));
|
|
2150
2196
|
},
|
|
2151
|
-
file: createCasedFile((part) => (0,
|
|
2197
|
+
file: createCasedFile((part) => (0, _kubb_kit.camelCase)(part, { suffix: "schema" })),
|
|
2152
2198
|
schema: {
|
|
2153
2199
|
typeName(name) {
|
|
2154
|
-
return this.memo(`typeName:${name}`, () => ensureValidVarName((0,
|
|
2200
|
+
return this.memo(`typeName:${name}`, () => ensureValidVarName((0, _kubb_kit.pascalCase)(name, { suffix: "schema type" })));
|
|
2155
2201
|
},
|
|
2156
2202
|
type(name) {
|
|
2157
|
-
return this.memo(`type:${name}`, () => ensureValidVarName((0,
|
|
2203
|
+
return this.memo(`type:${name}`, () => ensureValidVarName((0, _kubb_kit.pascalCase)(name, { suffix: "type" })));
|
|
2158
2204
|
},
|
|
2159
2205
|
inputName(name) {
|
|
2160
2206
|
return this.name(`${name} input`);
|
|
@@ -2163,10 +2209,10 @@ const resolverZod = (0, kubb_kit.createResolver)({
|
|
|
2163
2209
|
return this.schema.typeName(`${name} input`);
|
|
2164
2210
|
},
|
|
2165
2211
|
isName(name) {
|
|
2166
|
-
return ensureValidVarName((0,
|
|
2212
|
+
return ensureValidVarName((0, _kubb_kit.camelCase)(name, { prefix: "is" }));
|
|
2167
2213
|
},
|
|
2168
2214
|
assertName(name) {
|
|
2169
|
-
return ensureValidVarName((0,
|
|
2215
|
+
return ensureValidVarName((0, _kubb_kit.camelCase)(name, { prefix: "assert" }));
|
|
2170
2216
|
}
|
|
2171
2217
|
},
|
|
2172
2218
|
param: createOperationParamResolver(),
|
|
@@ -2220,7 +2266,7 @@ const pluginZodName = "plugin-zod";
|
|
|
2220
2266
|
* })
|
|
2221
2267
|
* ```
|
|
2222
2268
|
*/
|
|
2223
|
-
const pluginZod = (0,
|
|
2269
|
+
const pluginZod = (0, _kubb_kit.defineExtension)({
|
|
2224
2270
|
kind: "plugin",
|
|
2225
2271
|
meta: {
|
|
2226
2272
|
name: pluginZodName,
|
|
@@ -2232,9 +2278,9 @@ const pluginZod = (0, kubb_kit.defineExtension)({
|
|
|
2232
2278
|
path: "zod",
|
|
2233
2279
|
barrel: { type: "named" }
|
|
2234
2280
|
}, group, exclude = [], include, override = [], compile = false, mini = false, guidType = "uuid", regexType = "literal", oneOfType = "union", importPath = mini ? "zod/mini" : "zod", coercion = false, inferred = false, typeGuards = false, printer, resolver: userResolver, macros: userMacros } = options;
|
|
2235
|
-
(0,
|
|
2236
|
-
if (userMacros?.length) (0,
|
|
2237
|
-
(0,
|
|
2281
|
+
(0, _kubb_kit.setResolver)(userResolver ? _kubb_kit.Resolver.merge(resolverZod, userResolver) : resolverZod);
|
|
2282
|
+
if (userMacros?.length) (0, _kubb_kit.setMacros)(userMacros);
|
|
2283
|
+
(0, _kubb_kit.addGenerator)(zodGenerator);
|
|
2238
2284
|
return {
|
|
2239
2285
|
output,
|
|
2240
2286
|
exclude,
|