Support multiple status codes and schemas with responds
See original GitHub issueCurrently, only a single responds
decorator may be provided, optionally with a status_code
. Support for multiple schemas corresponding to different status codes would be straightforward to implement by inspecting the return type and mapping the status_code to the schema, if it is available.
The current functionality for ignoring pre-made Flask Responses would need to be modified to only ignore those for which it does not have a corresponding Schema.
The status code of the response can come from any of the normal Flask means (i.e. as a data, code, headers
tuple, via make_response, etc)
Issue Analytics
- State:
- Created 4 years ago
- Reactions:15
- Comments:7 (3 by maintainers)
Top Results From Across the Web
Swagger; specify two responses with same code based on ...
OAS2 does not support multiple response schemas per status code. You can only have a single schema, for example, a free-form object (...
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 >Describing Responses - Swagger
A response is defined by its HTTP status code and the data returned in the response body ... This is useful if multiple...
Read more >Swagger responses - Multiple response codes with t...
Hi! Is it possible to have multiple codes use the same schema without duplicating the schema-reference? I.e.: responses: '202': description: ...
Read more >How to define multiple responses and response codes for an ...
With this video we will learn following in Open API specification 3.0 (OAS):1. How to define multiple responses and response codes for an ......
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 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
Firstly thanks for this handy package!
That would be a really nice feature! If I find some spare time I will try to open a PR for this
For the time being here is my workaround in case you want to achieve this with Marshmallow schemas:
where ns is the Namespace or Api, and the schemas are Marshmallow schemas
Hi!
I agree with the premise that we don’t want to break backwards compatibility. Beyond that, a proposal that provides something like a dict mapping of status codes to associated schemas would seem solid. The decorator code can check for this argument or the type of the argument and react accordingly. This seems straightforward and prevents any need for stacking decorators. To extend an existing responds decorator, simply convert the single params to a dict of status_code:schema.
I’d happily review a tested PR and cut a release, but candidly the likelihood that I can find time to address this any time soon is very small.
-AJ
Sent from my iPhone