-
Notifications
You must be signed in to change notification settings - Fork 60
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
How to indicate that a schema using a transform or preprocess can be nullable / optional? #143
Comments
I've also tried this as a preprocess and have the same issue: const aSchema = z.object({
id: z.string(),
date: z
.preprocess(val => (val ? String(val) : null), z.string())
.nullable()
.openapi({ example: '2023-04-12', description: 'YYYY-MM-DD' }),
}); |
@codeinabox thank you for using the library and helping us identify issues to make it better. I'll answer on issue in two ways:
|
…o bugfix/#143-handle-preprocess-and-any
…cess-and-any Bugfix/#143 handle preprocess and any
@codeinabox some changes have been released with v5.1.0. With them the |
Is there a way to create a nullable transform with schema version 3.0.0? I had the following schema, which used coerce:
This correctly set
nullable: true
on the generated document. However due a bug with coerce colinhacks/zod#1760, I've had to switch to the following transform schema and I am having trouble getting it to say the field can be null in the responseThe text was updated successfully, but these errors were encountered: