openapi-zod-client
openapi-zod-client copied to clipboard
Validation not taken into account with `anyOf`
Describe the bug
When using anyOf
for an optional field, validation criteria are not generated.
Minimal reproduction
"first_name": {
"type": "string",
"minLength": 1
"maxLength": 30
}
The above works, and produces:
.object({
first_name: z.string().min(1).max(30),
})
The below does not work:
"first_name": {
"anyOf": [
{
"type": "string",
"maxLength": 30,
"minLength": 1
},
{
"type": "null"
}
],
"default": null
}
and produces:
.object({
first_name: z.union([z.string(), z.null()]),
})
Expected behavior
"first_name": {
"anyOf": [
{
"type": "string",
"maxLength": 30,
"minLength": 1
},
{
"type": "null"
}
],
"default": null
}
should produce:
.object({
first_name: z.union([z.string().min(1).max(30), z.null()]),
})
.object({
first_name: z.string().min(1).max(30).nullable(),
})