-
Notifications
You must be signed in to change notification settings - Fork 23
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
Only single path added for Flask API MethodViews #14
Comments
Comment by lafrech That would be an interesting enhancement, indeed. Would you like to take a stab at it? |
Comment by mathewmarcus If there's interest in adding it then yes definitely |
Comment by mathewmarcus Just wanted to lay out what I see as two directions we could take.
with app.test_request_context():
spec.add_paths(view=user_view)
with app.test_request_context():
spec.add_path(path='/users/', view=user_view, operations=dict(get={}))
spec.add_path(path='/users/', view=user_view, operations=dict(post={}))
spec.add_path(path='/users/{user_id}', view=user_view, operations=dict(get={}, put={}, delete={})) Which option would you prefer? Or do you see a better way to accomplish this? |
Comment by dankolbman Currently running into this exact problem. One more thing to consider is how to handle docstrings. The two rules |
Comment by lafrech @mathewmarcus I've had a quick look at it today. I think the second option is reasonable. It is not that verbose. Those three calls could reduce to only two. Besides, if I understand correctly, the purpose of the flask helper is to parse the YAML, so you don't need to pass the whole operation descriptions, only the method names, right? with app.test_request_context():
spec.add_path(path='/users/', view=user_view, methods=['get', 'post'])
spec.add_path(path='/users/{user_id}', view=user_view, methods=['get', 'put', 'delete']) Regarding @dankolbman's question about I can't really remember and I'm not impacted because I don't use this helper: I don't use YAML docstrings, and I have another layer on top of apispec that calls I declare my CRUD resources using two Here's an example. It uses flask-rest-api, a layer over apispec, which provides all the decorators and calls blp = Blueprint('test', __name__, url_prefix='/test')
@blp.route('/')
class Resource(MethodView):
@blp.response(DocSchema(many=True))
def get(self):
return collection.items
@blp.arguments(DocSchema)
@blp.response(DocSchema)
def post(self, new_item):
return collection.post(new_item)
@blp.route('/<int:item_id>')
class ResourceById(MethodView):
@blp.response(DocSchema)
def get(self, item_id):
return collection.get_or_404(item_id)
@blp.arguments(DocSchema)
@blp.response(DocSchema)
def put(self, new_item, item_id):
collection.get_or_404(item_id)
return collection.put(item_id, new_item)
@blp.response(code=204)
def delete(self, item_id):
collection.get_or_404(item_id)
collection.delete(item_id) I'm afraid I'm not being very helpful. |
Comment by mathewmarcus @lafrech on the contrary, that definitely clears things up. And I agree that separating the routes into two In any case, I can move ahead on the second option. |
Comment by ergo I think I had similar problem in pyramid, maybe the approach I used there could help? https://github.com/ergo/pyramid_apispec - one can register same view with different conditions for introspection. |
Could this be added? We're working on a large scale API (which is already in production) and recently found out our swagger documentation is invalid due to this (quite silent warning):
Could you at least add a logger statement which warns about this because it took us about 4 hours to debug (we're using flask-apispec to generate the docs, so this wasn't very apparent to us) :( |
Has there been any additional thought/movement on this? Ever since the issue was migrated it seems it's gone stale. This is a very common scenario for REST APIs, so it would be great to have this logic included. |
Is there any update on this issue? Would come very handy. |
Issue by mathewmarcus
Thursday Jan 18, 2018 at 21:14 GMT
Originally opened as marshmallow-code/apispec#181
The Flask documentation gives a use case - for RESTful APIs - where a single method view can be added under multiple URL rules. The following code snippet is provided as an example.
If we define the following apispec and add the above view function like so
only one of the above paths would be included in the generated apispec.
Looking at the
apispec.ext.flask
module, it seems that this behavior is a result of line 92 in the_rule_for_view
function.Given the comment, it seems like this behavior is expected. Is there any interest in/intent to modify this to enable all of the paths to be added to the apispec in the above situation?
The text was updated successfully, but these errors were encountered: