OpenApi response oneOf, for several response types
See original GitHub issueDescribe the feature
@OpenApiResponse(status = "200", content = @OpenApiContent(from = First.class, type= "application/json")),
@OpenApiResponse(status = "200", content = @OpenApiContent(from = Second.class, type= "application/json")),
@OpenApiResponse(status = "200", content = @OpenApiContent(from = Third.class, type= "application/json")),
should compile to corresponding oneOf in stead of picking the last item, from swagger.io
responses:
'200':
description: A JSON object containing pet information
content:
application/json:
schema:
oneOf:
- $ref: '#/components/schemas/Cat'
- $ref: '#/components/schemas/Dog'
- $ref: '#/components/schemas/Hamster'
Additional context Until then
@OpenApiResponse(status = "200", content = @OpenApiContent(from = First.class, type= "application/json")),
@OpenApiResponse(status = "200", content = @OpenApiContent(from = Second.class, type= "application/json")),
@OpenApiResponse(status = "200", content = @OpenApiContent(from = Third.class, type= "application/json")),
@OpenApiResponse(status = "200", content = @OpenApiContent(from = PlaceHolder.class, type= "application/json"))
class PlaceHolder {}
and custom ToJSONMapper (replace with it -> JacksonToJsonMapper.INSTANCE.map(it).replaceAll(…).replaceFirst(…))
String yaml = Yaml.pretty().writeValueAsString(openApi);
return yaml.replaceAll("\n(\\s+)(.+)/PlaceHolder'\n", "\n$1oneOf:\n $1- $2/First'\n $1- $2/Second'\n $1- $2/Third'\n").replaceFirst("\\s+PlaceHolder:\n\\s+type: object","");
Issue Analytics
- State:
- Created 4 years ago
- Comments:8 (4 by maintainers)
Top Results From Across the Web
Multiple responses using oneOf attribute do not appear in UI
Expected Behavior. Since I have two schemas passed in as a $ref to the 200 response I would expect to see two schemas...
Read more >oneOf, anyOf, allOf, not - Swagger
OAS 3 This guide is for OpenAPI 3.0. oneOf, anyOf, allOf, not. OpenAPI 3.0 provides several keywords which you can use to combine...
Read more >Building an OpenAPI response, including oneOf, and maybe ...
I tried a $ref , but it didn't work. The below successfully passes three different OpenAPI linting tools, but in the example it...
Read more >Why You Need oneOf in Your OpenAPI Specifications - APIMatic
Using oneOf in response types can help your API describe a variety of schemas, and consequently, the server response will validate against one ......
Read more >Swagger: Specify Two Responses with the Same ... - Baeldung
Having Two Different Responses With OpenAPI 3 ... In OpenAPI 3 specification, oneOf expects an array of objects and indicates that the ...
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 FreeTop 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
Top GitHub Comments
I will look at it in some time; on vacation for another week!
I think this was closed by #825 ?