flask-restful-swagger icon indicating copy to clipboard operation
flask-restful-swagger copied to clipboard

handle optional object ids in url

Open livni opened this issue 11 years ago • 2 comments

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?

livni avatar Nov 02 '14 15:11 livni

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 avatar Nov 02 '14 21:11 rantav

@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.

praveen-p avatar Jul 30 '15 04:07 praveen-p