diff --git a/connexion/apis/aiohttp_api.py b/connexion/apis/aiohttp_api.py index bbc082452..0b2ae0ac4 100644 --- a/connexion/apis/aiohttp_api.py +++ b/connexion/apis/aiohttp_api.py @@ -322,7 +322,8 @@ async def get_request(cls, req): body=body, json_getter=lambda: cls.jsonifier.loads(body), files={}, - context=req) + context=req, + cookies=req.cookies) @classmethod async def get_response(cls, response, mimetype=None, request=None): diff --git a/connexion/apis/flask_api.py b/connexion/apis/flask_api.py index b90c3da6e..6db86a4f7 100644 --- a/connexion/apis/flask_api.py +++ b/connexion/apis/flask_api.py @@ -244,7 +244,8 @@ def get_request(cls, *args, **params): json_getter=lambda: flask_request.get_json(silent=True), files=flask_request.files, path_params=params, - context=context_dict + context=context_dict, + cookies=flask_request.cookies, ) logger.debug('Getting data and status code', extra={ diff --git a/connexion/lifecycle.py b/connexion/lifecycle.py index b6db65244..acbbe13fc 100644 --- a/connexion/lifecycle.py +++ b/connexion/lifecycle.py @@ -16,7 +16,8 @@ def __init__(self, body=None, json_getter=None, files=None, - context=None): + context=None, + cookies=None): self.url = url self.method = method self.path_params = path_params or {} @@ -27,6 +28,7 @@ def __init__(self, self.json_getter = json_getter self.files = files self.context = context if context is not None else {} + self.cookies = cookies or {} @property def json(self): diff --git a/tests/aiohttp/test_aiohttp_simple_api.py b/tests/aiohttp/test_aiohttp_simple_api.py index 2f1b6273e..7e67c2c4f 100644 --- a/tests/aiohttp/test_aiohttp_simple_api.py +++ b/tests/aiohttp/test_aiohttp_simple_api.py @@ -189,6 +189,19 @@ async def test_pythonic_path_param(aiohttp_api_spec_dir, aiohttp_client): assert j['id_'] == 100 +async def test_cookie_param(aiohttp_api_spec_dir, aiohttp_client): + app = AioHttpApp(__name__, port=5001, + specification_dir=aiohttp_api_spec_dir, + debug=True) + app.add_api('openapi_simple.yaml', pass_context_arg_name="request") + + app_client = await aiohttp_client(app.app) + response = await app_client.get('/v1.0/test-cookie-param', headers={"Cookie": "test_cookie=hello"}) + assert response.status == 200 + j = await response.json() + assert j['cookie_value'] == "hello" + + async def test_swagger_ui_static(aiohttp_api_spec_dir, aiohttp_client): app = AioHttpApp(__name__, port=5001, specification_dir=aiohttp_api_spec_dir, diff --git a/tests/api/test_parameters.py b/tests/api/test_parameters.py index aa8c0fd47..358e8d30b 100644 --- a/tests/api/test_parameters.py +++ b/tests/api/test_parameters.py @@ -480,3 +480,11 @@ def test_get_unicode_request(simple_app): resp = app_client.get('/v1.0/get_unicode_request?price=%C2%A319.99') # £19.99 assert resp.status_code == 200 assert json.loads(resp.data.decode('utf-8'))['price'] == '£19.99' + + +def test_cookie_param(simple_app): + app_client = simple_app.app.test_client() + app_client.set_cookie("localhost", "test_cookie", "hello") + response = app_client.get("/v1.0/test-cookie-param") + assert response.status_code == 200 + assert response.json == {"cookie_value": "hello"} diff --git a/tests/fakeapi/aiohttp_handlers.py b/tests/fakeapi/aiohttp_handlers.py index e37af67fc..31007a5f5 100755 --- a/tests/fakeapi/aiohttp_handlers.py +++ b/tests/fakeapi/aiohttp_handlers.py @@ -105,3 +105,7 @@ async def get_date(): async def get_uuid(): return ConnexionResponse(body={'value': uuid.UUID(hex='e7ff66d0-3ec2-4c4e-bed0-6e4723c24c51')}) + + +async def test_cookie_param(request): + return {"cookie_value": request.cookies["test_cookie"]} diff --git a/tests/fakeapi/hello/__init__.py b/tests/fakeapi/hello/__init__.py index 997c2ac0c..d5a028401 100644 --- a/tests/fakeapi/hello/__init__.py +++ b/tests/fakeapi/hello/__init__.py @@ -330,6 +330,10 @@ def test_required_param(simple): return simple +def test_cookie_param(): + return {"cookie_value": request.cookies["test_cookie"]} + + def test_exploded_deep_object_param(id): return id diff --git a/tests/fixtures/aiohttp/openapi_simple.yaml b/tests/fixtures/aiohttp/openapi_simple.yaml index 41a66578f..215aeb6f1 100644 --- a/tests/fixtures/aiohttp/openapi_simple.yaml +++ b/tests/fixtures/aiohttp/openapi_simple.yaml @@ -20,3 +20,16 @@ paths: '200': description: ok security: [] + /test-cookie-param: + get: + summary: Test cookie parameter support. + operationId: fakeapi.aiohttp_handlers.test_cookie_param + parameters: + - name: test_cookie + in: cookie + required: true + schema: + type: string + responses: + '200': + description: OK diff --git a/tests/fixtures/simple/openapi.yaml b/tests/fixtures/simple/openapi.yaml index a448830c6..b76e7dd46 100644 --- a/tests/fixtures/simple/openapi.yaml +++ b/tests/fixtures/simple/openapi.yaml @@ -663,6 +663,19 @@ paths: responses: '200': description: OK + /test-cookie-param: + get: + summary: Test cookie parameter support. + operationId: fakeapi.hello.test_cookie_param + parameters: + - name: test_cookie + in: cookie + required: true + schema: + type: string + responses: + '200': + description: OK /parameters-in-root-path: parameters: - in: query diff --git a/tests/fixtures/simple/swagger.yaml b/tests/fixtures/simple/swagger.yaml index de3db771e..da3b0c7d0 100644 --- a/tests/fixtures/simple/swagger.yaml +++ b/tests/fixtures/simple/swagger.yaml @@ -518,6 +518,15 @@ paths: 200: description: OK + /test-cookie-param: + get: + summary: Test cookie parameter support. + operationId: fakeapi.hello.test_cookie_param + # No parameters because swagger / openapi 2.0 does not support describing cookie parameters. + responses: + 200: + description: OK + /parameters-in-root-path: parameters: - in: query