zod-to-openapi
zod-to-openapi copied to clipboard
Combining `partial` with `null` in a union type results in double producing `null` type matcher
The code below is causing problems for my use case, and I can't successfully generate a valid openapi definition because of it. Let me know if you need any more context!
Offending ZOD repro
export const ConditionSchema = z
.object({
targetValue: z.union([
z.string().array(),
z.number().array(),
z.string(),
z.number(),
z.null(),
]),
})
.partial({ targetValue: true });
Generated openapi block
"anyOf": [
{ "type": "array", "items": { "type": "string" } },
{ "type": "array", "items": { "type": "number" } },
{ "type": "string" },
{ "type": "number" },
{ "type": "null" },
{ "type": "null" }
]
@brent-statsig thank you for reporting that. Right now it is kind of hard to find time for such fixes, but I'll try and get to take a look at it whenever I can. In the meantime if you have an idea on how to fix it - feel free to open up a PR