Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support x-nullable OpenAPI 2.0 extension #156

Open
johnthagen opened this issue Jun 16, 2020 · 1 comment
Open

Support x-nullable OpenAPI 2.0 extension #156

johnthagen opened this issue Jun 16, 2020 · 1 comment
Labels
enhancement New feature or request

Comments

@johnthagen
Copy link
Contributor

Describe the solution you'd like
x-nullable is a very common vendor extension that allows expressing nullabilty in an OpenAPI 2.0 schema. Tools such as swagger-codegen and openapi-generator can use this to preserve this type information into the generated code. This is important when exposing database columns that can be NULL.

The DjangoRestFramework ecosystem has support for this.

Using x-nullable, would change the generated TypeScript from

id: number;

to

id: number | null;

The client code can then use type checking to ensure that null is properly checked before accessing the content.

This could be done by adding an optional nullable keyword argument to fields, for example:

my_model = api.model('MyModel', {
    'id': fields.Integer(nullable=True),
}
@johnthagen johnthagen added the enhancement New feature or request label Jun 16, 2020
@maartenvdmeulen
Copy link

maartenvdmeulen commented Mar 4, 2021

Any updates?
I like to use x-nullable with openapi-typescript-codegen. See #Nullable in OpenAPI v2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants