Skip to content

Commit

Permalink
fix: generate zod constants for oneOf schemas (orval-labs#1618)
Browse files Browse the repository at this point in the history
  • Loading branch information
yoshi2no authored Sep 8, 2024
1 parent f516975 commit 19ff0e0
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion packages/zod/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 19ff0e0

Please sign in to comment.