Defining multiple responses
See original GitHub issueI’d like to define multiple response codes for a view (201 for created, 200 for updated).
It seems that decorating a view twice will always return 200:
@thing_bp.response(ThingSchema, code=200, description='Thing was updated')
@thing_bp.response(ThingSchema, code=201, description='Thing was created')
def post(...)
Is there a way around this?
Thanks
Issue Analytics
- State:
- Created 5 years ago
- Comments:7 (3 by maintainers)
Top Results From Across the Web
Multiple Response Analysis
Multiple Response Sets. When a survey question can be answered multiple valid times, such as questions which note "Check all that apply", multiple...
Read more >Multiple response analysis
OverviewEdit. Multiple response analysis is a frequency analysis for data which include more than one response per participant, ...
Read more >Define multiple responses for each route
Multiple responses can be defined for each route with different body, headers and status. Learn how to create them and randomize them.
Read more >Multiple response: Define sets
Define multiple response sets ... Analyze > Multiple Response > Define Variable Sets. ... Click Add to add the current list to the...
Read more >Creating and Using a Multiple-Response Set in SPSS
A multiple-response set can contain a number of variables of various types, but it must be based on two or more dichotomy variables...
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
The framework is based on a few opinionated choices. The way we use it, the view function can only return the “normal” response, the one for which the status code is specified in the
@response
decorator.Then there can be errors that interrupt the normal flow and generate an
abort(another_status_code)
.Indeed, you can document other responses using
@doc
. It is precisely meant to add documentation that is not grabbed generated from the code. BTW, I’d like to make it easier to document error responses. I’m working on apispec to make this easier by allowing to declare reusable response components.However, calling twice the
@response
decorator is not supported. I’m pretty sure that would end up in a mess. I could add a check and raise anException
if someone attempts to do that.So you can document the two error codes using
@doc
, but how do you manage to actually return those error codes?What is your use case? I suppose you’re allowing PUT to create entities. Whether this is good practice is debated AFAIK. This is not something we do so we never tried to support it. We only use POST to create and PUT to update.
@thing_bp.doc(responses={...})
seems to work well.