-
-
Notifications
You must be signed in to change notification settings - Fork 51
Support union types for zod generator #237
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@alisabzevari Thanks! |
Sure, will do. |
Co-authored-by: alexandruluca <[email protected]>
I have added support for myzod but apparently yup does not support unions. |
@alisabzevari I believe you can use mixed and oneof for yup |
I tried that but the generated schema cannot properly validate the object. |
@alisabzevari Could you add this code for yup in function union<T>(...schemas: ReadonlyArray<yup.SchemaOf<T>>): yup.BaseSchema<T> {
return yup.mixed().test({
test: (value) => schemas.some((schema) => schema.isValidSync(value))
})
} And fix yup generator to generate code like below function ShapeSchema(): yup.BaseSchema<Shape> {
return union<Shape>(SquareSchema(), CircleSchema())
} |
I have added the code you mentioned. Please have a look. |
@alisabzevari Could you please fix the test? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
slight modifications for #237
Fixes #236
Fixes #181
This PR adds support for union types for generating zod schemas when
withObjectType
is enabled.