From 1edc2ab5dde2326afd2834d190a1b3ae0dc04d36 Mon Sep 17 00:00:00 2001 From: Victor Date: Tue, 19 Dec 2023 12:48:58 +0100 Subject: [PATCH] fix(zod): allow blank value for non-required enums (#1113) * fix(zod): allow blank value for non-required enums * fix(format): zod client --------- Co-authored-by: Eric Butler --- packages/zod/src/index.ts | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/packages/zod/src/index.ts b/packages/zod/src/index.ts index 4c4d4d5ee..c281f3ce6 100644 --- a/packages/zod/src/index.ts +++ b/packages/zod/src/index.ts @@ -214,14 +214,13 @@ const generateZodValidationSchemaDefinition = ( } if (schema.enum && type !== 'number') { - functions.push([ - 'enum', - [ - `[${schema.enum - .map((value) => (isString(value) ? `'${escape(value)}'` : `${value}`)) - .join(', ')}]`, - ], - ]); + const enumValues = schema.enum.map((value) => + isString(value) ? `'${escape(value)}'` : `${value}`, + ); + if (!schema.required) { + enumValues.push(`""`); + } + functions.push(['enum', [`[${enumValues.join(', ')}]`]]); } if (!required && nullable) {