-
-
Notifications
You must be signed in to change notification settings - Fork 766
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 async app #1613
Add async app #1613
Conversation
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.
Self review containing some explanations and TODOs still for this PR.
body = cls.jsonifier.dumps(data) | ||
elif not (isinstance(data, bytes) or isinstance(data, str)): | ||
warnings.warn( | ||
"Implicit (flask) JSON serialization will change in the next major version. " |
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.
Removed this deprecated behavior and lifted the method to the base class.
return request | ||
def get_request(cls, **kwargs) -> ConnexionRequest: | ||
uri_parser = kwargs.pop("uri_parser") | ||
return ConnexionRequest(flask.request, uri_parser=uri_parser) |
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.
I simplified the ConnexionRequest since I don't believe we should still provide such a high abstraction layer here anymore. This should only be implemented for Flask and Starlette. Other frameworks are supported via the ASGI interface.
return getattr(flask.globals.request_ctx, "connexion_context") | ||
|
||
|
||
context = LocalProxy(_get_context) |
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.
Connexion context is now provided by the connexion.context module and the Context Middleware.
) | ||
|
||
api_base_path = connexion_context.get("api_base_path") | ||
if api_base_path and not api_base_path == self.base_path: |
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 might be able to leverage the RoutedMiddleware base classes here, will try to rework.
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.
This might be possible, but there's some specific differences between the app and middleware which I'm not sure we can or should modify. Eg. apis on the app are nestable, while on the middleware they are not. More work would be needed to properly support this on the middleware.
Still something we can look at, but would do so in a separate PR.
@@ -172,7 +172,7 @@ def test_path_parameter_someint__bad(simple_app): | |||
# non-integer values will not match Flask route | |||
app_client = simple_app.app.test_client() | |||
resp = app_client.get("/v1.0/test-int-path/foo") # type: flask.Response | |||
assert resp.status_code == 400, resp.text | |||
assert resp.status_code == 404, resp.text |
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.
Due to the fix for the typed path params, we now return a 404 again instead of a 400 when sending the wrong type of path parameter. This is because the request is no longer matched by the router, so it doesn't hit the parameter validation. It is either rejected by the Middleware router, or directly passed to the App router, where it is rejected.
@@ -59,7 +59,7 @@ paths: | |||
'200': | |||
description: Requested new_stack data model | |||
content: | |||
text/plain: | |||
application/json: |
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 no longer parse the response with json for non json response types.
def _serialize_data(cls, data, mimetype): | ||
pass | ||
if isinstance(mimetype, str) and is_json_mimetype(mimetype): |
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.
Would be nice if we could make this pluggable.
from connexion.datastructures import MediaTypeDict | ||
|
||
|
||
def test_media_type_dict(): |
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.
This file wasn't added to git yet in the PR where I introduced the MediaTypeDict type, so including it here.
3f9343d
to
33c9726
Compare
cf88d51
to
406feae
Compare
Pull Request Test Coverage Report for Build 3783178053
💛 - Coveralls |
406feae
to
0add539
Compare
Merging this so I can continue the work on fresh PRs. |
Fixes #1534
Changes proposed in this pull request:
There's some more work to be done, but this PR is already quite huge, so I wanted to stop at a point where I got all the tests and a simple example working.
await
. The decorators should then run the sync route in a threadpool to prevent blocking.