Skip to content

Commit 08c985f

Browse files
asfaltboydbanty
andauthored
feat!: Change the Response.status_code type to the HTTPStatus enum [openapi-generators#665]
Co-authored-by: Dylan Anthony <dbanty@users.noreply.github.com>
1 parent e2cb382 commit 08c985f

Some content is hidden

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

41 files changed

+124
-76
lines changed

CONTRIBUTING.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
## Setting up a Dev Environment
1010

1111
1. Make sure you have [Poetry](https://python-poetry.org/) installed and up to date.
12-
2. Make sure you have a supported Python version (e.g. 3.8) installed and accessible to Poetry (e.g. with [pyenv](https://github.com/pyenv/pyenv).
12+
2. Make sure you have a supported Python version (e.g. 3.8) installed and accessible to Poetry (e.g. with [pyenv](https://github.com/pyenv/pyenv)).
1313
3. Use `poetry install` in the project directory to create a virtual environment with the relevant dependencies.
1414
4. Enter a `poetry shell` to make running commands easier.
1515

end_to_end_tests/golden-record/my_test_api_client/api/default/get_common_parameters.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from http import HTTPStatus
12
from typing import Any, Dict, Union
23

34
import httpx
@@ -33,7 +34,7 @@ def _get_kwargs(
3334

3435
def _build_response(*, response: httpx.Response) -> Response[Any]:
3536
return Response(
36-
status_code=response.status_code,
37+
status_code=HTTPStatus(response.status_code),
3738
content=response.content,
3839
headers=response.headers,
3940
parsed=None,

end_to_end_tests/golden-record/my_test_api_client/api/default/post_common_parameters.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from http import HTTPStatus
12
from typing import Any, Dict, Union
23

34
import httpx
@@ -33,7 +34,7 @@ def _get_kwargs(
3334

3435
def _build_response(*, response: httpx.Response) -> Response[Any]:
3536
return Response(
36-
status_code=response.status_code,
37+
status_code=HTTPStatus(response.status_code),
3738
content=response.content,
3839
headers=response.headers,
3940
parsed=None,

end_to_end_tests/golden-record/my_test_api_client/api/location/get_location_header_types.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from http import HTTPStatus
12
from typing import Any, Dict, Union
23

34
import httpx
@@ -52,7 +53,7 @@ def _get_kwargs(
5253

5354
def _build_response(*, response: httpx.Response) -> Response[Any]:
5455
return Response(
55-
status_code=response.status_code,
56+
status_code=HTTPStatus(response.status_code),
5657
content=response.content,
5758
headers=response.headers,
5859
parsed=None,

end_to_end_tests/golden-record/my_test_api_client/api/location/get_location_query_optionality.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import datetime
2+
from http import HTTPStatus
23
from typing import Any, Dict, Union
34

45
import httpx
@@ -57,7 +58,7 @@ def _get_kwargs(
5758

5859
def _build_response(*, response: httpx.Response) -> Response[Any]:
5960
return Response(
60-
status_code=response.status_code,
61+
status_code=HTTPStatus(response.status_code),
6162
content=response.content,
6263
headers=response.headers,
6364
parsed=None,

end_to_end_tests/golden-record/my_test_api_client/api/parameter_references/get_parameter_references_path_param.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from http import HTTPStatus
12
from typing import Any, Dict
23

34
import httpx
@@ -43,7 +44,7 @@ def _get_kwargs(
4344

4445
def _build_response(*, response: httpx.Response) -> Response[Any]:
4546
return Response(
46-
status_code=response.status_code,
47+
status_code=HTTPStatus(response.status_code),
4748
content=response.content,
4849
headers=response.headers,
4950
parsed=None,

end_to_end_tests/golden-record/my_test_api_client/api/parameters/delete_common_parameters_overriding_param.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from http import HTTPStatus
12
from typing import Any, Dict, Union
23

34
import httpx
@@ -34,7 +35,7 @@ def _get_kwargs(
3435

3536
def _build_response(*, response: httpx.Response) -> Response[Any]:
3637
return Response(
37-
status_code=response.status_code,
38+
status_code=HTTPStatus(response.status_code),
3839
content=response.content,
3940
headers=response.headers,
4041
parsed=None,

end_to_end_tests/golden-record/my_test_api_client/api/parameters/get_common_parameters_overriding_param.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from http import HTTPStatus
12
from typing import Any, Dict
23

34
import httpx
@@ -34,7 +35,7 @@ def _get_kwargs(
3435

3536
def _build_response(*, response: httpx.Response) -> Response[Any]:
3637
return Response(
37-
status_code=response.status_code,
38+
status_code=HTTPStatus(response.status_code),
3839
content=response.content,
3940
headers=response.headers,
4041
parsed=None,

end_to_end_tests/golden-record/my_test_api_client/api/parameters/get_same_name_multiple_locations_param.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from http import HTTPStatus
12
from typing import Any, Dict, Union
23

34
import httpx
@@ -42,7 +43,7 @@ def _get_kwargs(
4243

4344
def _build_response(*, response: httpx.Response) -> Response[Any]:
4445
return Response(
45-
status_code=response.status_code,
46+
status_code=HTTPStatus(response.status_code),
4647
content=response.content,
4748
headers=response.headers,
4849
parsed=None,

end_to_end_tests/golden-record/my_test_api_client/api/parameters/multiple_path_parameters.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from http import HTTPStatus
12
from typing import Any, Dict
23

34
import httpx
@@ -32,7 +33,7 @@ def _get_kwargs(
3233

3334
def _build_response(*, response: httpx.Response) -> Response[Any]:
3435
return Response(
35-
status_code=response.status_code,
36+
status_code=HTTPStatus(response.status_code),
3637
content=response.content,
3738
headers=response.headers,
3839
parsed=None,

end_to_end_tests/golden-record/my_test_api_client/api/responses/post_responses_unions_simple_before_complex.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from http import HTTPStatus
12
from typing import Any, Dict, Optional
23

34
import httpx
@@ -28,7 +29,7 @@ def _get_kwargs(
2829

2930

3031
def _parse_response(*, response: httpx.Response) -> Optional[PostResponsesUnionsSimpleBeforeComplexResponse200]:
31-
if response.status_code == 200:
32+
if response.status_code == HTTPStatus.OK:
3233
response_200 = PostResponsesUnionsSimpleBeforeComplexResponse200.from_dict(response.json())
3334

3435
return response_200
@@ -37,7 +38,7 @@ def _parse_response(*, response: httpx.Response) -> Optional[PostResponsesUnions
3738

3839
def _build_response(*, response: httpx.Response) -> Response[PostResponsesUnionsSimpleBeforeComplexResponse200]:
3940
return Response(
40-
status_code=response.status_code,
41+
status_code=HTTPStatus(response.status_code),
4142
content=response.content,
4243
headers=response.headers,
4344
parsed=_parse_response(response=response),

end_to_end_tests/golden-record/my_test_api_client/api/tag1/get_tag_with_number.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from http import HTTPStatus
12
from typing import Any, Dict
23

34
import httpx
@@ -26,7 +27,7 @@ def _get_kwargs(
2627

2728
def _build_response(*, response: httpx.Response) -> Response[Any]:
2829
return Response(
29-
status_code=response.status_code,
30+
status_code=HTTPStatus(response.status_code),
3031
content=response.content,
3132
headers=response.headers,
3233
parsed=None,

end_to_end_tests/golden-record/my_test_api_client/api/tests/callback_test.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from http import HTTPStatus
12
from typing import Any, Dict, Optional, Union, cast
23

34
import httpx
@@ -31,10 +32,10 @@ def _get_kwargs(
3132

3233

3334
def _parse_response(*, response: httpx.Response) -> Optional[Union[Any, HTTPValidationError]]:
34-
if response.status_code == 200:
35+
if response.status_code == HTTPStatus.OK:
3536
response_200 = cast(Any, response.json())
3637
return response_200
37-
if response.status_code == 422:
38+
if response.status_code == HTTPStatus.UNPROCESSABLE_ENTITY:
3839
response_422 = HTTPValidationError.from_dict(response.json())
3940

4041
return response_422
@@ -43,7 +44,7 @@ def _parse_response(*, response: httpx.Response) -> Optional[Union[Any, HTTPVali
4344

4445
def _build_response(*, response: httpx.Response) -> Response[Union[Any, HTTPValidationError]]:
4546
return Response(
46-
status_code=response.status_code,
47+
status_code=HTTPStatus(response.status_code),
4748
content=response.content,
4849
headers=response.headers,
4950
parsed=_parse_response(response=response),

end_to_end_tests/golden-record/my_test_api_client/api/tests/defaults_tests_defaults_post.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import datetime
2+
from http import HTTPStatus
23
from typing import Any, Dict, List, Optional, Union, cast
34

45
import httpx
@@ -98,10 +99,10 @@ def _get_kwargs(
9899

99100

100101
def _parse_response(*, response: httpx.Response) -> Optional[Union[Any, HTTPValidationError]]:
101-
if response.status_code == 200:
102+
if response.status_code == HTTPStatus.OK:
102103
response_200 = cast(Any, response.json())
103104
return response_200
104-
if response.status_code == 422:
105+
if response.status_code == HTTPStatus.UNPROCESSABLE_ENTITY:
105106
response_422 = HTTPValidationError.from_dict(response.json())
106107

107108
return response_422
@@ -110,7 +111,7 @@ def _parse_response(*, response: httpx.Response) -> Optional[Union[Any, HTTPVali
110111

111112
def _build_response(*, response: httpx.Response) -> Response[Union[Any, HTTPValidationError]]:
112113
return Response(
113-
status_code=response.status_code,
114+
status_code=HTTPStatus(response.status_code),
114115
content=response.content,
115116
headers=response.headers,
116117
parsed=_parse_response(response=response),

end_to_end_tests/golden-record/my_test_api_client/api/tests/get_basic_list_of_booleans.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from http import HTTPStatus
12
from typing import Any, Dict, List, Optional, cast
23

34
import httpx
@@ -25,7 +26,7 @@ def _get_kwargs(
2526

2627

2728
def _parse_response(*, response: httpx.Response) -> Optional[List[bool]]:
28-
if response.status_code == 200:
29+
if response.status_code == HTTPStatus.OK:
2930
response_200 = cast(List[bool], response.json())
3031

3132
return response_200
@@ -34,7 +35,7 @@ def _parse_response(*, response: httpx.Response) -> Optional[List[bool]]:
3435

3536
def _build_response(*, response: httpx.Response) -> Response[List[bool]]:
3637
return Response(
37-
status_code=response.status_code,
38+
status_code=HTTPStatus(response.status_code),
3839
content=response.content,
3940
headers=response.headers,
4041
parsed=_parse_response(response=response),

end_to_end_tests/golden-record/my_test_api_client/api/tests/get_basic_list_of_floats.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from http import HTTPStatus
12
from typing import Any, Dict, List, Optional, cast
23

34
import httpx
@@ -25,7 +26,7 @@ def _get_kwargs(
2526

2627

2728
def _parse_response(*, response: httpx.Response) -> Optional[List[float]]:
28-
if response.status_code == 200:
29+
if response.status_code == HTTPStatus.OK:
2930
response_200 = cast(List[float], response.json())
3031

3132
return response_200
@@ -34,7 +35,7 @@ def _parse_response(*, response: httpx.Response) -> Optional[List[float]]:
3435

3536
def _build_response(*, response: httpx.Response) -> Response[List[float]]:
3637
return Response(
37-
status_code=response.status_code,
38+
status_code=HTTPStatus(response.status_code),
3839
content=response.content,
3940
headers=response.headers,
4041
parsed=_parse_response(response=response),

end_to_end_tests/golden-record/my_test_api_client/api/tests/get_basic_list_of_integers.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from http import HTTPStatus
12
from typing import Any, Dict, List, Optional, cast
23

34
import httpx
@@ -25,7 +26,7 @@ def _get_kwargs(
2526

2627

2728
def _parse_response(*, response: httpx.Response) -> Optional[List[int]]:
28-
if response.status_code == 200:
29+
if response.status_code == HTTPStatus.OK:
2930
response_200 = cast(List[int], response.json())
3031

3132
return response_200
@@ -34,7 +35,7 @@ def _parse_response(*, response: httpx.Response) -> Optional[List[int]]:
3435

3536
def _build_response(*, response: httpx.Response) -> Response[List[int]]:
3637
return Response(
37-
status_code=response.status_code,
38+
status_code=HTTPStatus(response.status_code),
3839
content=response.content,
3940
headers=response.headers,
4041
parsed=_parse_response(response=response),

end_to_end_tests/golden-record/my_test_api_client/api/tests/get_basic_list_of_strings.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from http import HTTPStatus
12
from typing import Any, Dict, List, Optional, cast
23

34
import httpx
@@ -25,7 +26,7 @@ def _get_kwargs(
2526

2627

2728
def _parse_response(*, response: httpx.Response) -> Optional[List[str]]:
28-
if response.status_code == 200:
29+
if response.status_code == HTTPStatus.OK:
2930
response_200 = cast(List[str], response.json())
3031

3132
return response_200
@@ -34,7 +35,7 @@ def _parse_response(*, response: httpx.Response) -> Optional[List[str]]:
3435

3536
def _build_response(*, response: httpx.Response) -> Response[List[str]]:
3637
return Response(
37-
status_code=response.status_code,
38+
status_code=HTTPStatus(response.status_code),
3839
content=response.content,
3940
headers=response.headers,
4041
parsed=_parse_response(response=response),

end_to_end_tests/golden-record/my_test_api_client/api/tests/get_user_list.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import datetime
2+
from http import HTTPStatus
23
from typing import Any, Dict, List, Optional, Union
34

45
import httpx
@@ -69,7 +70,7 @@ def _get_kwargs(
6970

7071

7172
def _parse_response(*, response: httpx.Response) -> Optional[Union[HTTPValidationError, List[AModel]]]:
72-
if response.status_code == 200:
73+
if response.status_code == HTTPStatus.OK:
7374
response_200 = []
7475
_response_200 = response.json()
7576
for response_200_item_data in _response_200:
@@ -78,11 +79,11 @@ def _parse_response(*, response: httpx.Response) -> Optional[Union[HTTPValidatio
7879
response_200.append(response_200_item)
7980

8081
return response_200
81-
if response.status_code == 422:
82+
if response.status_code == HTTPStatus.UNPROCESSABLE_ENTITY:
8283
response_422 = HTTPValidationError.from_dict(response.json())
8384

8485
return response_422
85-
if response.status_code == 423:
86+
if response.status_code == HTTPStatus.LOCKED:
8687
response_423 = HTTPValidationError.from_dict(response.json())
8788

8889
return response_423
@@ -91,7 +92,7 @@ def _parse_response(*, response: httpx.Response) -> Optional[Union[HTTPValidatio
9192

9293
def _build_response(*, response: httpx.Response) -> Response[Union[HTTPValidationError, List[AModel]]]:
9394
return Response(
94-
status_code=response.status_code,
95+
status_code=HTTPStatus(response.status_code),
9596
content=response.content,
9697
headers=response.headers,
9798
parsed=_parse_response(response=response),

end_to_end_tests/golden-record/my_test_api_client/api/tests/int_enum_tests_int_enum_post.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from http import HTTPStatus
12
from typing import Any, Dict, Optional, Union, cast
23

34
import httpx
@@ -36,10 +37,10 @@ def _get_kwargs(
3637

3738

3839
def _parse_response(*, response: httpx.Response) -> Optional[Union[Any, HTTPValidationError]]:
39-
if response.status_code == 200:
40+
if response.status_code == HTTPStatus.OK:
4041
response_200 = cast(Any, response.json())
4142
return response_200
42-
if response.status_code == 422:
43+
if response.status_code == HTTPStatus.UNPROCESSABLE_ENTITY:
4344
response_422 = HTTPValidationError.from_dict(response.json())
4445

4546
return response_422
@@ -48,7 +49,7 @@ def _parse_response(*, response: httpx.Response) -> Optional[Union[Any, HTTPVali
4849

4950
def _build_response(*, response: httpx.Response) -> Response[Union[Any, HTTPValidationError]]:
5051
return Response(
51-
status_code=response.status_code,
52+
status_code=HTTPStatus(response.status_code),
5253
content=response.content,
5354
headers=response.headers,
5455
parsed=_parse_response(response=response),

0 commit comments

Comments
 (0)