Skip to content
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

Can return HTTPStatus member when default response is declared #1918

Merged
merged 3 commits into from
May 30, 2024
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)
Ruwann marked this conversation as resolved.
Show resolved Hide resolved
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
Loading