From af03dbd610d53acb268cc1199b626e6a8624c2c4 Mon Sep 17 00:00:00 2001 From: Hikaru Yoshino Date: Sun, 8 Sep 2024 15:40:07 +0900 Subject: [PATCH] fix: generate zod constants for oneOf schemas --- packages/zod/src/index.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/packages/zod/src/index.ts b/packages/zod/src/index.ts index c1cfee636..dded26eae 100644 --- a/packages/zod/src/index.ts +++ b/packages/zod/src/index.ts @@ -404,10 +404,20 @@ export const parseZodValidationSchemaDefinition = ( if (fn === 'oneOf' || fn === 'anyOf') { return args.reduce( - (acc: string, { functions }: { functions: [string, any][] }) => { + ( + acc: string, + { + functions, + consts: argConsts, + }: { functions: [string, any][]; consts: string[] }, + ) => { const value = functions.map(parseProperty).join(''); const valueWithZod = `${value.startsWith('.') ? 'zod' : ''}${value}`; + if (argConsts.length) { + consts += argConsts.join(''); + } + if (!acc) { acc += valueWithZod; return acc;