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.

Multiple ResponseSchemas

See original GitHub issue
@ResponseSchema({200: SomeObject, 400: SomeErrorObject})
handler() { ... }

_Originally posted by @epiphone in https://github.com/epiphone/routing-controllers-openapi/pull/9#issuecomment-412455027_

Hi! Thanks for making this awesome library. I have a use case for multiple ResponseSchemas, what do you think of the mapping implementation as referenced in the above comment? If it sounds good I can work on implementing it.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:12 (12 by maintainers)

github_iconTop GitHub Comments

1reaction
godwinpangcommented, Sep 2, 2020

opened up a PR @epiphone 😃

1reaction
epiphonecommented, Sep 2, 2020

So if I got it right (tests to verify this would be great) multiple ResponseSchemas work right now as long as each decorator uses a different statusCode or contentType. This is thanks to _.merge’s deep merging logic.

What doesn’t work is the case @thaigillespie described above, i.e., multiple ResponseSchemas for the same statusCode and contentType. oneOf seems like a good solution here indeed, probably implemented as part of the merging logic here: https://github.com/epiphone/routing-controllers-openapi/blob/81bfab558be469d058be1d048d4993072bb576df/src/decorators.ts#L58.

One downside of oneOf is that swagger-ui still can’t render it. I think other doc viewers like https://github.com/Redocly/redoc can though.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Swagger; specify two responses with same code based on ...
I have a GET with an optional parameter; e.g., GET /endpoint?selector=foo . I want to return a 200 whose schema is different based...
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 >
Allow for multiple response schemas for each response code
I'd reflexively written response schemas using oneOf to point to different responses and only later discovered that although they're valid JSON ...
Read more >
Describing Responses - Swagger
The schema keyword is used to describe the response body. A schema can define: an object or an array — typically used with...
Read more >
How to define multiple responses and response codes for an ...
How to create multiple responses and response code like 200, 500,..etc for an API operation with schema and response components Blog link ...
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