Closed
Description
I have an API that needs to differentiate between properties that are T | null
and T | undefined
. It looks like using nullable
works for basic types but is ignored for $ref
:
schemas:
TestObject:
type: object
properties:
stringMaybeUndefined:
type: string
stringMaybeNullA:
type: string
nullable: true
stringMaybeNullB:
anyOf:
- type: string
nullable: true
otherObjectMaybeUndefined:
$ref: "#/components/schemas/OtherObject"
otherObjectMaybeNullA:
$ref: "#/components/schemas/OtherObject"
nullable: true
otherObjectMaybeNullB:
anyOf:
- $ref: "#/components/schemas/OtherObject"
nullable: true
required:
- stringMaybeNullA
- stringMaybeNullB
- otherObjectMaybeNullA
- otherObjectMaybeNullB
OtherObject:
type: object
Generates:
export interface TestObject {
stringMaybeUndefined?: string;
stringMaybeNullA?: string | null;
stringMaybeNullB?: string;
otherObjectMaybeUndefined?: OtherObject;
otherObjectMaybeNullA?: OtherObject;
otherObjectMaybeNullB?: OtherObject;
}
Note: The OpenAPI 3.1 syntax
oneOf:
- $ref: "#/components/schemas/OtherObject"
- type: 'null'
works, but I'm forced to use OpenAPI 3.0 because of constraints from other tooling.
Can this be achieved somehow?
Edit, relevant resources:
- Reference objects don't combine well with “nullable” OAI/OpenAPI-Specification#1368
- https://github.com/OAI/OpenAPI-Specification/blob/master/proposals/003_Clarify-Nullable.md
If I interpret these (long) discussions correctly, at least the allOf
wrapping should work?
Metadata
Metadata
Assignees
Labels
No labels