asteasolutions / zod-to-openapi

A library that generates OpenAPI (Swagger) docs from Zod schemas
MIT License
955 stars 60 forks source link

nullable is part of "allOf" instead of being separate schema key when using shared component #248

Open Grawl opened 3 months ago

Grawl commented 3 months ago
const phoneNumber = z.string().openapi('Phone')

const mySchema = z.object({
    somePhone: phoneNumber.nullable(),
    anotherPhone: phoneNumber,
})

Expected result:

"somePhone": {
    "allOf": [
        {
            "$ref": "#/components/schemas/Phone"
        },
    ],
    "nullable": true
},
"anotherPhone": {
    "$ref": "#/components/schemas/Phone"
},

Actual result:

"somePhone": {
    "allOf": [
        {
            "$ref": "#/components/schemas/Phone"
        },
        {
            "nullable": true
        }
    ]
},
"anotherPhone": {
    "$ref": "#/components/schemas/Phone"
},

I am using Hono

davidask commented 3 hours ago

@AGalabov do you have any info here? Ready to help out here if given a pointer 👍🏻