From 19ff0e0c727616b8486f3c241da90a6a2b9a1fe0 Mon Sep 17 00:00:00 2001 From: yoshi2no <57059705+yoshi2no@users.noreply.github.com> Date: Sun, 8 Sep 2024 20:02:40 +0900 Subject: [PATCH] fix: generate zod constants for oneOf schemas (#1618) --- 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;