-
Notifications
You must be signed in to change notification settings - Fork 93
Closed
Labels
questionFurther information is requestedFurther information is requested
Description
Using OpenApi 3.1.0 nullable fields are described using anyOf:
---
openapi: 3.1.0
components:
schemas:
DTO:
type: object
properties:
name:
type: string
examples:
- Hello World
localTime:
$ref: "#/components/schemas/LocalTime"
type: string
examples:
- 13:45:30.123456789
- 13:45:30.123456789
localTimeNullable:
type:
- string
- "null"
examples:
- 13:45:30.123456789
- 13:45:30.123456789
anyOf:
- $ref: "#/components/schemas/LocalTime"
- type: "null"
LocalTime:
type: string
format: local-time
examples:
- 13:45:30.123456789
externalDocs:
description: As defined by 'partial-time' in RFC3339
url: https://www.rfc-editor.org/rfc/rfc3339.html#section-5.6
paths:
/hello:
get:
responses:
"200":
description: OK
content:
application/json:
schema:
$ref: "#/components/schemas/DTO"
summary: Hello
tags:
- Greeting Resource
info:
title: code-with-quarkus API
version: 1.0.0-SNAPSHOTIn swagger-ui this yaml will be rendered as follows:

As you can see (especially if collapsed) the 'real' type of the nullable field is not easy to see.
IMHO instead of using anyOf to describe that the field is nullable, using $ref and a type-array would be better:
---
openapi: 3.1.0
components:
schemas:
DTO:
type: object
properties:
name:
type: string
examples:
- Hello World
localTime:
$ref: "#/components/schemas/LocalTime"
type: string
examples:
- 13:45:30.123456789
- 13:45:30.123456789
localTimeNullable:
$ref: "#/components/schemas/LocalTime"
type:
- string
- "null"
examples:
- 13:45:30.123456789
- 13:45:30.123456789
LocalTime:
type: string
format: local-time
examples:
- 13:45:30.123456789
externalDocs:
description: As defined by 'partial-time' in RFC3339
url: https://www.rfc-editor.org/rfc/rfc3339.html#section-5.6
paths:
/hello:
get:
responses:
"200":
description: OK
content:
application/json:
schema:
$ref: "#/components/schemas/DTO"
summary: Hello
tags:
- Greeting Resource
info:
title: code-with-quarkus API
version: 1.0.0-SNAPSHOTThis would be rendered as follows

AFAIK the later kind is valid OpenApi 3.1.0, https://editor-next.swagger.io/ shows no warnings/errors
see https://github.com/ChMThiel/quarkus_demo/tree/OpenApi_generator_3.1.0_nullable for reproducer
Metadata
Metadata
Assignees
Labels
questionFurther information is requestedFurther information is requested