You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This affects all versions. Flask-openapi3 removes all arguments passed to the view by any previous callers -- such as Dependency Injection frameworks, breaking things in the meanwhile.
In request._validate_request all arguments kwargs are removed as they are treated as path args. This is however not always a correct assumption as views from flask-openapi3 may be decorated again before being passed onto flask.
In this case flask calls the views decorated elsewhere which supply some arguments to flask-openapi3 which then simply removes them instead of passing them down. There are a few flask extensions which do this as well.
In the below example the call chain is as follows flask -> inject_services -> flask_openapi3.
Example:
@app.get("/greet")defview(greeter: GreeterService, query: GreetQuery):
returngreeter.greet(query.name)
...
# Automatically decorate all flask views so that known services are passed down.app.view_functions= {k: inject_services(v) fork, vinapp.view_functions.items()}
...
The text was updated successfully, but these errors were encountered:
Using this sort of set-up together with openapi3 means:
flask handles incoming request (routing)
flask-openapi3 checks incoming query-string, body, etc via the _validate_request (validation)
decorators come into play (authorization)
Meaning our authentication decorator goes off AFTER the payload, query-string and all that has been checked.
So we get validation before authorization! Which is in my opinion a bad pattern.
Personally, I think it's better to first check;
Route existence
Authorization
Validation
I don't see a easy solution to this, since the current set-up with _validate_request is on a high level.
Perhaps move the _validate_request logic into a decorator? Then we control the flow by the order of decorators.
Then you could remove all the validation_error_callback logic and just document how to catch ValidationError in a errorhandler on app level. Now you're trying to do everything, which isn't needed IMO.
Environment:
This affects all versions. Flask-openapi3 removes all arguments passed to the view by any previous callers -- such as Dependency Injection frameworks, breaking things in the meanwhile.
In
request._validate_request
all arguments kwargs are removed as they are treated as path args. This is however not always a correct assumption as views from flask-openapi3 may be decorated again before being passed onto flask.In this case flask calls the views decorated elsewhere which supply some arguments to flask-openapi3 which then simply removes them instead of passing them down. There are a few flask extensions which do this as well.
In the below example the call chain is as follows
flask -> inject_services -> flask_openapi3
.Example:
The text was updated successfully, but these errors were encountered: