Response types using Nullable/oneOf are invisible in swagger-ui (OpenApi3)
See original GitHub issueThis can be seen for example in NSwag.Sample.NETCore22 (unmodified):
Operation /pet/{petId}:
Definition:
"/pet/{petId}": {
"get": {
"tags": [
"Pet"
],
"operationId": "Pet_FindById",
"parameters": [
{
"name": "petId",
"in": "path",
"required": true,
"schema": {
"type": "integer",
"format": "int32"
},
"x-position": 1
}
],
"responses": {
"200": {
"description": "",
"content": {
"application/json": {
"schema": {
"nullable": true,
"oneOf": [
{
"$ref": "#/components/schemas/Pet"
}
]
}
}
}
},
The schemas for the other responses are visible because they are array types. But the problem exists for all single object return types.
The only workaround I found is
config.DefaultReferenceTypeNullHandling = ReferenceTypeNullHandling.NotNull;
But that doesn’t seem to be a good solution…
Issue Analytics
- State:
- Created 4 years ago
- Comments:31 (24 by maintainers)
Top Results From Across the Web
How to specify a property can be null or a reference with ...
Note: some swagger implementations use x-nullable (or some-such) to specify a property value can be null, however, $ref replaces the object with ......
Read more >Describing Responses
In OpenAPI 3.0, you can use oneOf to specify alternate schemas for the response and document possible dependencies verbally in the response description...
Read more >OpenAPI Specification - Version 3.0.3
The OpenAPI Specification defines a standard interface to RESTful APIs which allows both humans and computers to understand service capabilities without ...
Read more >Data Types
OpenAPI defines the following basic types: string (this includes dates and files); number; integer; boolean; array ...
Read more >Describing Parameters
In OpenAPI 3.0, parameters are defined in the parameters section of an operation or path. To describe a parameter, you specify its name...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
But I think we still need to create an issue in Swagger UI - as this will be probably a problem for all these nullable + oneOfs (also between DTO schemas, etc.) - can you do that?
@handrews thanks for your fast answer!