jmcarp / flask-apispec

MIT License
655 stars 157 forks source link

combining get one and get all in a MethodView's get() method #120

Open twosigmajab opened 6 years ago

twosigmajab commented 6 years ago

http://flask.pocoo.org/docs/0.12/views/#method-views-for-apis demonstrates how to implement a get method on a MethodView that handles both the "get all" case (e.g. GET /todos/) as well as the "get one by id" case (e.g. GET /todos/1), and how to set up the url rules appropriately.

When I tried to adapt this to a simple class that extends flask_apispec.MethodResource, I got an error like this:

  File ".../flask_apispec/paths.py", line 39, in argument_to_param
    type_, format_ = CONVERTER_MAPPING.get(type(rule._converters[argument]), DEFAULT_TYPE)
KeyError: 'id'

The examples on https://flask-apispec.readthedocs.io/en/latest/usage.html only show how to set up a separate function outside the MethodResource to implement "get all" (namely list_pets()). Does flask-apispec not support combining the "get all" functionality into the MethodResource.get(...), method as Flask's "MethodViews for APIs" docs suggest? Thanks.

jasonamyers commented 5 years ago

@twosigmajab did you ever figure this one out?

twosigmajab commented 5 years ago

I ended up switching to Flask-Rebar and haven't looked back since. Its APIs are fantastic and the maintainers are extremely responsive!