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:
- Created 3 years ago
- Comments:12 (12 by maintainers)
Top 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 >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
opened up a PR @epiphone 😃
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
orcontentType
. 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
andcontentType
.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.