Skip to content

Latest commit

 

History

History
38 lines (34 loc) · 1.02 KB

nullable-props.md

File metadata and controls

38 lines (34 loc) · 1.02 KB

Nullable props (OpenAPI v2)

In the OpenAPI v3 spec you can create properties that can be NULL, by providing a nullable: true in your schema. However, the v2 spec does not allow you to do this. You can use the unofficial x-nullable in your specification to generate nullable properties in OpenApi v2.

{
    "ModelWithNullableString": {
        "required": [
            "requiredProp"
        ],
        "description": "This is a model with one string property",
        "type": "object",
        "properties": {
            "prop": {
                "description": "This is a simple string property",
                "type": "string",
                "x-nullable": true
            },
            "requiredProp": {
                "description": "This is a simple string property",
                "type": "string",
                "x-nullable": true
            }
        }
    }
}

Generated code:

export type ModelWithNullableString = {
    prop?: string | null;
    requiredProp: string | null;
};