Skip to content

Commit

Permalink
Revert "fix(zod): allow blank value for non-required enums (#1113)" (#…
Browse files Browse the repository at this point in the history
…1116)

This reverts commit 1edc2ab.
  • Loading branch information
Eric Butler authored Dec 19, 2023
1 parent f9a2c38 commit 7580f55
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions packages/zod/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,13 +214,14 @@ const generateZodValidationSchemaDefinition = (
}

if (schema.enum && type !== 'number') {
const enumValues = schema.enum.map((value) =>
isString(value) ? `'${escape(value)}'` : `${value}`,
);
if (!schema.required) {
enumValues.push(`""`);
}
functions.push(['enum', [`[${enumValues.join(', ')}]`]]);
functions.push([
'enum',
[
`[${schema.enum
.map((value) => (isString(value) ? `'${escape(value)}'` : `${value}`))
.join(', ')}]`,
],
]);
}

if (!required && nullable) {
Expand Down

0 comments on commit 7580f55

Please sign in to comment.