-
-
Notifications
You must be signed in to change notification settings - Fork 762
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 add_middleware
interface
#1683
Conversation
@@ -27,19 +26,6 @@ def test_app_with_relative_path(simple_api_spec_dir, spec): | |||
assert get_bye.text == "Goodbye jsantos" | |||
|
|||
|
|||
def test_app_with_resolver(simple_api_spec_dir, spec): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These tests only test if the resolver becomes available as api.resolver
, which doesn't really seem that useful.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, it's good to be sure that it's actually the resolver that was passed in 😅 But seems indeed too trivial to have a test for it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes and add_api
no longer returns the same API object. So it's not as easy to test this anymore. I see we don't have an integration test for this either though, I'll add one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We do already have integration tests for this in test_resolver_methodview.py
, so will merge as is.
Pull Request Test Coverage Report for Build 4686618629
💛 - Coveralls |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Makes me think of the Starlette implementation a bit - I wonder whether the same middleware class makes sense here as it does seem elegant.
@@ -27,19 +26,6 @@ def test_app_with_relative_path(simple_api_spec_dir, spec): | |||
assert get_bye.text == "Goodbye jsantos" | |||
|
|||
|
|||
def test_app_with_resolver(simple_api_spec_dir, spec): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, it's good to be sure that it's actually the resolver that was passed in 😅 But seems indeed too trivial to have a test for it
Yes, I went for this approach instead of leveraging the starlette
Happy to hear if you don't agree. |
This PR adds an
add_middleware
method to the apps andConnexionMiddleware
to easily add middleware to the stack. Before, the only way to do this was to pass in a complete middleware stack.The default position to add the new middleware is right before the
ContextMiddleware
, which is the final middleware in the stack. Another position can be selected by passing in aMiddlewarePosition
enum, which defines some positions which make sense.Since we can no longer assume that the whole middleware stack is defined when initializing the
ConnexionMiddleware
, we need to delay building the middleware stack until theConnexionMiddleware
is actually called. This also means we need to delay registering the APIs and error handlers. This is now all done in the_build_middleware_stack
method.