Multiple responses using oneOf attribute do not appear in UI
See original GitHub issueQ | A |
---|---|
Bug or feature request? | Bug |
Which Swagger/OpenAPI version? | |
Which Swagger-UI version? | |
How did you install Swagger-UI? | |
Which browser & version? | |
Which operating system? |
Demonstration API definition
responses:
'200':
description: OK
content:
application/json:
schema:
oneOf:
- $ref: '#/components/schemas/AuthorisationResponse'
- $ref: '#/components/schemas/ForbiddenResponse'
Configuration (browser query string, constructor, config.yaml)
constructorConfig contains just the default values.
Expected Behavior
Since I have two schemas passed in as a $ref to the 200 response I would expect to see two schemas in the Swagger UI application.
Current Behavior
Instead I see only the reference to the 200 response and its description with no example responses displayed as JSON in the black boxes.
Possible Solution
Context
Issue Analytics
- State:
- Created 6 years ago
- Reactions:378
- Comments:115 (23 by maintainers)
Top Results From Across the Web
oneOf, anyOf, allOf, not - Swagger
Use the oneOf keyword to ensure the given data is valid against one of the ... object is not valid against both schemas,...
Read more >Swagger: Specify Two Responses with the Same ... - Baeldung
Learn how to write an API specification that returns two different objects for the same response code using Java and Swagger.
Read more >Swagger; specify two responses with same code based on ...
OpenAPI 2.0. OAS2 does not support multiple response schemas per status code. You can only have a single schema, for example, ...
Read more >How to properly use oneOf and anyOf in Rest Schema?
(and yes, the type must be set, or else the API response would be invalidated with many "undefined index" notices). For each item,...
Read more >F.A.Q - Springdoc-openapi
How can I define multiple OpenAPI definitions in one Spring Boot project? ... You can use the standard swagger-ui property filter.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
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
any news from maintainers regarding this issue?
Applying the
oneOf
to type withincomponents/schema
does not work around this problem.You can sort of work around this by declaring
type: object
as a sibling tooneOf
:OR In the referenced schema component
The work-around isn’t great because it puts an empty object in the response example (which is shown by default), but at least consumers can see the relevant models: