Skip to content

Commit

Permalink
Can return HTTPStatus member when default response is declared
Browse files Browse the repository at this point in the history
  • Loading branch information
chbndrhnns committed Apr 30, 2024
1 parent fcfe151 commit c21a788
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 2 deletions.
6 changes: 5 additions & 1 deletion connexion/middleware/response_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,11 @@ async def wrapped_send(message: t.MutableMapping[str, t.Any]) -> None:
if message["status"] < 400:
self.validate_mime_type(mime_type)

status = str(message["status"])
try:
status = str(message["status"].value)
except AttributeError:
status = str(message["status"])

response_definition = self._operation.response_definition(
status, mime_type
)
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

0 comments on commit c21a788

Please sign in to comment.