Skip to content

Commit 657b0b5

Browse files
committed
fix: improve enum handling in getTypeFromSchema function
This commit adds a check to ensure that the enum array is not empty before processing it in the getTypeFromSchema function. This enhancement prevents potential issues when dealing with empty enums and maintains type safety in the generated TypeScript code.
1 parent 836095b commit 657b0b5

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/utils.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,13 @@ export function getTypeFromSchema(
8585

8686
// Handle enums as union types
8787
if ("enum" in schema && schema.enum) {
88+
if (Object.values(schema.enum)?.length > 0) {
89+
return (
90+
Object.values(schema.enum)
91+
.map((e) => (typeof e === "string" ? `'${e}'` : e))
92+
.join(" | ") + nullable
93+
);
94+
}
8895
return schema.enum.map((e) => (typeof e === "string" ? `'${e}'` : e)).join(" | ") + nullable;
8996
}
9097

0 commit comments

Comments
 (0)