question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

OpenApi response oneOf, for several response types

See original GitHub issue

Describe 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:closed
  • Created 4 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
MikkelHJuulcommented, Aug 1, 2019

I will look at it in some time; on vacation for another week!

0reactions
tipsycommented, Dec 14, 2019

I think this was closed by #825 ?

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found