Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow alt_response on MethodView #280

Open
der-joel opened this issue Sep 22, 2021 · 5 comments
Open

Allow alt_response on MethodView #280

der-joel opened this issue Sep 22, 2021 · 5 comments

Comments

@der-joel
Copy link

It would be a nice enhancement to allow the usage of the alt_response-Decorator on MethodView-classes.
It could act as a shortcut to decorating every endpoint of the view with alt_response.

An example use case would be a custom converter that rejects any pet_id not present in the pet database.
Since its declared in the route-decorator, every endpoint will raise 404 if the pet was not found:

@blp.route('/<object_id(must_exist=True):pet_id>')
@blp.alt_response(404, ErrorSchema)
class PetsById(MethodView):

    @blp.response(200, PetSchema)
    def get(self, pet_id):
        """Get pet by ID"""
        return Pet.get_by_id(pet_id)

    @blp.response(204)
    def delete(self, pet_id):
        """Delete pet"""
        Pet.delete(pet_id)
@lafrech
Copy link
Member

lafrech commented Sep 27, 2021

This makes sense. I have a few other things listed for alt_response (#256, #260). We could do this as well.

Would you like to investigate any further?

@zedrdave
Copy link

zedrdave commented Aug 16, 2023

From what I can see, this feature has been added now?

Unfortunately it seems like adding alt_response on MethodView makes method-level response get ignored… Is this intended?

If not, should I file a separate issue or is this already listed (I couldn't find anything)?

Edit: in fact, it seems like all method-level annotations (eg Docstrings) get ignored when providing a class-level alt_response… Obviously that seems undesirable and a bug 😅

@lafrech
Copy link
Member

lafrech commented Aug 16, 2023

I don't remember but from your findings, the use case is still unsupported. It just seems to work but screws everything up.

Let's keep the discussion in this thread.

@zedrdave
Copy link

Thanks! My bad then: just assumed it had been implemented, but if it's still WIP, feel free to ignore the above comment 😉

@lafrech
Copy link
Member

lafrech commented Aug 16, 2023

No pb. Your comment may help someone facing the same issue.

As you can see, it is not really in progress, unless someone wants to take charge.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants