Skip to content

Commit

Permalink
Merge pull request #4413 from avanderbergh/avanderbergh/issue4157
Browse files Browse the repository at this point in the history
  • Loading branch information
JonnyBurger authored Oct 23, 2024
2 parents 2ca3223 + dd50de3 commit 8a6f5d3
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
1 change: 1 addition & 0 deletions packages/example/src/Root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1268,6 +1268,7 @@ export const Index: React.FC = () => {
{type: 'a' as const, a: {a: 'hi'}},
{type: 'b' as const, b: {b: 'hi'}},
],
discriminatedUnion: {type: 'auto'},
}}
/>
{/**
Expand Down
9 changes: 9 additions & 0 deletions packages/example/src/SchemaTest/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@ export const schemaTestSchema = z.object({
}),
]),
),
discriminatedUnion: z.discriminatedUnion('type', [
z.object({
type: z.literal('auto'),
}),
z.object({
type: z.literal('fixed'),
value: z.number().min(1080),
}),
]),
});

export const schemaArrayTestSchema = z.array(z.number());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,20 @@ export const createZodValues = (
switch (typeName) {
case zodRuntime.ZodFirstPartyTypeKind.ZodString:
return '';
case zodRuntime.ZodFirstPartyTypeKind.ZodNumber:
case zodRuntime.ZodFirstPartyTypeKind.ZodNumber: {
for (const check of (def as z.ZodNumberDef).checks) {
if (check.kind === 'min') {
return check.value;
}

if (check.kind === 'max' && check.value < 0) {
return check.value;
}
}

return 0;
}

case zodRuntime.ZodFirstPartyTypeKind.ZodBigInt:
return BigInt(0);
case zodRuntime.ZodFirstPartyTypeKind.ZodBoolean:
Expand Down

0 comments on commit 8a6f5d3

Please sign in to comment.