From 038d36cef60e36e877244d6501007f56311a544a Mon Sep 17 00:00:00 2001 From: Robbe Sneyders Date: Mon, 19 Sep 2022 21:52:03 +0200 Subject: [PATCH] Explicitly support Flask async routes --- setup.py | 2 +- tests/api/test_bootstrap.py | 6 ++++++ tests/fakeapi/hello/__init__.py | 4 ++++ tests/fixtures/simple/openapi.yaml | 7 +++++++ tests/fixtures/simple/swagger.yaml | 7 +++++++ 5 files changed, 25 insertions(+), 1 deletion(-) diff --git a/setup.py b/setup.py index c9c1a1117..3636247cb 100755 --- a/setup.py +++ b/setup.py @@ -33,7 +33,7 @@ def read_version(package): swagger_ui_require = 'swagger-ui-bundle>=0.0.2,<0.1' flask_require = [ - 'flask>=2.2,<3', + 'flask[async]>=2.2,<3', 'a2wsgi>=1.4,<2', ] diff --git a/tests/api/test_bootstrap.py b/tests/api/test_bootstrap.py index a303dff7e..cd95f8bbb 100644 --- a/tests/api/test_bootstrap.py +++ b/tests/api/test_bootstrap.py @@ -361,3 +361,9 @@ def test_using_all_fields_in_path_item(simple_api_spec_dir): continue test_methods.update({method.lower() for method in rule.methods}) assert set(test_methods) == METHODS + + +def test_async_route(simple_app): + app_client = simple_app.app.test_client() + resp = app_client.get("/v1.0/async-route") + assert resp.status_code == 200 diff --git a/tests/fakeapi/hello/__init__.py b/tests/fakeapi/hello/__init__.py index 0e40d4635..0d1c3bca0 100644 --- a/tests/fakeapi/hello/__init__.py +++ b/tests/fakeapi/hello/__init__.py @@ -647,3 +647,7 @@ def nullable_default(test): def get_streaming_response(): return send_file(__file__) + + +async def async_route(): + return {}, 200 diff --git a/tests/fixtures/simple/openapi.yaml b/tests/fixtures/simple/openapi.yaml index 88f5c5144..58fdc1193 100644 --- a/tests/fixtures/simple/openapi.yaml +++ b/tests/fixtures/simple/openapi.yaml @@ -1239,6 +1239,13 @@ paths: responses: '200': description: Echo the validated request. + /async-route: + get: + operationId: fakeapi.hello.async_route + responses: + 200: + description: 'OK' + servers: - url: http://localhost:{port}/{basePath} diff --git a/tests/fixtures/simple/swagger.yaml b/tests/fixtures/simple/swagger.yaml index 7359ac8e1..f6543da6d 100644 --- a/tests/fixtures/simple/swagger.yaml +++ b/tests/fixtures/simple/swagger.yaml @@ -1046,6 +1046,13 @@ paths: schema: type: file + /async-route: + get: + operationId: fakeapi.hello.async_route + responses: + 200: + description: 'OK' + definitions: new_stack: type: object