Skip to content

Support x-nullable as an alternative to nullable behind an option #846

@mitchell-merry

Description

@mitchell-merry

What is the problem this feature would solve?

In Swagger 2.0, there is no way to represent that a type is "nullable", i.e., that null is a valid value to pass to it (like nullable in Openapi 3.0.x).

External documents/projects?

No mention of nullable in the 2.0 spec: https://swagger.io/specification/v2/

nullable: true is how it is done in 3.0.x: https://swagger.io/docs/specification/data-models/data-types#null

(3.1.x uses an anyOf with null)

What is the feature you are proposing to solve the problem?

A common convention is to use x-nullable to represent this instead. I would like it if kubb supported this (specifically, for swagger-zod).

I recently implemented this in openapi-typescript: openapi-ts/openapi-typescript#1576, and need this feature to maintain feature parity (currently we cannot use these zod schemas as they miss this crucial feature). If approved, I would make the PR to support it here.

The core of the change would effectively be changing this:

const nullable = schema.nullable ?? false

to this (but exposed as an option):

const nullable = (schema.nullable || schema["x-nullable"]) ?? false

What alternatives have you considered?

Upgrading to 3.1.x... but that is impossible for a number of reasons right now 😅

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions