flask-restful-swagger
flask-restful-swagger copied to clipboard
handle optional object ids in url
It's useful to consolidate GET requests for single or multiple objects as follows:
class Todo(Resource):
@swagger.operation()
def get(self, todo_id=None):
# return single or multiple todos depending if todo_id is None
api.add_resource(Todo, '/todo', '/todo/<todo_id>')
If I understand correctly, flask-restful-swagger only recognizes the first url and ignores the second url option. Perhaps we could support multiple decorators, one per url?
usually you want to use two different mapping for this: (with two different methods)
/todo/<todo_id>
and
/todos
Even if you wanted to have the same URL e.g. /todo/id and /todo (which in English is a bit confusing but ok...) you would still want to bind them to different methods I believe, it makes the methods a little easier and code a little easier to read.
@rantav flask-restful-swagger binds the swagger docs of the HTTP methods supported by the resource. if we have two endpoints /todo/ and /todo/id, they will have to be get methods of two different resources (correct me if i am wrong). Having two difference resources adds of lot of unnecessary code.