Skip to content

Commit 0f42964

Browse files
author
Alfonso Tankia
committed
feat: Added support for text/yaml in OpenAPI to be used in benchling-api-client BNCH-37249
1 parent 5fe002c commit 0f42964

File tree

6 files changed

+36
-14
lines changed

6 files changed

+36
-14
lines changed

end_to_end_tests/golden-record-custom/pyproject.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ include = ["CHANGELOG.md", "custom_e2e/py.typed"]
1414

1515
[tool.poetry.dependencies]
1616
python = "^3.6"
17-
httpx = "^0.15.0"
18-
attrs = "^20.1.0"
17+
httpx = ">=0.15.0, <=0.22.0"
18+
attrs = ">=20.1.0, <22.0"
1919
python-dateutil = "^2.8.0"
2020

2121
[tool.black]

end_to_end_tests/golden-record/pyproject.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ include = ["CHANGELOG.md", "my_test_api_client/py.typed"]
1414

1515
[tool.poetry.dependencies]
1616
python = "^3.6"
17-
httpx = "^0.15.0"
18-
attrs = "^20.1.0"
17+
httpx = ">=0.15.0, <=0.22.0"
18+
attrs = ">=20.1.0, <22.0"
1919
python-dateutil = "^2.8.0"
2020

2121
[tool.black]

openapi_python_client/parser/openapi.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ def _add_responses(*, endpoint: "Endpoint", data: oai.Responses, schemas: Schema
177177
ParseError(
178178
detail=(
179179
f"Cannot parse response for status code {code}, "
180-
f"response will be ommitted from generated client"
180+
f"response will be omitted from generated client"
181181
),
182182
data=response.data,
183183
)

openapi_python_client/parser/responses.py

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ class Response:
2222
"application/json": "response.json()",
2323
"application/octet-stream": "response.content",
2424
"text/html": "response.text",
25+
"text/yaml": "response.text",
2526
}
2627

2728

tests/test_parser/test_openapi.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -312,12 +312,12 @@ def test__add_responses(self, mocker):
312312
response_1 = Response(
313313
status_code=200,
314314
source="source",
315-
prop=DateTimeProperty(name="datetime", required=True, nullable=False, default=None),
315+
prop=DateTimeProperty(name="datetime", required=True, nullable=False, default=None, description=None),
316316
)
317317
response_2 = Response(
318318
status_code=404,
319319
source="source",
320-
prop=DateProperty(name="date", required=True, nullable=False, default=None),
320+
prop=DateProperty(name="date", required=True, nullable=False, default=None, description=None),
321321
)
322322
response_from_data = mocker.patch(
323323
f"{MODULE_NAME}.response_from_data", side_effect=[(response_1, schemas_1), (response_2, schemas_2)]

tests/test_parser/test_responses.py

+28-7
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,20 @@ def test_response_from_data_no_content():
99
from openapi_python_client.parser.responses import Response, response_from_data
1010

1111
response, schemas = response_from_data(
12-
status_code=200, data=oai.Response.construct(description=""), schemas=Schemas(), parent_name="parent"
12+
status_code=200, data=oai.Response.construct(description="description"), schemas=Schemas(), parent_name="parent"
1313
)
1414

1515
assert response == Response(
1616
status_code=200,
17-
prop=NoneProperty(name="response_200", default=None, nullable=False, required=True),
17+
prop=NoneProperty(name="response_200", default=None, nullable=False, required=True, description=None),
1818
source="None",
1919
)
2020

2121

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

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

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

3434
data = oai.Response.construct(description="", content={"application/json": oai.MediaType.construct()})
3535
response, schemas = response_from_data(status_code=200, data=data, schemas=Schemas(), parent_name="parent")
36-
3736
assert response == Response(
3837
status_code=200,
39-
prop=NoneProperty(name="response_200", default=None, nullable=False, required=True),
38+
prop=NoneProperty(name="response_200", default=None, nullable=False, required=True, description=None),
4039
source="None",
4140
)
4241

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

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

64-
prop = StringProperty(name="prop", required=True, nullable=False, default=None)
63+
prop = StringProperty(name="prop", required=True, nullable=False, default=None, description=None)
6564
property_from_data = mocker.patch.object(responses, "property_from_data", return_value=(prop, Schemas()))
6665
data = oai.Response.construct(
6766
description="", content={"application/json": oai.MediaType.construct(media_type_schema="something")}
@@ -78,3 +77,25 @@ def test_response_from_data_property(mocker):
7877
property_from_data.assert_called_once_with(
7978
name="response_400", required=True, data="something", schemas=Schemas(), parent_name="parent"
8079
)
80+
81+
82+
def test_response_from_data_property_of_type_text_yaml(mocker):
83+
from openapi_python_client.parser import responses
84+
85+
prop = StringProperty(name="prop", required=True, nullable=False, default=None, description=None)
86+
property_from_data = mocker.patch.object(responses, "property_from_data", return_value=(prop, Schemas()))
87+
data = oai.Response.construct(
88+
description="", content={"text/yaml": oai.MediaType.construct(media_type_schema="something")}
89+
)
90+
response, schemas = responses.response_from_data(
91+
status_code=400, data=data, schemas=Schemas(), parent_name="parent"
92+
)
93+
94+
assert response == responses.Response(
95+
status_code=400,
96+
prop=prop,
97+
source="response.text",
98+
)
99+
property_from_data.assert_called_once_with(
100+
name="response_400", required=True, data="something", schemas=Schemas(), parent_name="parent"
101+
)

0 commit comments

Comments
 (0)