Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 2 additions & 2 deletions end_to_end_tests/golden-record-custom/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ include = ["CHANGELOG.md", "custom_e2e/py.typed"]

[tool.poetry.dependencies]
python = "^3.6"
httpx = "^0.15.0"
attrs = "^20.1.0"
httpx = ">=0.15.0, <=0.22.0"
attrs = ">=20.1.0, <22.0"
python-dateutil = "^2.8.0"

[tool.black]
Expand Down
4 changes: 2 additions & 2 deletions end_to_end_tests/golden-record/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ include = ["CHANGELOG.md", "my_test_api_client/py.typed"]

[tool.poetry.dependencies]
python = "^3.6"
httpx = "^0.15.0"
attrs = "^20.1.0"
httpx = ">=0.15.0, <=0.22.0"
attrs = ">=20.1.0, <22.0"
python-dateutil = "^2.8.0"

[tool.black]
Expand Down
2 changes: 1 addition & 1 deletion openapi_python_client/parser/openapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ def _add_responses(*, endpoint: "Endpoint", data: oai.Responses, schemas: Schema
ParseError(
detail=(
f"Cannot parse response for status code {code}, "
f"response will be ommitted from generated client"
f"response will be omitted from generated client"
),
data=response.data,
)
Expand Down
1 change: 1 addition & 0 deletions openapi_python_client/parser/responses.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class Response:
"application/json": "response.json()",
"application/octet-stream": "response.content",
"text/html": "response.text",
"text/yaml": "response.text",
}


Expand Down
4 changes: 2 additions & 2 deletions tests/test_parser/test_openapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,12 +312,12 @@ def test__add_responses(self, mocker):
response_1 = Response(
status_code=200,
source="source",
prop=DateTimeProperty(name="datetime", required=True, nullable=False, default=None),
prop=DateTimeProperty(name="datetime", required=True, nullable=False, default=None, description=None),
)
response_2 = Response(
status_code=404,
source="source",
prop=DateProperty(name="date", required=True, nullable=False, default=None),
prop=DateProperty(name="date", required=True, nullable=False, default=None, description=None),
)
response_from_data = mocker.patch(
f"{MODULE_NAME}.response_from_data", side_effect=[(response_1, schemas_1), (response_2, schemas_2)]
Expand Down
35 changes: 28 additions & 7 deletions tests/test_parser/test_responses.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,20 @@ def test_response_from_data_no_content():
from openapi_python_client.parser.responses import Response, response_from_data

response, schemas = response_from_data(
status_code=200, data=oai.Response.construct(description=""), schemas=Schemas(), parent_name="parent"
status_code=200, data=oai.Response.construct(description="description"), schemas=Schemas(), parent_name="parent"
)

assert response == Response(
status_code=200,
prop=NoneProperty(name="response_200", default=None, nullable=False, required=True),
prop=NoneProperty(name="response_200", default=None, nullable=False, required=True, description=None),
source="None",
)


def test_response_from_data_unsupported_content_type():
from openapi_python_client.parser.responses import response_from_data

data = oai.Response.construct(description="", content={"blah": None})
data = oai.Response.construct(description="description", content={"blah": None})
response, schemas = response_from_data(status_code=200, data=data, schemas=Schemas(), parent_name="parent")

assert response == ParseError(data=data, detail="Unsupported content_type {'blah': None}")
Expand All @@ -33,10 +33,9 @@ def test_response_from_data_no_content_schema():

data = oai.Response.construct(description="", content={"application/json": oai.MediaType.construct()})
response, schemas = response_from_data(status_code=200, data=data, schemas=Schemas(), parent_name="parent")

assert response == Response(
status_code=200,
prop=NoneProperty(name="response_200", default=None, nullable=False, required=True),
prop=NoneProperty(name="response_200", default=None, nullable=False, required=True, description=None),
source="None",
)

Expand All @@ -46,7 +45,7 @@ def test_response_from_data_property_error(mocker):

property_from_data = mocker.patch.object(responses, "property_from_data", return_value=(PropertyError(), Schemas()))
data = oai.Response.construct(
description="", content={"application/json": oai.MediaType.construct(media_type_schema="something")}
description="description", content={"application/json": oai.MediaType.construct(media_type_schema="something")}
)
response, schemas = responses.response_from_data(
status_code=400, data=data, schemas=Schemas(), parent_name="parent"
Expand All @@ -61,7 +60,7 @@ def test_response_from_data_property_error(mocker):
def test_response_from_data_property(mocker):
from openapi_python_client.parser import responses

prop = StringProperty(name="prop", required=True, nullable=False, default=None)
prop = StringProperty(name="prop", required=True, nullable=False, default=None, description=None)
property_from_data = mocker.patch.object(responses, "property_from_data", return_value=(prop, Schemas()))
data = oai.Response.construct(
description="", content={"application/json": oai.MediaType.construct(media_type_schema="something")}
Expand All @@ -78,3 +77,25 @@ def test_response_from_data_property(mocker):
property_from_data.assert_called_once_with(
name="response_400", required=True, data="something", schemas=Schemas(), parent_name="parent"
)


def test_response_from_data_property_of_type_text_yaml(mocker):
from openapi_python_client.parser import responses

prop = StringProperty(name="prop", required=True, nullable=False, default=None, description=None)
property_from_data = mocker.patch.object(responses, "property_from_data", return_value=(prop, Schemas()))
data = oai.Response.construct(
description="", content={"text/yaml": oai.MediaType.construct(media_type_schema="something")}
)
response, schemas = responses.response_from_data(
status_code=400, data=data, schemas=Schemas(), parent_name="parent"
)

assert response == responses.Response(
status_code=400,
prop=prop,
source="response.text",
)
property_from_data.assert_called_once_with(
name="response_400", required=True, data="something", schemas=Schemas(), parent_name="parent"
)