mirror of
https://github.com/ferdikoomen/openapi-typescript-codegen.git
synced 2025-12-08 20:16:21 +00:00
1.0 KiB
1.0 KiB
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;
};