Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion connexion/decorators/response.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
):
Expand Down
7 changes: 7 additions & 0 deletions tests/api/test_responses.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
5 changes: 5 additions & 0 deletions tests/fakeapi/hello/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import asyncio
import datetime
import uuid
from http import HTTPStatus

import flask
from connexion import NoContent, ProblemException, context, request
Expand Down Expand Up @@ -737,3 +738,7 @@ def get_streaming_response():

async def async_route():
return {}, 200


def httpstatus():
return {}, HTTPStatus.CREATED
18 changes: 17 additions & 1 deletion tests/fixtures/simple/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down