Skip to content

[zod-openapi] Inconsistent and incorrect handling of z.null() between OAS 3.0 and 3.1 #250

Open
@hexpunk

Description

@hexpunk

z.null() still doesn't seem to be generating proper values. This is related to #220 and #228.

OAS Document Version API Version API Output Swagger UI Correct & Works?
3.0 generateSchema(extendApi(z.null()), false, '3.0') { "type": "null" }
3.1 generateSchema(extendApi(z.null()), false, '3.1') { "type": [ "string", "null" ], "enum": [ "null" ] }
3.1 generateSchema(extendApi(z.null()), false, '3.0') { "type": "null" }

When the overall document version is 3.0 and the version passed to generateSchema is 3.0, it generates a value that causes Swagger UI to print "Unknown type: null", which misleadingly looks like a string literal value.

When the overall document version is 3.1 and the version passed to generateSchema is 3.1, it generates a string literal value of "null", which is incorrect.

When the overall document version is 3.1 and the version passed to generateSchema is 3.0, Swagger UI works as expected... at least as far as handling z.null() is concerned. I don't know enough about the differences between 3.0 and 3.1 to trust this approach broadly.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions