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.

Defining multiple responses

See original GitHub issue

I’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:closed
  • Created 5 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
lafrechcommented, Oct 15, 2018

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 an Exception 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.

1reaction
fbergrothcommented, Oct 15, 2018

@thing_bp.doc(responses={...}) seems to work well.

Read more comments on GitHub >

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

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