Skip to content

Commit 2af77e8

Browse files
author
Adam Gray
authored
Allow responses with no content (#66)
Fixes #66
1 parent 590c1a2 commit 2af77e8

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

openapi_python_client/openapi_parser/responses.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def constructor(self) -> str:
8080
def response_from_dict(*, status_code: int, data: Dict[str, Any]) -> Response:
8181
""" Generate a Response from the OpenAPI dictionary representation of it """
8282
if "content" not in data:
83-
raise ParseError(data)
83+
return Response(status_code=status_code)
8484

8585
content = data["content"]
8686
if "application/json" in content:

tests/test_openapi_parser/test_responses.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,16 @@ def test_constructor(self):
9595

9696

9797
class TestResponseFromDict:
98-
def test_response_from_dict_no_content(self):
98+
def test_response_from_dict_no_content(self, mocker):
9999
from openapi_python_client.openapi_parser.responses import response_from_dict
100100

101-
with pytest.raises(ValueError):
102-
response_from_dict(status_code=200, data={})
101+
Response = mocker.patch(f"{MODULE_NAME}.Response")
102+
103+
status_code = mocker.MagicMock(autospec=int)
104+
response = response_from_dict(status_code=status_code, data={})
105+
106+
Response.assert_called_once_with(status_code=status_code)
107+
assert response == Response()
103108

104109
def test_response_from_dict_unsupported_content_type(self):
105110
from openapi_python_client.openapi_parser.responses import response_from_dict

0 commit comments

Comments
 (0)