diff --git a/connexion/decorators/response.py b/connexion/decorators/response.py index 160ace61c..0aa58870d 100644 --- a/connexion/decorators/response.py +++ b/connexion/decorators/response.py @@ -138,7 +138,8 @@ def _unpack_handler_response( elif len(handler_response) == 2: data, status_code_or_headers = handler_response if isinstance(status_code_or_headers, int): - status_code = status_code_or_headers + # Extra int call because of int subclasses such as http.HTTPStatus (IntEnum) + status_code = int(status_code_or_headers) elif isinstance(status_code_or_headers, Enum) and isinstance( status_code_or_headers.value, int ): diff --git a/tests/api/test_responses.py b/tests/api/test_responses.py index e9649bf0c..afcb39c49 100644 --- a/tests/api/test_responses.py +++ b/tests/api/test_responses.py @@ -140,6 +140,13 @@ def test_pass_through(simple_app): ) +def test_can_use_httpstatus_enum(simple_openapi_app): + app_client = simple_openapi_app.test_client() + + response = app_client.get("/v1.0/httpstatus") + assert response.status_code == 201 + + def test_empty(simple_app): app_client = simple_app.test_client() diff --git a/tests/fakeapi/hello/__init__.py b/tests/fakeapi/hello/__init__.py index de2af8fdd..b6d6c00ac 100644 --- a/tests/fakeapi/hello/__init__.py +++ b/tests/fakeapi/hello/__init__.py @@ -1,6 +1,7 @@ import asyncio import datetime import uuid +from http import HTTPStatus import flask from connexion import NoContent, ProblemException, context, request @@ -737,3 +738,7 @@ def get_streaming_response(): async def async_route(): return {}, 200 + + +def httpstatus(): + return {}, HTTPStatus.CREATED diff --git a/tests/fixtures/simple/openapi.yaml b/tests/fixtures/simple/openapi.yaml index c4ce61773..e183a1cb9 100644 --- a/tests/fixtures/simple/openapi.yaml +++ b/tests/fixtures/simple/openapi.yaml @@ -1316,7 +1316,23 @@ paths: responses: 200: description: 'OK' - + /httpstatus: + get: + operationId: fakeapi.hello.httpstatus + responses: + 201: + description: "happy path" + default: + description: "default" + content: + application/json: + schema: + type: object + properties: + error_code: + type: integer + required: + - error_code servers: - url: http://localhost:{port}/{basePath}