Skip to content
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

Add support for location='view_args' #301

Closed
teodorkostov opened this issue May 19, 2022 · 2 comments · Fixed by #302
Closed

Add support for location='view_args' #301

teodorkostov opened this issue May 19, 2022 · 2 comments · Fixed by #302
Assignees

Comments

@teodorkostov
Copy link

To validate path arguments with webargs the location value that has to be used is view_args. Documentation link.

The following code

from webargs.flaskparser import use_args
@use_args(IdSchema, location='view_args')

should be possible to be written as

from apiflask import APIFlask
app = APIFlask(__name__)
@app.input(IdSchema, location='view_args')
@teodorkostov teodorkostov changed the title Add support for location=view_args Add support for location='view_args' May 19, 2022
@greyli greyli self-assigned this May 19, 2022
@greyli
Copy link
Member

greyli commented May 19, 2022

Thanks for reporting on this. I will add the path and view_args locations later.

I have some doubts about this. If a view accepts a path schema, then the view function will have to declare both the path variables (one by one) and the path schema data:

@app.get('/pets/<id>/<name>/<category>')
@app.input(PathSchema, location='path')
def hello(id, name, category, path_data):
    ...

Is it the correct usage?

@teodorkostov
Copy link
Author

@greyli Correct. Unfortunately, the path_data is passed as another dictionary after all the path arguments. I do not know the reasoning behind it but this is the implementation from webargs.

Thank you for this fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants