@kubb/plugin-zod 5.8.0-canary.20261029T124214 → 5.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +120 -120
- 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 +4 -4
- package/dist/index.js.map +1 -1
- 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()");
|
|
@@ -1343,7 +1343,7 @@ function buildZodNodes(dialect, cyclicSchemas) {
|
|
|
1343
1343
|
...buildScalarNodes(dialect),
|
|
1344
1344
|
ref(node) {
|
|
1345
1345
|
if (!node.name) return null;
|
|
1346
|
-
const refName =
|
|
1346
|
+
const refName = _kubb_kit.ast.resolveRefName(node);
|
|
1347
1347
|
if (!refName) return null;
|
|
1348
1348
|
const useInputVariant = node.ref != null && (dialect.useInputVariant?.(node, this.options) ?? false);
|
|
1349
1349
|
const resolvedName = node.ref ? useInputVariant ? this.options.resolver?.schema.inputName(refName) ?? refName : this.options.resolver?.name(refName) ?? refName : node.name;
|
|
@@ -1367,14 +1367,14 @@ function buildZodNodes(dialect, cyclicSchemas) {
|
|
|
1367
1367
|
return catchallType ? dialect.catchall(objectBase, catchallType) : objectBase;
|
|
1368
1368
|
}
|
|
1369
1369
|
if (entries.length === 0 && patterns.length === 0 && propertyNamesKeySchema && !isStrict) {
|
|
1370
|
-
const unknownType = this.transform(
|
|
1370
|
+
const unknownType = this.transform(_kubb_kit.ast.factory.createSchema({ type: _kubb_kit.ast.schemaTypes.unknown }));
|
|
1371
1371
|
return `${recordFn}(${propertyNamesKeySchema}, ${unknownType})`;
|
|
1372
1372
|
}
|
|
1373
1373
|
if (node.additionalProperties === true) return objectBase;
|
|
1374
1374
|
if (isStrict) return objectBase;
|
|
1375
1375
|
if (patterns.length > 0) {
|
|
1376
1376
|
const values = patterns.map(([, valueSchema]) => {
|
|
1377
|
-
const valueType = this.transform(valueSchema) ?? this.transform(
|
|
1377
|
+
const valueType = this.transform(valueSchema) ?? this.transform(_kubb_kit.ast.factory.createSchema({ type: _kubb_kit.ast.schemaTypes.unknown }));
|
|
1378
1378
|
return valueSchema.nullable ? dialect.nullable(valueType) : valueType;
|
|
1379
1379
|
});
|
|
1380
1380
|
const distinct = [...new Set(values)];
|
|
@@ -1391,7 +1391,7 @@ function buildZodNodes(dialect, cyclicSchemas) {
|
|
|
1391
1391
|
});
|
|
1392
1392
|
},
|
|
1393
1393
|
array(node) {
|
|
1394
|
-
const base = `z.array(${mapSchemaItems(node, (item) => this.transform(item)).map(({ output }) => output).filter(Boolean).join(", ") || this.transform(
|
|
1394
|
+
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
1395
|
...node,
|
|
1396
1396
|
regexType: this.options.regexType
|
|
1397
1397
|
})}`;
|
|
@@ -1415,7 +1415,7 @@ function buildZodNodes(dialect, cyclicSchemas) {
|
|
|
1415
1415
|
intersection(node) {
|
|
1416
1416
|
const members = node.members ?? [];
|
|
1417
1417
|
if (members.length === 0) return "";
|
|
1418
|
-
const hasSiblingProperties = members.some((member) => member.type ===
|
|
1418
|
+
const hasSiblingProperties = members.some((member) => member.type === _kubb_kit.ast.schemaTypes.object && member.properties.length > 0);
|
|
1419
1419
|
const transform = (member) => {
|
|
1420
1420
|
if (!hasSiblingProperties) return this.transform(member);
|
|
1421
1421
|
unionsWithSiblings.add(member);
|
|
@@ -1446,13 +1446,13 @@ function buildZodNodes(dialect, cyclicSchemas) {
|
|
|
1446
1446
|
}
|
|
1447
1447
|
// src/printers/printerZod.ts
|
|
1448
1448
|
function strictOneOfMember(member, node, cyclicSchemas) {
|
|
1449
|
-
if (node.type ===
|
|
1449
|
+
if (node.type === _kubb_kit.ast.schemaTypes.ref) {
|
|
1450
1450
|
if (member.startsWith("z.lazy(")) return member;
|
|
1451
|
-
const refName =
|
|
1451
|
+
const refName = _kubb_kit.ast.resolveRefName(node);
|
|
1452
1452
|
if (refName && cyclicSchemas?.has(refName)) return member;
|
|
1453
|
-
const schema = (0,
|
|
1453
|
+
const schema = (0, _kubb_kit.syncSchemaRef)(node);
|
|
1454
1454
|
if (schema.nullable || schema.optional || node.nullable || node.optional) return member;
|
|
1455
|
-
if (schema.type ===
|
|
1455
|
+
if (schema.type === _kubb_kit.ast.schemaTypes.object && (schema.additionalProperties === void 0 || schema.additionalProperties === false)) return `${member}.strict()`;
|
|
1456
1456
|
}
|
|
1457
1457
|
return member;
|
|
1458
1458
|
}
|
|
@@ -1468,7 +1468,7 @@ function buildZodObjectShape(ctx, node) {
|
|
|
1468
1468
|
optional: schema.optional || required === false,
|
|
1469
1469
|
nullish: schema.nullish,
|
|
1470
1470
|
defaultValue: meta.default,
|
|
1471
|
-
description: schema.type !==
|
|
1471
|
+
description: schema.type !== _kubb_kit.ast.schemaTypes.ref && meta.type === _kubb_kit.ast.schemaTypes.ref ? void 0 : meta.description,
|
|
1472
1472
|
examples: meta.examples
|
|
1473
1473
|
});
|
|
1474
1474
|
if (!cyclic) return `${objectKey(name)}: ${body}`;
|
|
@@ -1489,21 +1489,21 @@ function buildZodObjectShape(ctx, node) {
|
|
|
1489
1489
|
function recursiveGetterType({ ctx, schema, required }) {
|
|
1490
1490
|
function baseType(schema) {
|
|
1491
1491
|
if (ctx.options.nodes?.[schema.type]) return void 0;
|
|
1492
|
-
if (schema.type ===
|
|
1492
|
+
if (schema.type === _kubb_kit.ast.schemaTypes.ref) {
|
|
1493
1493
|
const saved = ctx.options.cyclicSchemas;
|
|
1494
1494
|
ctx.options.cyclicSchemas = void 0;
|
|
1495
1495
|
const name = ctx.transform(schema);
|
|
1496
1496
|
ctx.options.cyclicSchemas = saved;
|
|
1497
1497
|
return name ? `typeof ${name}` : void 0;
|
|
1498
1498
|
}
|
|
1499
|
-
if (schema.type ===
|
|
1499
|
+
if (schema.type === _kubb_kit.ast.schemaTypes.array && schema.items?.length === 1) {
|
|
1500
1500
|
const item = baseType(schema.items[0]);
|
|
1501
1501
|
return item ? `z.ZodArray<${item}>` : void 0;
|
|
1502
1502
|
}
|
|
1503
1503
|
}
|
|
1504
1504
|
const base = baseType(schema);
|
|
1505
1505
|
if (!base) return void 0;
|
|
1506
|
-
const meta = (0,
|
|
1506
|
+
const meta = (0, _kubb_kit.syncSchemaRef)(schema);
|
|
1507
1507
|
const optional = schema.optional || required === false;
|
|
1508
1508
|
const wrapped = (() => {
|
|
1509
1509
|
if (schema.nullish || meta.nullable && optional) return `z.ZodOptional<z.ZodNullable<${base}>>`;
|
|
@@ -1518,12 +1518,12 @@ function recursiveGetterType({ ctx, schema, required }) {
|
|
|
1518
1518
|
* `direction` themselves, so {@link containsDirectionalNode} probes their children instead.
|
|
1519
1519
|
*/
|
|
1520
1520
|
const CONTAINER_TYPES = /* @__PURE__ */ new Set([
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1521
|
+
_kubb_kit.ast.schemaTypes.object,
|
|
1522
|
+
_kubb_kit.ast.schemaTypes.array,
|
|
1523
|
+
_kubb_kit.ast.schemaTypes.tuple,
|
|
1524
|
+
_kubb_kit.ast.schemaTypes.union,
|
|
1525
|
+
_kubb_kit.ast.schemaTypes.intersection,
|
|
1526
|
+
_kubb_kit.ast.schemaTypes.ref
|
|
1527
1527
|
]);
|
|
1528
1528
|
/**
|
|
1529
1529
|
* Runs the node's effective handler (a `printer.nodes` override, else the built-in) once per
|
|
@@ -1554,7 +1554,7 @@ function variesByDirection({ node, printerOptions }) {
|
|
|
1554
1554
|
*/
|
|
1555
1555
|
function containsDirectionalNode({ node, printerOptions }) {
|
|
1556
1556
|
if (!node) return false;
|
|
1557
|
-
return
|
|
1557
|
+
return _kubb_kit.ast.findSchema(node, {
|
|
1558
1558
|
predicate: (schema) => variesByDirection({
|
|
1559
1559
|
node: schema,
|
|
1560
1560
|
printerOptions
|
|
@@ -1566,10 +1566,10 @@ function containsDirectionalNode({ node, printerOptions }) {
|
|
|
1566
1566
|
* Names of the `$ref` schemas the generator should route to their input (encode) variant.
|
|
1567
1567
|
*/
|
|
1568
1568
|
function collectDirectionalRefNames({ node, printerOptions }) {
|
|
1569
|
-
return
|
|
1569
|
+
return _kubb_kit.ast.collectSync(node, { schema: (n) => n.type === _kubb_kit.ast.schemaTypes.ref && n.ref && containsDirectionalNode({
|
|
1570
1570
|
node: n,
|
|
1571
1571
|
printerOptions
|
|
1572
|
-
}) ?
|
|
1572
|
+
}) ? _kubb_kit.ast.resolveRefName(n) ?? void 0 : void 0 });
|
|
1573
1573
|
}
|
|
1574
1574
|
/**
|
|
1575
1575
|
* Handlers that never recurse into children, so {@link variesByDirection} can call one directly
|
|
@@ -1635,7 +1635,7 @@ const scalarNodes = {
|
|
|
1635
1635
|
* const code = printer.print(stringNode) // "z.string()"
|
|
1636
1636
|
* ```
|
|
1637
1637
|
*/
|
|
1638
|
-
const printerZod =
|
|
1638
|
+
const printerZod = _kubb_kit.ast.createPrinter((options) => {
|
|
1639
1639
|
return {
|
|
1640
1640
|
name: "zod",
|
|
1641
1641
|
options,
|
|
@@ -1702,7 +1702,7 @@ const miniDialect = {
|
|
|
1702
1702
|
extend: (base, shape) => `z.extend(${base}, ${shape})`,
|
|
1703
1703
|
intersection: (left, right) => `z.intersection(${left}, ${right})`
|
|
1704
1704
|
};
|
|
1705
|
-
const printerZodMini =
|
|
1705
|
+
const printerZodMini = _kubb_kit.ast.createPrinter((options) => {
|
|
1706
1706
|
return {
|
|
1707
1707
|
name: "zod-mini",
|
|
1708
1708
|
options,
|
|
@@ -1777,9 +1777,9 @@ function getPrinter(resolver, options, mini, direction) {
|
|
|
1777
1777
|
* When `mini: true`, schemas use the Zod Mini functional API instead of
|
|
1778
1778
|
* chainable methods.
|
|
1779
1779
|
*/
|
|
1780
|
-
const zodGenerator = (0,
|
|
1780
|
+
const zodGenerator = (0, _kubb_kit.defineGenerator)({
|
|
1781
1781
|
name: "zod",
|
|
1782
|
-
renderer:
|
|
1782
|
+
renderer: _kubb_renderer_jsx.jsxRenderer,
|
|
1783
1783
|
schema(node, ctx) {
|
|
1784
1784
|
const { adapter, config, resolver, root } = ctx;
|
|
1785
1785
|
const { output, coercion, guidType, regexType, oneOfType, compile, mini, inferred, typeGuards, importPath, group, printer } = ctx.options;
|
|
@@ -1835,7 +1835,7 @@ const zodGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
1835
1835
|
const isName = typeGuards ? resolver.schema.isName(node.name) : null;
|
|
1836
1836
|
const assertName = typeGuards ? resolver.schema.assertName(node.name) : null;
|
|
1837
1837
|
const schemaPrinter = getPrinter(resolver, printerOptions, mini, "decode");
|
|
1838
|
-
return /* @__PURE__ */ (0,
|
|
1838
|
+
return /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsxs)(_kubb_renderer_jsx.File, {
|
|
1839
1839
|
baseName: meta.file.baseName,
|
|
1840
1840
|
path: meta.file.path,
|
|
1841
1841
|
meta: meta.file.meta,
|
|
@@ -1856,12 +1856,12 @@ const zodGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
1856
1856
|
}
|
|
1857
1857
|
}),
|
|
1858
1858
|
children: [
|
|
1859
|
-
/* @__PURE__ */ (0,
|
|
1859
|
+
/* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Import, {
|
|
1860
1860
|
name: isZodImport ? "z" : ["z"],
|
|
1861
1861
|
path: importPath,
|
|
1862
1862
|
isNameSpace: isZodImport
|
|
1863
1863
|
}),
|
|
1864
|
-
imports.map((imp) => /* @__PURE__ */ (0,
|
|
1864
|
+
imports.map((imp) => /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Import, {
|
|
1865
1865
|
root: meta.file.path,
|
|
1866
1866
|
path: imp.path,
|
|
1867
1867
|
name: imp.name
|
|
@@ -1870,7 +1870,7 @@ const zodGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
1870
1870
|
imp.path,
|
|
1871
1871
|
imp.name
|
|
1872
1872
|
].join("-"))),
|
|
1873
|
-
/* @__PURE__ */ (0,
|
|
1873
|
+
/* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(Zod, {
|
|
1874
1874
|
name: meta.name,
|
|
1875
1875
|
node,
|
|
1876
1876
|
printer: schemaPrinter,
|
|
@@ -1883,7 +1883,7 @@ const zodGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
1883
1883
|
cyclic: cyclicSchemas.has(node.name),
|
|
1884
1884
|
compile
|
|
1885
1885
|
}),
|
|
1886
|
-
hasDirectionalNode && /* @__PURE__ */ (0,
|
|
1886
|
+
hasDirectionalNode && /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(Zod, {
|
|
1887
1887
|
name: resolver.schema.inputName(node.name),
|
|
1888
1888
|
node,
|
|
1889
1889
|
printer: getPrinter(resolver, printerOptions, mini, "encode"),
|
|
@@ -1900,7 +1900,7 @@ const zodGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
1900
1900
|
});
|
|
1901
1901
|
},
|
|
1902
1902
|
operation(node, ctx) {
|
|
1903
|
-
if (!
|
|
1903
|
+
if (!_kubb_kit.ast.isHttpOperationNode(node)) return null;
|
|
1904
1904
|
const { adapter, config, resolver, root } = ctx;
|
|
1905
1905
|
const { output, coercion, guidType, regexType, oneOfType, compile, mini, inferred, importPath, group, printer } = ctx.options;
|
|
1906
1906
|
const dateType = getOasAdapter(adapter).options.dateType;
|
|
@@ -1941,7 +1941,7 @@ const zodGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
1941
1941
|
...printerOptions,
|
|
1942
1942
|
keysToOmit
|
|
1943
1943
|
}, mini, direction);
|
|
1944
|
-
return /* @__PURE__ */ (0,
|
|
1944
|
+
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
1945
|
root: meta.file.path,
|
|
1946
1946
|
path: imp.path,
|
|
1947
1947
|
name: imp.name
|
|
@@ -1949,7 +1949,7 @@ const zodGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
1949
1949
|
name,
|
|
1950
1950
|
imp.path,
|
|
1951
1951
|
imp.name
|
|
1952
|
-
].join("-"))), /* @__PURE__ */ (0,
|
|
1952
|
+
].join("-"))), /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(Zod, {
|
|
1953
1953
|
name,
|
|
1954
1954
|
node: schema,
|
|
1955
1955
|
printer: schemaPrinter,
|
|
@@ -1961,14 +1961,14 @@ const zodGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
1961
1961
|
}
|
|
1962
1962
|
function buildContentTypeVariants(entries, baseName, decorate, direction) {
|
|
1963
1963
|
const variants = resolveContentTypeVariants(entries, baseName);
|
|
1964
|
-
const unionSchema =
|
|
1964
|
+
const unionSchema = _kubb_kit.ast.factory.createSchema({
|
|
1965
1965
|
type: "union",
|
|
1966
|
-
members: variants.map((variant) =>
|
|
1966
|
+
members: variants.map((variant) => _kubb_kit.ast.factory.createSchema({
|
|
1967
1967
|
type: "ref",
|
|
1968
1968
|
name: variant.name
|
|
1969
1969
|
}))
|
|
1970
1970
|
});
|
|
1971
|
-
return /* @__PURE__ */ (0,
|
|
1971
|
+
return /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsxs)(_kubb_renderer_jsx_jsx_runtime.Fragment, { children: [variants.map((variant) => renderSchemaEntry({
|
|
1972
1972
|
schema: decorate ? decorate(variant.schema) : variant.schema,
|
|
1973
1973
|
name: variant.name,
|
|
1974
1974
|
keysToOmit: variant.keysToOmit,
|
|
@@ -1980,17 +1980,17 @@ const zodGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
1980
1980
|
})] });
|
|
1981
1981
|
}
|
|
1982
1982
|
function buildResponseUnion({ responses, name, fallbackUnknown }) {
|
|
1983
|
-
if (new Set(responses.flatMap((res) => (res.content ?? []).flatMap((entry) => entry.schema ?
|
|
1984
|
-
const members = responses.map((res) =>
|
|
1983
|
+
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;
|
|
1984
|
+
const members = responses.map((res) => _kubb_kit.ast.factory.createSchema({
|
|
1985
1985
|
type: "ref",
|
|
1986
1986
|
name: resolver.response.status(node, res.statusCode)
|
|
1987
1987
|
}));
|
|
1988
1988
|
if (fallbackUnknown && members.length === 0) return renderSchemaEntry({
|
|
1989
|
-
schema:
|
|
1989
|
+
schema: _kubb_kit.ast.factory.createSchema({ type: "unknown" }),
|
|
1990
1990
|
name
|
|
1991
1991
|
});
|
|
1992
1992
|
return renderSchemaEntry({
|
|
1993
|
-
schema: members.length === 1 ? members[0] :
|
|
1993
|
+
schema: members.length === 1 ? members[0] : _kubb_kit.ast.factory.createSchema({
|
|
1994
1994
|
type: "union",
|
|
1995
1995
|
members
|
|
1996
1996
|
}),
|
|
@@ -2061,10 +2061,10 @@ const zodGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
2061
2061
|
params: header
|
|
2062
2062
|
}
|
|
2063
2063
|
].filter(({ params }) => params.length > 0).map(({ kind, params }) => renderSchemaEntry({
|
|
2064
|
-
schema:
|
|
2064
|
+
schema: _kubb_kit.ast.factory.createSchema({
|
|
2065
2065
|
type: "object",
|
|
2066
2066
|
primitive: "object",
|
|
2067
|
-
properties: params.map((param) =>
|
|
2067
|
+
properties: params.map((param) => _kubb_kit.ast.factory.createProperty({
|
|
2068
2068
|
name: param.name,
|
|
2069
2069
|
required: param.required,
|
|
2070
2070
|
schema: param.schema
|
|
@@ -2082,7 +2082,7 @@ const zodGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
2082
2082
|
schema: buildResponses(node, resolver),
|
|
2083
2083
|
name: resolver.response.responses(node)
|
|
2084
2084
|
}) : null;
|
|
2085
|
-
return /* @__PURE__ */ (0,
|
|
2085
|
+
return /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsxs)(_kubb_renderer_jsx.File, {
|
|
2086
2086
|
baseName: meta.file.baseName,
|
|
2087
2087
|
path: meta.file.path,
|
|
2088
2088
|
meta: meta.file.meta,
|
|
@@ -2103,7 +2103,7 @@ const zodGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
2103
2103
|
}
|
|
2104
2104
|
}),
|
|
2105
2105
|
children: [
|
|
2106
|
-
/* @__PURE__ */ (0,
|
|
2106
|
+
/* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Import, {
|
|
2107
2107
|
name: isZodImport ? "z" : ["z"],
|
|
2108
2108
|
path: importPath,
|
|
2109
2109
|
isNameSpace: isZodImport
|
|
@@ -2126,7 +2126,7 @@ var compatibility = {
|
|
|
2126
2126
|
"node": ">=22.22"
|
|
2127
2127
|
};
|
|
2128
2128
|
// package.json
|
|
2129
|
-
var version = "5.8.0
|
|
2129
|
+
var version = "5.8.0";
|
|
2130
2130
|
// src/resolvers/resolverZod.ts
|
|
2131
2131
|
/**
|
|
2132
2132
|
* Default resolver used by `@kubb/plugin-zod`. Decides the names and file
|
|
@@ -2143,18 +2143,18 @@ var version = "5.8.0-canary.20261029T124214";
|
|
|
2143
2143
|
* resolverZod.schema.typeName('pet') // 'PetSchemaType'
|
|
2144
2144
|
* ```
|
|
2145
2145
|
*/
|
|
2146
|
-
const resolverZod = (0,
|
|
2146
|
+
const resolverZod = (0, _kubb_kit.createResolver)({
|
|
2147
2147
|
pluginName: "plugin-zod",
|
|
2148
2148
|
name(name) {
|
|
2149
|
-
return this.memo(`name:${name}`, () => ensureValidVarName((0,
|
|
2149
|
+
return this.memo(`name:${name}`, () => ensureValidVarName((0, _kubb_kit.camelCase)(name, { suffix: "schema" })));
|
|
2150
2150
|
},
|
|
2151
|
-
file: createCasedFile((part) => (0,
|
|
2151
|
+
file: createCasedFile((part) => (0, _kubb_kit.camelCase)(part, { suffix: "schema" })),
|
|
2152
2152
|
schema: {
|
|
2153
2153
|
typeName(name) {
|
|
2154
|
-
return this.memo(`typeName:${name}`, () => ensureValidVarName((0,
|
|
2154
|
+
return this.memo(`typeName:${name}`, () => ensureValidVarName((0, _kubb_kit.pascalCase)(name, { suffix: "schema type" })));
|
|
2155
2155
|
},
|
|
2156
2156
|
type(name) {
|
|
2157
|
-
return this.memo(`type:${name}`, () => ensureValidVarName((0,
|
|
2157
|
+
return this.memo(`type:${name}`, () => ensureValidVarName((0, _kubb_kit.pascalCase)(name, { suffix: "type" })));
|
|
2158
2158
|
},
|
|
2159
2159
|
inputName(name) {
|
|
2160
2160
|
return this.name(`${name} input`);
|
|
@@ -2163,10 +2163,10 @@ const resolverZod = (0, kubb_kit.createResolver)({
|
|
|
2163
2163
|
return this.schema.typeName(`${name} input`);
|
|
2164
2164
|
},
|
|
2165
2165
|
isName(name) {
|
|
2166
|
-
return ensureValidVarName((0,
|
|
2166
|
+
return ensureValidVarName((0, _kubb_kit.camelCase)(name, { prefix: "is" }));
|
|
2167
2167
|
},
|
|
2168
2168
|
assertName(name) {
|
|
2169
|
-
return ensureValidVarName((0,
|
|
2169
|
+
return ensureValidVarName((0, _kubb_kit.camelCase)(name, { prefix: "assert" }));
|
|
2170
2170
|
}
|
|
2171
2171
|
},
|
|
2172
2172
|
param: createOperationParamResolver(),
|
|
@@ -2220,7 +2220,7 @@ const pluginZodName = "plugin-zod";
|
|
|
2220
2220
|
* })
|
|
2221
2221
|
* ```
|
|
2222
2222
|
*/
|
|
2223
|
-
const pluginZod = (0,
|
|
2223
|
+
const pluginZod = (0, _kubb_kit.defineExtension)({
|
|
2224
2224
|
kind: "plugin",
|
|
2225
2225
|
meta: {
|
|
2226
2226
|
name: pluginZodName,
|
|
@@ -2232,9 +2232,9 @@ const pluginZod = (0, kubb_kit.defineExtension)({
|
|
|
2232
2232
|
path: "zod",
|
|
2233
2233
|
barrel: { type: "named" }
|
|
2234
2234
|
}, 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,
|
|
2235
|
+
(0, _kubb_kit.setResolver)(userResolver ? _kubb_kit.Resolver.merge(resolverZod, userResolver) : resolverZod);
|
|
2236
|
+
if (userMacros?.length) (0, _kubb_kit.setMacros)(userMacros);
|
|
2237
|
+
(0, _kubb_kit.addGenerator)(zodGenerator);
|
|
2238
2238
|
return {
|
|
2239
2239
|
output,
|
|
2240
2240
|
exclude,
|