Skip to content

Commit 590d500

Browse files
committed
fix enum generation
1 parent 7be3d8b commit 590d500

File tree

2 files changed

+360
-394
lines changed

2 files changed

+360
-394
lines changed

src/core/schema/zod-types-from-schema.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ class ZodDeclarationFileBuilder {
3838

3939
// we keep track of the schemas we've seen so we can
4040
// process resolve-ref schemas
41+
// deno-lint-ignore no-explicit-any
4142
schemas: Record<string, any> = {};
4243

4344
// deno-lint-ignore no-explicit-any
@@ -106,18 +107,13 @@ ${zodInferredTypes}`;
106107
convertSchemaEnum(schema: any): string | undefined {
107108
// deno-lint-ignore no-explicit-any
108109
const zodEnumDeclaration = (values: any[]) => {
109-
// deno-lint-ignore no-explicit-any
110-
const zodEnumValues = values.map((value: any) => {
111-
return JSON.stringify(value);
112-
});
113-
114110
// first filter out strings
115-
const zodEnumStrings = zodEnumValues.filter((value) => {
111+
const zodEnumStrings = values.filter((value) => {
116112
return typeof value === "string";
117113
}).map((value) => {
118114
return JSON.stringify(value);
119115
});
120-
const zodLiterals = zodEnumValues.filter((x) => {
116+
const zodLiterals = values.filter((x) => {
121117
return typeof x !== "string";
122118
});
123119
const zodTypes: string[] = [];
@@ -131,7 +127,7 @@ ${zodInferredTypes}`;
131127
zodTypes.push(
132128
...zodLiterals.map((x) => {
133129
return `z.literal(${JSON.stringify(x)})`;
134-
}).join(", "),
130+
}),
135131
);
136132
}
137133
if (zodTypes.length === 0) {

0 commit comments

Comments
 (0)