Skip to content

Commit 4743ae8

Browse files
committed
Refactored response handling to use the same schema generation as input properties.
1 parent c8ae42d commit 4743ae8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+467
-647
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1111

1212
- Any request/response field that is not `required` and wasn't specified is now set to `UNSET` instead of `None`.
1313
- Values that are `UNSET` will not be sent along in API calls
14+
- Schemas defined with `type=object` will now be converted into classes, just like if they were created as ref components.
15+
The previous behavior was a combination of skipping and using generic Dicts for these schemas.
16+
- Response schema handling was unified with input schema handling, meaning that responses will behave differently than before.
17+
Specifically, instead of the content-type deciding what the generated Python type is, the schema itself will.
18+
- Instead of skipping input properties with no type, enum, anyOf, or oneOf declared, the property will be declared as `None`.
1419

1520
### Additions
1621

1722
- Added a `--custom-template-path` option for providing custom jinja2 templates (#231 - Thanks @erichulburd!).
1823
- Better compatibility for "required" (whether or not the field must be included) and "nullable" (whether or not the field can be null) (#205 & #208). Thanks @bowenwr & @emannguitar!
24+
- Support for all the same schemas in responses as are supported in parameters.
1925

2026
## 0.6.2 - 2020-11-03
2127

end_to_end_tests/golden-record-custom/custom_e2e/api/tests/defaults_tests_defaults_post.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
Client = httpx.Client
66

77
import datetime
8-
from typing import List, Union, cast
8+
from typing import Dict, List, Union
99

1010
from dateutil.parser import isoparse
1111

@@ -16,9 +16,13 @@
1616

1717
def _parse_response(*, response: httpx.Response) -> Optional[Union[None, HTTPValidationError]]:
1818
if response.status_code == 200:
19-
return None
19+
response_200 = None
20+
21+
return response_200
2022
if response.status_code == 422:
21-
return HTTPValidationError.from_dict(cast(Dict[str, Any], response.json()))
23+
response_422 = HTTPValidationError.from_dict(response.json())
24+
25+
return response_422
2226
return None
2327

2428

end_to_end_tests/golden-record-custom/custom_e2e/api/tests/get_basic_list_of_booleans.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,14 @@
44

55
Client = httpx.Client
66

7+
from typing import List, cast
8+
79

810
def _parse_response(*, response: httpx.Response) -> Optional[List[bool]]:
911
if response.status_code == 200:
10-
return [bool(item) for item in cast(List[bool], response.json())]
12+
response_200 = cast(List[bool], response.json())
13+
14+
return response_200
1115
return None
1216

1317

end_to_end_tests/golden-record-custom/custom_e2e/api/tests/get_basic_list_of_floats.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,14 @@
44

55
Client = httpx.Client
66

7+
from typing import List, cast
8+
79

810
def _parse_response(*, response: httpx.Response) -> Optional[List[float]]:
911
if response.status_code == 200:
10-
return [float(item) for item in cast(List[float], response.json())]
12+
response_200 = cast(List[float], response.json())
13+
14+
return response_200
1115
return None
1216

1317

end_to_end_tests/golden-record-custom/custom_e2e/api/tests/get_basic_list_of_integers.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,14 @@
44

55
Client = httpx.Client
66

7+
from typing import List, cast
8+
79

810
def _parse_response(*, response: httpx.Response) -> Optional[List[int]]:
911
if response.status_code == 200:
10-
return [int(item) for item in cast(List[int], response.json())]
12+
response_200 = cast(List[int], response.json())
13+
14+
return response_200
1115
return None
1216

1317

end_to_end_tests/golden-record-custom/custom_e2e/api/tests/get_basic_list_of_strings.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,14 @@
44

55
Client = httpx.Client
66

7+
from typing import List, cast
8+
79

810
def _parse_response(*, response: httpx.Response) -> Optional[List[str]]:
911
if response.status_code == 200:
10-
return [str(item) for item in cast(List[str], response.json())]
12+
response_200 = cast(List[str], response.json())
13+
14+
return response_200
1115
return None
1216

1317

end_to_end_tests/golden-record-custom/custom_e2e/api/tests/get_user_list.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
Client = httpx.Client
66

77
import datetime
8-
from typing import List, Union, cast
8+
from typing import Dict, List, Union
99

1010
from ...models.a_model import AModel
1111
from ...models.an_enum import AnEnum
@@ -14,9 +14,17 @@
1414

1515
def _parse_response(*, response: httpx.Response) -> Optional[Union[List[AModel], HTTPValidationError]]:
1616
if response.status_code == 200:
17-
return [AModel.from_dict(item) for item in cast(List[Dict[str, Any]], response.json())]
17+
response_200 = []
18+
for response_200_item_data in response.json():
19+
response_200_item = AModel.from_dict(response_200_item_data)
20+
21+
response_200.append(response_200_item)
22+
23+
return response_200
1824
if response.status_code == 422:
19-
return HTTPValidationError.from_dict(cast(Dict[str, Any], response.json()))
25+
response_422 = HTTPValidationError.from_dict(response.json())
26+
27+
return response_422
2028
return None
2129

2230

end_to_end_tests/golden-record-custom/custom_e2e/api/tests/int_enum_tests_int_enum_post.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,21 @@
44

55
Client = httpx.Client
66

7+
from typing import Dict
8+
79
from ...models.an_int_enum import AnIntEnum
810
from ...models.http_validation_error import HTTPValidationError
911

1012

1113
def _parse_response(*, response: httpx.Response) -> Optional[Union[None, HTTPValidationError]]:
1214
if response.status_code == 200:
13-
return None
15+
response_200 = None
16+
17+
return response_200
1418
if response.status_code == 422:
15-
return HTTPValidationError.from_dict(cast(Dict[str, Any], response.json()))
19+
response_422 = HTTPValidationError.from_dict(response.json())
20+
21+
return response_422
1622
return None
1723

1824

end_to_end_tests/golden-record-custom/custom_e2e/api/tests/json_body_tests_json_body_post.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,19 @@
44

55
Client = httpx.Client
66

7-
from typing import Dict, cast
8-
97
from ...models.a_model import AModel
108
from ...models.http_validation_error import HTTPValidationError
119

1210

1311
def _parse_response(*, response: httpx.Response) -> Optional[Union[None, HTTPValidationError]]:
1412
if response.status_code == 200:
15-
return None
13+
response_200 = None
14+
15+
return response_200
1616
if response.status_code == 422:
17-
return HTTPValidationError.from_dict(cast(Dict[str, Any], response.json()))
17+
response_422 = HTTPValidationError.from_dict(response.json())
18+
19+
return response_422
1820
return None
1921

2022

end_to_end_tests/golden-record-custom/custom_e2e/api/tests/octet_stream_tests_octet_stream_get.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,20 @@
44

55
Client = httpx.Client
66

7+
from io import BytesIO
78

8-
def _parse_response(*, response: httpx.Response) -> Optional[bytes]:
9+
from ...types import File
10+
11+
12+
def _parse_response(*, response: httpx.Response) -> Optional[File]:
913
if response.status_code == 200:
10-
return bytes(response.content)
14+
response_200 = File(payload=BytesIO(response.content))
15+
16+
return response_200
1117
return None
1218

1319

14-
def _build_response(*, response: httpx.Response) -> httpx.Response[bytes]:
20+
def _build_response(*, response: httpx.Response) -> httpx.Response[File]:
1521
return httpx.Response(
1622
status_code=response.status_code,
1723
content=response.content,
@@ -23,7 +29,7 @@ def _build_response(*, response: httpx.Response) -> httpx.Response[bytes]:
2329
def httpx_request(
2430
*,
2531
client: Client,
26-
) -> httpx.Response[bytes]:
32+
) -> httpx.Response[File]:
2733

2834
response = client.request(
2935
"get",

0 commit comments

Comments
 (0)