rantav / flask-restful-swagger

A Swagger spec extractor for flask-restful
MIT License
665 stars 215 forks source link

handle optional object ids in url #56

Open livni opened 10 years ago

livni commented 10 years ago

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?

rantav commented 10 years ago

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.

praveen-p commented 9 years ago

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