@kubb/plugin-zod 5.0.0-alpha.33 → 5.0.0-alpha.35
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 +94 -161
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +15 -18
- package/dist/index.js +96 -163
- package/dist/index.js.map +1 -1
- package/package.json +4 -5
- package/src/components/Operations.tsx +2 -2
- package/src/components/Zod.tsx +3 -4
- package/src/generators/zodGenerator.tsx +17 -18
- package/src/generators/zodGeneratorLegacy.tsx +47 -48
- package/src/plugin.ts +50 -84
- package/src/printers/printerZod.ts +11 -11
- package/src/printers/printerZodMini.ts +10 -10
- package/src/types.ts +10 -11
- package/src/utils.ts +9 -10
- package/src/presets.ts +0 -30
package/dist/index.cjs
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
//#endregion
|
|
3
|
-
let _kubb_ast = require("@kubb/ast");
|
|
4
3
|
let _kubb_core = require("@kubb/core");
|
|
5
4
|
let _kubb_renderer_jsx = require("@kubb/renderer-jsx");
|
|
6
5
|
let _kubb_renderer_jsx_jsx_runtime = require("@kubb/renderer-jsx/jsx-runtime");
|
|
@@ -373,7 +372,7 @@ function containsSelfRef(node, { schemaName, resolver, visited = /* @__PURE__ */
|
|
|
373
372
|
if (visited.has(node)) return false;
|
|
374
373
|
visited.add(node);
|
|
375
374
|
if (node.type === "ref" && node.ref) {
|
|
376
|
-
const rawName =
|
|
375
|
+
const rawName = _kubb_core.ast.extractRefName(node.ref) ?? node.name;
|
|
377
376
|
return (rawName ? resolver?.default(rawName, "function") ?? rawName : node.name) === schemaName;
|
|
378
377
|
}
|
|
379
378
|
if (node.type === "object") {
|
|
@@ -476,7 +475,7 @@ const printerZod = (0, _kubb_core.definePrinter)((options) => {
|
|
|
476
475
|
},
|
|
477
476
|
ref(node) {
|
|
478
477
|
if (!node.name) return void 0;
|
|
479
|
-
const refName = node.ref ?
|
|
478
|
+
const refName = node.ref ? _kubb_core.ast.extractRefName(node.ref) ?? node.name : node.name;
|
|
480
479
|
const resolvedName = node.ref ? this.options.resolver?.default(refName, "function") ?? refName : node.name;
|
|
481
480
|
if (node.ref && this.options.schemaName != null && resolvedName === this.options.schemaName) return `z.lazy(() => ${resolvedName})`;
|
|
482
481
|
return resolvedName;
|
|
@@ -484,7 +483,7 @@ const printerZod = (0, _kubb_core.definePrinter)((options) => {
|
|
|
484
483
|
object(node) {
|
|
485
484
|
let result = `z.object({\n ${node.properties.map((prop) => {
|
|
486
485
|
const { name: propName, schema } = prop;
|
|
487
|
-
const meta =
|
|
486
|
+
const meta = _kubb_core.ast.syncSchemaRef(schema);
|
|
488
487
|
const isNullable = meta.nullable;
|
|
489
488
|
const isOptional = schema.optional;
|
|
490
489
|
const isNullish = schema.nullish;
|
|
@@ -492,7 +491,7 @@ const printerZod = (0, _kubb_core.definePrinter)((options) => {
|
|
|
492
491
|
schemaName: this.options.schemaName,
|
|
493
492
|
resolver: this.options.resolver
|
|
494
493
|
});
|
|
495
|
-
const baseOutput = this.transform(schema) ?? this.transform(
|
|
494
|
+
const baseOutput = this.transform(schema) ?? this.transform(_kubb_core.ast.createSchema({ type: "unknown" }));
|
|
496
495
|
const resolvedOutput = hasSelfRef ? baseOutput.replaceAll(`z.lazy(() => ${this.options.schemaName})`, this.options.schemaName) : baseOutput;
|
|
497
496
|
const value = applyModifiers({
|
|
498
497
|
value: this.options.wrapOutput ? this.options.wrapOutput({
|
|
@@ -511,12 +510,12 @@ const printerZod = (0, _kubb_core.definePrinter)((options) => {
|
|
|
511
510
|
if (node.additionalProperties && node.additionalProperties !== true) {
|
|
512
511
|
const catchallType = this.transform(node.additionalProperties);
|
|
513
512
|
if (catchallType) result += `.catchall(${catchallType})`;
|
|
514
|
-
} else if (node.additionalProperties === true) result += `.catchall(${this.transform(
|
|
513
|
+
} else if (node.additionalProperties === true) result += `.catchall(${this.transform(_kubb_core.ast.createSchema({ type: "unknown" }))})`;
|
|
515
514
|
else if (node.additionalProperties === false) result += ".strict()";
|
|
516
515
|
return result;
|
|
517
516
|
},
|
|
518
517
|
array(node) {
|
|
519
|
-
let result = `z.array(${(node.items ?? []).map((item) => this.transform(item)).filter(Boolean).join(", ") || this.transform(
|
|
518
|
+
let result = `z.array(${(node.items ?? []).map((item) => this.transform(item)).filter(Boolean).join(", ") || this.transform(_kubb_core.ast.createSchema({ type: "unknown" }))})${lengthConstraints(node)}`;
|
|
520
519
|
if (node.unique) result += `.refine(items => new Set(items).size === items.length, { message: "Array entries must be unique" })`;
|
|
521
520
|
return result;
|
|
522
521
|
},
|
|
@@ -540,19 +539,19 @@ const printerZod = (0, _kubb_core.definePrinter)((options) => {
|
|
|
540
539
|
if (!base) return "";
|
|
541
540
|
for (const member of rest) {
|
|
542
541
|
if (member.primitive === "string") {
|
|
543
|
-
const c = lengthConstraints(
|
|
542
|
+
const c = lengthConstraints(_kubb_core.ast.narrowSchema(member, "string") ?? {});
|
|
544
543
|
if (c) {
|
|
545
544
|
base += c;
|
|
546
545
|
continue;
|
|
547
546
|
}
|
|
548
547
|
} else if (member.primitive === "number" || member.primitive === "integer") {
|
|
549
|
-
const c = numberConstraints(
|
|
548
|
+
const c = numberConstraints(_kubb_core.ast.narrowSchema(member, "number") ?? _kubb_core.ast.narrowSchema(member, "integer") ?? {});
|
|
550
549
|
if (c) {
|
|
551
550
|
base += c;
|
|
552
551
|
continue;
|
|
553
552
|
}
|
|
554
553
|
} else if (member.primitive === "array") {
|
|
555
|
-
const c = lengthConstraints(
|
|
554
|
+
const c = lengthConstraints(_kubb_core.ast.narrowSchema(member, "array") ?? {});
|
|
556
555
|
if (c) {
|
|
557
556
|
base += c;
|
|
558
557
|
continue;
|
|
@@ -569,7 +568,7 @@ const printerZod = (0, _kubb_core.definePrinter)((options) => {
|
|
|
569
568
|
const { keysToOmit } = this.options;
|
|
570
569
|
let base = this.transform(node);
|
|
571
570
|
if (!base) return null;
|
|
572
|
-
const meta =
|
|
571
|
+
const meta = _kubb_core.ast.syncSchemaRef(node);
|
|
573
572
|
if (keysToOmit?.length && meta.primitive === "object" && !(meta.type === "union" && meta.discriminatorPropertyName)) base = `${base}.omit({ ${keysToOmit.map((k) => `"${k}": true`).join(", ")} })`;
|
|
574
573
|
return applyModifiers({
|
|
575
574
|
value: base,
|
|
@@ -655,7 +654,7 @@ const printerZodMini = (0, _kubb_core.definePrinter)((options) => {
|
|
|
655
654
|
},
|
|
656
655
|
ref(node) {
|
|
657
656
|
if (!node.name) return void 0;
|
|
658
|
-
const refName = node.ref ?
|
|
657
|
+
const refName = node.ref ? _kubb_core.ast.extractRefName(node.ref) ?? node.name : node.name;
|
|
659
658
|
const resolvedName = node.ref ? this.options.resolver?.default(refName, "function") ?? refName : node.name;
|
|
660
659
|
if (node.ref && this.options.schemaName != null && resolvedName === this.options.schemaName) return `z.lazy(() => ${resolvedName})`;
|
|
661
660
|
return resolvedName;
|
|
@@ -663,7 +662,7 @@ const printerZodMini = (0, _kubb_core.definePrinter)((options) => {
|
|
|
663
662
|
object(node) {
|
|
664
663
|
return `z.object({\n ${node.properties.map((prop) => {
|
|
665
664
|
const { name: propName, schema } = prop;
|
|
666
|
-
const meta =
|
|
665
|
+
const meta = _kubb_core.ast.syncSchemaRef(schema);
|
|
667
666
|
const isNullable = meta.nullable;
|
|
668
667
|
const isOptional = schema.optional;
|
|
669
668
|
const isNullish = schema.nullish;
|
|
@@ -671,7 +670,7 @@ const printerZodMini = (0, _kubb_core.definePrinter)((options) => {
|
|
|
671
670
|
schemaName: this.options.schemaName,
|
|
672
671
|
resolver: this.options.resolver
|
|
673
672
|
});
|
|
674
|
-
const baseOutput = this.transform(schema) ?? this.transform(
|
|
673
|
+
const baseOutput = this.transform(schema) ?? this.transform(_kubb_core.ast.createSchema({ type: "unknown" }));
|
|
675
674
|
const resolvedOutput = hasSelfRef ? baseOutput.replaceAll(`z.lazy(() => ${this.options.schemaName})`, this.options.schemaName) : baseOutput;
|
|
676
675
|
const value = applyMiniModifiers({
|
|
677
676
|
value: this.options.wrapOutput ? this.options.wrapOutput({
|
|
@@ -688,7 +687,7 @@ const printerZodMini = (0, _kubb_core.definePrinter)((options) => {
|
|
|
688
687
|
}).join(",\n ")}\n })`;
|
|
689
688
|
},
|
|
690
689
|
array(node) {
|
|
691
|
-
let result = `z.array(${(node.items ?? []).map((item) => this.transform(item)).filter(Boolean).join(", ") || this.transform(
|
|
690
|
+
let result = `z.array(${(node.items ?? []).map((item) => this.transform(item)).filter(Boolean).join(", ") || this.transform(_kubb_core.ast.createSchema({ type: "unknown" }))})${lengthChecksMini(node)}`;
|
|
692
691
|
if (node.unique) result += `.refine(items => new Set(items).size === items.length, { message: "Array entries must be unique" })`;
|
|
693
692
|
return result;
|
|
694
693
|
},
|
|
@@ -712,19 +711,19 @@ const printerZodMini = (0, _kubb_core.definePrinter)((options) => {
|
|
|
712
711
|
if (!base) return "";
|
|
713
712
|
for (const member of rest) {
|
|
714
713
|
if (member.primitive === "string") {
|
|
715
|
-
const c = lengthChecksMini(
|
|
714
|
+
const c = lengthChecksMini(_kubb_core.ast.narrowSchema(member, "string") ?? {});
|
|
716
715
|
if (c) {
|
|
717
716
|
base += c;
|
|
718
717
|
continue;
|
|
719
718
|
}
|
|
720
719
|
} else if (member.primitive === "number" || member.primitive === "integer") {
|
|
721
|
-
const c = numberChecksMini(
|
|
720
|
+
const c = numberChecksMini(_kubb_core.ast.narrowSchema(member, "number") ?? _kubb_core.ast.narrowSchema(member, "integer") ?? {});
|
|
722
721
|
if (c) {
|
|
723
722
|
base += c;
|
|
724
723
|
continue;
|
|
725
724
|
}
|
|
726
725
|
} else if (member.primitive === "array") {
|
|
727
|
-
const c = lengthChecksMini(
|
|
726
|
+
const c = lengthChecksMini(_kubb_core.ast.narrowSchema(member, "array") ?? {});
|
|
728
727
|
if (c) {
|
|
729
728
|
base += c;
|
|
730
729
|
continue;
|
|
@@ -741,7 +740,7 @@ const printerZodMini = (0, _kubb_core.definePrinter)((options) => {
|
|
|
741
740
|
const { keysToOmit } = this.options;
|
|
742
741
|
let base = this.transform(node);
|
|
743
742
|
if (!base) return null;
|
|
744
|
-
const meta =
|
|
743
|
+
const meta = _kubb_core.ast.syncSchemaRef(node);
|
|
745
744
|
if (keysToOmit?.length && meta.primitive === "object" && !(meta.type === "union" && meta.discriminatorPropertyName)) base = `${base}.omit({ ${keysToOmit.map((k) => `"${k}": true`).join(", ")} })`;
|
|
746
745
|
return applyMiniModifiers({
|
|
747
746
|
value: base,
|
|
@@ -757,11 +756,12 @@ const printerZodMini = (0, _kubb_core.definePrinter)((options) => {
|
|
|
757
756
|
//#region src/generators/zodGenerator.tsx
|
|
758
757
|
const zodGenerator = (0, _kubb_core.defineGenerator)({
|
|
759
758
|
name: "zod",
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
const {
|
|
759
|
+
renderer: _kubb_renderer_jsx.jsxRenderer,
|
|
760
|
+
schema(node, ctx) {
|
|
761
|
+
const { adapter, config, resolver, root } = ctx;
|
|
762
|
+
const { output, coercion, guidType, mini, wrapOutput, inferred, importPath, group, printer } = ctx.options;
|
|
763
763
|
if (!node.name) return;
|
|
764
|
-
const mode =
|
|
764
|
+
const mode = ctx.getMode(output);
|
|
765
765
|
const isZodImport = ZOD_NAMESPACE_IMPORTS.has(importPath);
|
|
766
766
|
const imports = adapter.getImports(node, (schemaName) => ({
|
|
767
767
|
name: resolver.resolveSchemaName(schemaName),
|
|
@@ -832,12 +832,12 @@ const zodGenerator = (0, _kubb_core.defineGenerator)({
|
|
|
832
832
|
]
|
|
833
833
|
});
|
|
834
834
|
},
|
|
835
|
-
operation(node,
|
|
836
|
-
const { adapter, config, resolver, root } =
|
|
837
|
-
const { output, coercion, guidType, mini, wrapOutput, inferred, importPath, group, paramsCasing, printer } = options;
|
|
838
|
-
const mode =
|
|
835
|
+
operation(node, ctx) {
|
|
836
|
+
const { adapter, config, resolver, root } = ctx;
|
|
837
|
+
const { output, coercion, guidType, mini, wrapOutput, inferred, importPath, group, paramsCasing, printer } = ctx.options;
|
|
838
|
+
const mode = ctx.getMode(output);
|
|
839
839
|
const isZodImport = ZOD_NAMESPACE_IMPORTS.has(importPath);
|
|
840
|
-
const params =
|
|
840
|
+
const params = _kubb_core.ast.caseParams(node.parameters, paramsCasing);
|
|
841
841
|
const meta = { file: resolver.resolveFile({
|
|
842
842
|
name: node.operationId,
|
|
843
843
|
extname: ".ts",
|
|
@@ -934,9 +934,9 @@ const zodGenerator = (0, _kubb_core.defineGenerator)({
|
|
|
934
934
|
]
|
|
935
935
|
});
|
|
936
936
|
},
|
|
937
|
-
operations(nodes,
|
|
938
|
-
const { adapter, config, resolver, root } =
|
|
939
|
-
const { output, importPath, group, operations, paramsCasing } = options;
|
|
937
|
+
operations(nodes, ctx) {
|
|
938
|
+
const { adapter, config, resolver, root } = ctx;
|
|
939
|
+
const { output, importPath, group, operations, paramsCasing } = ctx.options;
|
|
940
940
|
if (!operations) return;
|
|
941
941
|
const isZodImport = ZOD_NAMESPACE_IMPORTS.has(importPath);
|
|
942
942
|
const meta = { file: resolver.resolveFile({
|
|
@@ -951,7 +951,7 @@ const zodGenerator = (0, _kubb_core.defineGenerator)({
|
|
|
951
951
|
return {
|
|
952
952
|
node,
|
|
953
953
|
data: buildSchemaNames(node, {
|
|
954
|
-
params:
|
|
954
|
+
params: _kubb_core.ast.caseParams(node.parameters, paramsCasing),
|
|
955
955
|
resolver
|
|
956
956
|
})
|
|
957
957
|
};
|
|
@@ -1009,12 +1009,12 @@ const zodGenerator = (0, _kubb_core.defineGenerator)({
|
|
|
1009
1009
|
//#endregion
|
|
1010
1010
|
//#region src/generators/zodGeneratorLegacy.tsx
|
|
1011
1011
|
function buildGroupedParamsSchema({ params, optional }) {
|
|
1012
|
-
return
|
|
1012
|
+
return _kubb_core.ast.createSchema({
|
|
1013
1013
|
type: "object",
|
|
1014
1014
|
optional,
|
|
1015
1015
|
primitive: "object",
|
|
1016
1016
|
properties: params.map((param) => {
|
|
1017
|
-
return
|
|
1017
|
+
return _kubb_core.ast.createProperty({
|
|
1018
1018
|
name: param.name,
|
|
1019
1019
|
required: param.required,
|
|
1020
1020
|
schema: param.schema
|
|
@@ -1029,72 +1029,72 @@ function buildLegacyResponsesSchemaNode(node, { resolver }) {
|
|
|
1029
1029
|
return !Number.isNaN(code) && code >= 200 && code < 300;
|
|
1030
1030
|
});
|
|
1031
1031
|
const errorResponses = node.responses.filter((res) => res.statusCode === "default" || Number(res.statusCode) >= 400);
|
|
1032
|
-
const responseSchema = successResponses.length > 0 ? successResponses.length === 1 ?
|
|
1032
|
+
const responseSchema = successResponses.length > 0 ? successResponses.length === 1 ? _kubb_core.ast.createSchema({
|
|
1033
1033
|
type: "ref",
|
|
1034
1034
|
name: resolver.resolveResponseStatusName(node, successResponses[0].statusCode)
|
|
1035
|
-
}) :
|
|
1035
|
+
}) : _kubb_core.ast.createSchema({
|
|
1036
1036
|
type: "union",
|
|
1037
|
-
members: successResponses.map((res) =>
|
|
1037
|
+
members: successResponses.map((res) => _kubb_core.ast.createSchema({
|
|
1038
1038
|
type: "ref",
|
|
1039
1039
|
name: resolver.resolveResponseStatusName(node, res.statusCode)
|
|
1040
1040
|
}))
|
|
1041
|
-
}) :
|
|
1042
|
-
const errorsSchema = errorResponses.length > 0 ? errorResponses.length === 1 ?
|
|
1041
|
+
}) : _kubb_core.ast.createSchema({ type: "any" });
|
|
1042
|
+
const errorsSchema = errorResponses.length > 0 ? errorResponses.length === 1 ? _kubb_core.ast.createSchema({
|
|
1043
1043
|
type: "ref",
|
|
1044
1044
|
name: resolver.resolveResponseStatusName(node, errorResponses[0].statusCode)
|
|
1045
|
-
}) :
|
|
1045
|
+
}) : _kubb_core.ast.createSchema({
|
|
1046
1046
|
type: "union",
|
|
1047
|
-
members: errorResponses.map((res) =>
|
|
1047
|
+
members: errorResponses.map((res) => _kubb_core.ast.createSchema({
|
|
1048
1048
|
type: "ref",
|
|
1049
1049
|
name: resolver.resolveResponseStatusName(node, res.statusCode)
|
|
1050
1050
|
}))
|
|
1051
|
-
}) :
|
|
1052
|
-
const properties = [
|
|
1051
|
+
}) : _kubb_core.ast.createSchema({ type: "any" });
|
|
1052
|
+
const properties = [_kubb_core.ast.createProperty({
|
|
1053
1053
|
name: "Response",
|
|
1054
1054
|
required: true,
|
|
1055
1055
|
schema: responseSchema
|
|
1056
1056
|
})];
|
|
1057
|
-
if (!isGet && node.requestBody?.schema) properties.push(
|
|
1057
|
+
if (!isGet && node.requestBody?.schema) properties.push(_kubb_core.ast.createProperty({
|
|
1058
1058
|
name: "Request",
|
|
1059
1059
|
required: true,
|
|
1060
|
-
schema:
|
|
1060
|
+
schema: _kubb_core.ast.createSchema({
|
|
1061
1061
|
type: "ref",
|
|
1062
1062
|
name: resolver.resolveDataName(node)
|
|
1063
1063
|
})
|
|
1064
1064
|
}));
|
|
1065
1065
|
const queryParam = node.parameters.find((p) => p.in === "query");
|
|
1066
|
-
if (queryParam) properties.push(
|
|
1066
|
+
if (queryParam) properties.push(_kubb_core.ast.createProperty({
|
|
1067
1067
|
name: "QueryParams",
|
|
1068
1068
|
required: true,
|
|
1069
|
-
schema:
|
|
1069
|
+
schema: _kubb_core.ast.createSchema({
|
|
1070
1070
|
type: "ref",
|
|
1071
1071
|
name: resolver.resolveQueryParamsName(node, queryParam)
|
|
1072
1072
|
})
|
|
1073
1073
|
}));
|
|
1074
1074
|
const pathParam = node.parameters.find((p) => p.in === "path");
|
|
1075
|
-
if (pathParam) properties.push(
|
|
1075
|
+
if (pathParam) properties.push(_kubb_core.ast.createProperty({
|
|
1076
1076
|
name: "PathParams",
|
|
1077
1077
|
required: true,
|
|
1078
|
-
schema:
|
|
1078
|
+
schema: _kubb_core.ast.createSchema({
|
|
1079
1079
|
type: "ref",
|
|
1080
1080
|
name: resolver.resolvePathParamsName(node, pathParam)
|
|
1081
1081
|
})
|
|
1082
1082
|
}));
|
|
1083
1083
|
const headerParam = node.parameters.find((p) => p.in === "header");
|
|
1084
|
-
if (headerParam) properties.push(
|
|
1084
|
+
if (headerParam) properties.push(_kubb_core.ast.createProperty({
|
|
1085
1085
|
name: "HeaderParams",
|
|
1086
1086
|
required: true,
|
|
1087
|
-
schema:
|
|
1087
|
+
schema: _kubb_core.ast.createSchema({
|
|
1088
1088
|
type: "ref",
|
|
1089
1089
|
name: resolver.resolveHeaderParamsName(node, headerParam)
|
|
1090
1090
|
})
|
|
1091
1091
|
}));
|
|
1092
|
-
properties.push(
|
|
1092
|
+
properties.push(_kubb_core.ast.createProperty({
|
|
1093
1093
|
name: "Errors",
|
|
1094
1094
|
required: true,
|
|
1095
1095
|
schema: errorsSchema
|
|
1096
1096
|
}));
|
|
1097
|
-
return
|
|
1097
|
+
return _kubb_core.ast.createSchema({
|
|
1098
1098
|
type: "object",
|
|
1099
1099
|
primitive: "object",
|
|
1100
1100
|
properties
|
|
@@ -1105,14 +1105,14 @@ function buildLegacyResponseUnionSchemaNode(node, { resolver }) {
|
|
|
1105
1105
|
const code = Number(res.statusCode);
|
|
1106
1106
|
return !Number.isNaN(code) && code >= 200 && code < 300;
|
|
1107
1107
|
});
|
|
1108
|
-
if (successResponses.length === 0) return
|
|
1109
|
-
if (successResponses.length === 1) return
|
|
1108
|
+
if (successResponses.length === 0) return _kubb_core.ast.createSchema({ type: "any" });
|
|
1109
|
+
if (successResponses.length === 1) return _kubb_core.ast.createSchema({
|
|
1110
1110
|
type: "ref",
|
|
1111
1111
|
name: resolver.resolveResponseStatusName(node, successResponses[0].statusCode)
|
|
1112
1112
|
});
|
|
1113
|
-
return
|
|
1113
|
+
return _kubb_core.ast.createSchema({
|
|
1114
1114
|
type: "union",
|
|
1115
|
-
members: successResponses.map((res) =>
|
|
1115
|
+
members: successResponses.map((res) => _kubb_core.ast.createSchema({
|
|
1116
1116
|
type: "ref",
|
|
1117
1117
|
name: resolver.resolveResponseStatusName(node, res.statusCode)
|
|
1118
1118
|
}))
|
|
@@ -1146,11 +1146,12 @@ function buildLegacySchemaNames(node, params, resolver) {
|
|
|
1146
1146
|
}
|
|
1147
1147
|
const zodGeneratorLegacy = (0, _kubb_core.defineGenerator)({
|
|
1148
1148
|
name: "zod-legacy",
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
const {
|
|
1149
|
+
renderer: _kubb_renderer_jsx.jsxRenderer,
|
|
1150
|
+
schema(node, ctx) {
|
|
1151
|
+
const { adapter, config, resolver, root } = ctx;
|
|
1152
|
+
const { output, coercion, guidType, mini, wrapOutput, inferred, importPath, group, printer } = ctx.options;
|
|
1152
1153
|
if (!node.name) return;
|
|
1153
|
-
const mode =
|
|
1154
|
+
const mode = ctx.getMode(output);
|
|
1154
1155
|
const isZodImport = ZOD_NAMESPACE_IMPORTS.has(importPath);
|
|
1155
1156
|
const imports = adapter.getImports(node, (schemaName) => ({
|
|
1156
1157
|
name: resolver.resolveSchemaName(schemaName),
|
|
@@ -1221,12 +1222,12 @@ const zodGeneratorLegacy = (0, _kubb_core.defineGenerator)({
|
|
|
1221
1222
|
]
|
|
1222
1223
|
});
|
|
1223
1224
|
},
|
|
1224
|
-
operation(node,
|
|
1225
|
-
const { adapter, config, resolver, root } =
|
|
1226
|
-
const { output, coercion, guidType, mini, wrapOutput, inferred, importPath, group, paramsCasing, printer } = options;
|
|
1227
|
-
const mode =
|
|
1225
|
+
operation(node, ctx) {
|
|
1226
|
+
const { adapter, config, resolver, root } = ctx;
|
|
1227
|
+
const { output, coercion, guidType, mini, wrapOutput, inferred, importPath, group, paramsCasing, printer } = ctx.options;
|
|
1228
|
+
const mode = ctx.getMode(output);
|
|
1228
1229
|
const isZodImport = ZOD_NAMESPACE_IMPORTS.has(importPath);
|
|
1229
|
-
const params =
|
|
1230
|
+
const params = _kubb_core.ast.caseParams(node.parameters, paramsCasing);
|
|
1230
1231
|
const meta = { file: resolver.resolveFile({
|
|
1231
1232
|
name: node.operationId,
|
|
1232
1233
|
extname: ".ts",
|
|
@@ -1361,9 +1362,9 @@ const zodGeneratorLegacy = (0, _kubb_core.defineGenerator)({
|
|
|
1361
1362
|
]
|
|
1362
1363
|
});
|
|
1363
1364
|
},
|
|
1364
|
-
operations(nodes,
|
|
1365
|
-
const { adapter, config, resolver, root } =
|
|
1366
|
-
const { output, importPath, group, operations, paramsCasing } = options;
|
|
1365
|
+
operations(nodes, ctx) {
|
|
1366
|
+
const { adapter, config, resolver, root } = ctx;
|
|
1367
|
+
const { output, importPath, group, operations, paramsCasing } = ctx.options;
|
|
1367
1368
|
if (!operations) return;
|
|
1368
1369
|
const isZodImport = ZOD_NAMESPACE_IMPORTS.has(importPath);
|
|
1369
1370
|
const meta = { file: resolver.resolveFile({
|
|
@@ -1377,7 +1378,7 @@ const zodGeneratorLegacy = (0, _kubb_core.defineGenerator)({
|
|
|
1377
1378
|
const transformedOperations = nodes.map((node) => {
|
|
1378
1379
|
return {
|
|
1379
1380
|
node,
|
|
1380
|
-
data: buildLegacySchemaNames(node,
|
|
1381
|
+
data: buildLegacySchemaNames(node, _kubb_core.ast.caseParams(node.parameters, paramsCasing), resolver)
|
|
1381
1382
|
};
|
|
1382
1383
|
});
|
|
1383
1384
|
const imports = transformedOperations.flatMap(({ node, data }) => {
|
|
@@ -1431,9 +1432,6 @@ const zodGeneratorLegacy = (0, _kubb_core.defineGenerator)({
|
|
|
1431
1432
|
}
|
|
1432
1433
|
});
|
|
1433
1434
|
//#endregion
|
|
1434
|
-
//#region package.json
|
|
1435
|
-
var version = "5.0.0-alpha.33";
|
|
1436
|
-
//#endregion
|
|
1437
1435
|
//#region src/resolvers/resolverZod.ts
|
|
1438
1436
|
/**
|
|
1439
1437
|
* Default resolver for `@kubb/plugin-zod`.
|
|
@@ -1552,30 +1550,6 @@ const resolverZodLegacy = (0, _kubb_core.defineResolver)(() => {
|
|
|
1552
1550
|
};
|
|
1553
1551
|
});
|
|
1554
1552
|
//#endregion
|
|
1555
|
-
//#region src/presets.ts
|
|
1556
|
-
/**
|
|
1557
|
-
* Built-in preset registry for `@kubb/plugin-zod`.
|
|
1558
|
-
*
|
|
1559
|
-
* - `default` — uses `resolverZod` and `zodGenerator` (current naming conventions).
|
|
1560
|
-
* - `kubbV4` — uses `resolverZodLegacy` and `zodGeneratorLegacy` (Kubb v4 naming conventions).
|
|
1561
|
-
*
|
|
1562
|
-
* Note: `printerZodMini` is selected at runtime by the generator when `mini: true` is set.
|
|
1563
|
-
*/
|
|
1564
|
-
const presets = (0, _kubb_core.definePresets)({
|
|
1565
|
-
default: {
|
|
1566
|
-
name: "default",
|
|
1567
|
-
resolver: resolverZod,
|
|
1568
|
-
generators: [zodGenerator],
|
|
1569
|
-
printer: printerZod
|
|
1570
|
-
},
|
|
1571
|
-
kubbV4: {
|
|
1572
|
-
name: "kubbV4",
|
|
1573
|
-
resolver: resolverZodLegacy,
|
|
1574
|
-
generators: [zodGeneratorLegacy],
|
|
1575
|
-
printer: printerZod
|
|
1576
|
-
}
|
|
1577
|
-
});
|
|
1578
|
-
//#endregion
|
|
1579
1553
|
//#region src/plugin.ts
|
|
1580
1554
|
/**
|
|
1581
1555
|
* Canonical plugin name for `@kubb/plugin-zod`, used to identify the plugin in driver lookups and warnings.
|
|
@@ -1597,43 +1571,30 @@ const pluginZodName = "plugin-zod";
|
|
|
1597
1571
|
* })
|
|
1598
1572
|
* ```
|
|
1599
1573
|
*/
|
|
1600
|
-
const pluginZod = (0, _kubb_core.
|
|
1574
|
+
const pluginZod = (0, _kubb_core.definePlugin)((options) => {
|
|
1601
1575
|
const { output = {
|
|
1602
1576
|
path: "zod",
|
|
1603
1577
|
barrelType: "named"
|
|
1604
|
-
}, group, exclude = [], include, override = [], dateType = "string", typed = false, operations = false, mini = false, guidType = "uuid", importPath = mini ? "zod/mini" : "zod", coercion = false, inferred = false, wrapOutput = void 0, paramsCasing, printer,
|
|
1605
|
-
const
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
let resolvePathWarning = false;
|
|
1578
|
+
}, group, exclude = [], include, override = [], dateType = "string", typed = false, operations = false, mini = false, guidType = "uuid", importPath = mini ? "zod/mini" : "zod", coercion = false, inferred = false, wrapOutput = void 0, paramsCasing, printer, resolver: userResolver, transformer: userTransformer, generators: userGenerators = [], compatibilityPreset = "default" } = options;
|
|
1579
|
+
const defaultResolver = compatibilityPreset === "kubbV4" ? resolverZodLegacy : resolverZod;
|
|
1580
|
+
const defaultGenerator = compatibilityPreset === "kubbV4" ? zodGeneratorLegacy : zodGenerator;
|
|
1581
|
+
const groupConfig = group ? {
|
|
1582
|
+
...group,
|
|
1583
|
+
name: (ctx) => {
|
|
1584
|
+
if (group.type === "path") return `${ctx.group.split("/")[1]}`;
|
|
1585
|
+
return `${camelCase(ctx.group)}Controller`;
|
|
1586
|
+
}
|
|
1587
|
+
} : void 0;
|
|
1615
1588
|
return {
|
|
1616
1589
|
name: pluginZodName,
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
},
|
|
1621
|
-
get transformer() {
|
|
1622
|
-
return preset.transformer;
|
|
1623
|
-
},
|
|
1624
|
-
get options() {
|
|
1625
|
-
return {
|
|
1590
|
+
options,
|
|
1591
|
+
hooks: { "kubb:plugin:setup"(ctx) {
|
|
1592
|
+
ctx.setOptions({
|
|
1626
1593
|
output,
|
|
1627
1594
|
exclude,
|
|
1628
1595
|
include,
|
|
1629
1596
|
override,
|
|
1630
|
-
group:
|
|
1631
|
-
...group,
|
|
1632
|
-
name: (ctx) => {
|
|
1633
|
-
if (group.type === "path") return `${ctx.group.split("/")[1]}`;
|
|
1634
|
-
return `${camelCase(ctx.group)}Controller`;
|
|
1635
|
-
}
|
|
1636
|
-
} : void 0,
|
|
1597
|
+
group: groupConfig,
|
|
1637
1598
|
dateType,
|
|
1638
1599
|
typed,
|
|
1639
1600
|
importPath,
|
|
@@ -1645,43 +1606,15 @@ const pluginZod = (0, _kubb_core.createPlugin)((options) => {
|
|
|
1645
1606
|
wrapOutput,
|
|
1646
1607
|
paramsCasing,
|
|
1647
1608
|
printer
|
|
1648
|
-
};
|
|
1649
|
-
},
|
|
1650
|
-
resolvePath(baseName, pathMode, options) {
|
|
1651
|
-
if (!resolvePathWarning) {
|
|
1652
|
-
this.warn("Do not use resolvePath for pluginZod, use resolverZod.resolvePath instead");
|
|
1653
|
-
resolvePathWarning = true;
|
|
1654
|
-
}
|
|
1655
|
-
return this.plugin.resolver.resolvePath({
|
|
1656
|
-
baseName,
|
|
1657
|
-
pathMode,
|
|
1658
|
-
tag: options?.group?.tag,
|
|
1659
|
-
path: options?.group?.path
|
|
1660
|
-
}, {
|
|
1661
|
-
root: this.root,
|
|
1662
|
-
output,
|
|
1663
|
-
group: this.plugin.options.group
|
|
1664
1609
|
});
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
}
|
|
1673
|
-
async schema(node, options) {
|
|
1674
|
-
return mergedGenerator.schema?.call(this, node, options);
|
|
1675
|
-
},
|
|
1676
|
-
async operation(node, options) {
|
|
1677
|
-
return mergedGenerator.operation?.call(this, node, options);
|
|
1678
|
-
},
|
|
1679
|
-
async operations(nodes, options) {
|
|
1680
|
-
return mergedGenerator.operations?.call(this, nodes, options);
|
|
1681
|
-
},
|
|
1682
|
-
async buildStart() {
|
|
1683
|
-
await this.openInStudio({ ast: true });
|
|
1684
|
-
}
|
|
1610
|
+
ctx.setResolver(userResolver ? {
|
|
1611
|
+
...defaultResolver,
|
|
1612
|
+
...userResolver
|
|
1613
|
+
} : defaultResolver);
|
|
1614
|
+
if (userTransformer) ctx.setTransformer(userTransformer);
|
|
1615
|
+
ctx.addGenerator(defaultGenerator);
|
|
1616
|
+
for (const gen of userGenerators) ctx.addGenerator(gen);
|
|
1617
|
+
} }
|
|
1685
1618
|
};
|
|
1686
1619
|
});
|
|
1687
1620
|
//#endregion
|