diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 52c9ab6b2..66ec1cf3b 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -9,7 +9,7 @@ ## Setting up a Dev Environment 1. Make sure you have [Poetry](https://python-poetry.org/) installed and up to date. -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). +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)). 3. Use `poetry install` in the project directory to create a virtual environment with the relevant dependencies. 4. Enter a `poetry shell` to make running commands easier. diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/default/get_common_parameters.py b/end_to_end_tests/golden-record/my_test_api_client/api/default/get_common_parameters.py index 68c3bdf76..73b39c755 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/default/get_common_parameters.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/default/get_common_parameters.py @@ -1,3 +1,4 @@ +from http import HTTPStatus from typing import Any, Dict, Union import httpx @@ -33,7 +34,7 @@ def _get_kwargs( def _build_response(*, response: httpx.Response) -> Response[Any]: return Response( - status_code=response.status_code, + status_code=HTTPStatus(response.status_code), content=response.content, headers=response.headers, parsed=None, diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/default/post_common_parameters.py b/end_to_end_tests/golden-record/my_test_api_client/api/default/post_common_parameters.py index 4041c7079..512f5acec 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/default/post_common_parameters.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/default/post_common_parameters.py @@ -1,3 +1,4 @@ +from http import HTTPStatus from typing import Any, Dict, Union import httpx @@ -33,7 +34,7 @@ def _get_kwargs( def _build_response(*, response: httpx.Response) -> Response[Any]: return Response( - status_code=response.status_code, + status_code=HTTPStatus(response.status_code), content=response.content, headers=response.headers, parsed=None, diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/location/get_location_header_types.py b/end_to_end_tests/golden-record/my_test_api_client/api/location/get_location_header_types.py index 5495d78dd..9232ff57b 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/location/get_location_header_types.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/location/get_location_header_types.py @@ -1,3 +1,4 @@ +from http import HTTPStatus from typing import Any, Dict, Union import httpx @@ -52,7 +53,7 @@ def _get_kwargs( def _build_response(*, response: httpx.Response) -> Response[Any]: return Response( - status_code=response.status_code, + status_code=HTTPStatus(response.status_code), content=response.content, headers=response.headers, parsed=None, diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/location/get_location_query_optionality.py b/end_to_end_tests/golden-record/my_test_api_client/api/location/get_location_query_optionality.py index 9838c2881..b30237822 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/location/get_location_query_optionality.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/location/get_location_query_optionality.py @@ -1,4 +1,5 @@ import datetime +from http import HTTPStatus from typing import Any, Dict, Union import httpx @@ -57,7 +58,7 @@ def _get_kwargs( def _build_response(*, response: httpx.Response) -> Response[Any]: return Response( - status_code=response.status_code, + status_code=HTTPStatus(response.status_code), content=response.content, headers=response.headers, parsed=None, diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/parameter_references/get_parameter_references_path_param.py b/end_to_end_tests/golden-record/my_test_api_client/api/parameter_references/get_parameter_references_path_param.py index 33028801f..5966089d0 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/parameter_references/get_parameter_references_path_param.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/parameter_references/get_parameter_references_path_param.py @@ -1,3 +1,4 @@ +from http import HTTPStatus from typing import Any, Dict import httpx @@ -43,7 +44,7 @@ def _get_kwargs( def _build_response(*, response: httpx.Response) -> Response[Any]: return Response( - status_code=response.status_code, + status_code=HTTPStatus(response.status_code), content=response.content, headers=response.headers, parsed=None, diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/parameters/delete_common_parameters_overriding_param.py b/end_to_end_tests/golden-record/my_test_api_client/api/parameters/delete_common_parameters_overriding_param.py index a9fdf4d89..ff0026f6f 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/parameters/delete_common_parameters_overriding_param.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/parameters/delete_common_parameters_overriding_param.py @@ -1,3 +1,4 @@ +from http import HTTPStatus from typing import Any, Dict, Union import httpx @@ -34,7 +35,7 @@ def _get_kwargs( def _build_response(*, response: httpx.Response) -> Response[Any]: return Response( - status_code=response.status_code, + status_code=HTTPStatus(response.status_code), content=response.content, headers=response.headers, parsed=None, diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/parameters/get_common_parameters_overriding_param.py b/end_to_end_tests/golden-record/my_test_api_client/api/parameters/get_common_parameters_overriding_param.py index 9965f6926..9742bbaf3 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/parameters/get_common_parameters_overriding_param.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/parameters/get_common_parameters_overriding_param.py @@ -1,3 +1,4 @@ +from http import HTTPStatus from typing import Any, Dict import httpx @@ -34,7 +35,7 @@ def _get_kwargs( def _build_response(*, response: httpx.Response) -> Response[Any]: return Response( - status_code=response.status_code, + status_code=HTTPStatus(response.status_code), content=response.content, headers=response.headers, parsed=None, diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/parameters/get_same_name_multiple_locations_param.py b/end_to_end_tests/golden-record/my_test_api_client/api/parameters/get_same_name_multiple_locations_param.py index ea985c15d..122081859 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/parameters/get_same_name_multiple_locations_param.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/parameters/get_same_name_multiple_locations_param.py @@ -1,3 +1,4 @@ +from http import HTTPStatus from typing import Any, Dict, Union import httpx @@ -42,7 +43,7 @@ def _get_kwargs( def _build_response(*, response: httpx.Response) -> Response[Any]: return Response( - status_code=response.status_code, + status_code=HTTPStatus(response.status_code), content=response.content, headers=response.headers, parsed=None, diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/parameters/multiple_path_parameters.py b/end_to_end_tests/golden-record/my_test_api_client/api/parameters/multiple_path_parameters.py index ea47dfaa8..772f405c7 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/parameters/multiple_path_parameters.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/parameters/multiple_path_parameters.py @@ -1,3 +1,4 @@ +from http import HTTPStatus from typing import Any, Dict import httpx @@ -32,7 +33,7 @@ def _get_kwargs( def _build_response(*, response: httpx.Response) -> Response[Any]: return Response( - status_code=response.status_code, + status_code=HTTPStatus(response.status_code), content=response.content, headers=response.headers, parsed=None, diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/responses/post_responses_unions_simple_before_complex.py b/end_to_end_tests/golden-record/my_test_api_client/api/responses/post_responses_unions_simple_before_complex.py index 9dd058470..115936303 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/responses/post_responses_unions_simple_before_complex.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/responses/post_responses_unions_simple_before_complex.py @@ -1,3 +1,4 @@ +from http import HTTPStatus from typing import Any, Dict, Optional import httpx @@ -28,7 +29,7 @@ def _get_kwargs( def _parse_response(*, response: httpx.Response) -> Optional[PostResponsesUnionsSimpleBeforeComplexResponse200]: - if response.status_code == 200: + if response.status_code == HTTPStatus.OK: response_200 = PostResponsesUnionsSimpleBeforeComplexResponse200.from_dict(response.json()) return response_200 @@ -37,7 +38,7 @@ def _parse_response(*, response: httpx.Response) -> Optional[PostResponsesUnions def _build_response(*, response: httpx.Response) -> Response[PostResponsesUnionsSimpleBeforeComplexResponse200]: return Response( - status_code=response.status_code, + status_code=HTTPStatus(response.status_code), content=response.content, headers=response.headers, parsed=_parse_response(response=response), diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/tag1/get_tag_with_number.py b/end_to_end_tests/golden-record/my_test_api_client/api/tag1/get_tag_with_number.py index d50631c94..35999bf9f 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/tag1/get_tag_with_number.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/tag1/get_tag_with_number.py @@ -1,3 +1,4 @@ +from http import HTTPStatus from typing import Any, Dict import httpx @@ -26,7 +27,7 @@ def _get_kwargs( def _build_response(*, response: httpx.Response) -> Response[Any]: return Response( - status_code=response.status_code, + status_code=HTTPStatus(response.status_code), content=response.content, headers=response.headers, parsed=None, diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/tests/callback_test.py b/end_to_end_tests/golden-record/my_test_api_client/api/tests/callback_test.py index e76778af3..4b2655c7c 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/tests/callback_test.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/tests/callback_test.py @@ -1,3 +1,4 @@ +from http import HTTPStatus from typing import Any, Dict, Optional, Union, cast import httpx @@ -31,10 +32,10 @@ def _get_kwargs( def _parse_response(*, response: httpx.Response) -> Optional[Union[Any, HTTPValidationError]]: - if response.status_code == 200: + if response.status_code == HTTPStatus.OK: response_200 = cast(Any, response.json()) return response_200 - if response.status_code == 422: + if response.status_code == HTTPStatus.UNPROCESSABLE_ENTITY: response_422 = HTTPValidationError.from_dict(response.json()) return response_422 @@ -43,7 +44,7 @@ def _parse_response(*, response: httpx.Response) -> Optional[Union[Any, HTTPVali def _build_response(*, response: httpx.Response) -> Response[Union[Any, HTTPValidationError]]: return Response( - status_code=response.status_code, + status_code=HTTPStatus(response.status_code), content=response.content, headers=response.headers, parsed=_parse_response(response=response), diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/tests/defaults_tests_defaults_post.py b/end_to_end_tests/golden-record/my_test_api_client/api/tests/defaults_tests_defaults_post.py index 6c30b939d..5eb7ec0f0 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/tests/defaults_tests_defaults_post.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/tests/defaults_tests_defaults_post.py @@ -1,4 +1,5 @@ import datetime +from http import HTTPStatus from typing import Any, Dict, List, Optional, Union, cast import httpx @@ -98,10 +99,10 @@ def _get_kwargs( def _parse_response(*, response: httpx.Response) -> Optional[Union[Any, HTTPValidationError]]: - if response.status_code == 200: + if response.status_code == HTTPStatus.OK: response_200 = cast(Any, response.json()) return response_200 - if response.status_code == 422: + if response.status_code == HTTPStatus.UNPROCESSABLE_ENTITY: response_422 = HTTPValidationError.from_dict(response.json()) return response_422 @@ -110,7 +111,7 @@ def _parse_response(*, response: httpx.Response) -> Optional[Union[Any, HTTPVali def _build_response(*, response: httpx.Response) -> Response[Union[Any, HTTPValidationError]]: return Response( - status_code=response.status_code, + status_code=HTTPStatus(response.status_code), content=response.content, headers=response.headers, parsed=_parse_response(response=response), diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/tests/get_basic_list_of_booleans.py b/end_to_end_tests/golden-record/my_test_api_client/api/tests/get_basic_list_of_booleans.py index bddce1d9a..abe983938 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/tests/get_basic_list_of_booleans.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/tests/get_basic_list_of_booleans.py @@ -1,3 +1,4 @@ +from http import HTTPStatus from typing import Any, Dict, List, Optional, cast import httpx @@ -25,7 +26,7 @@ def _get_kwargs( def _parse_response(*, response: httpx.Response) -> Optional[List[bool]]: - if response.status_code == 200: + if response.status_code == HTTPStatus.OK: response_200 = cast(List[bool], response.json()) return response_200 @@ -34,7 +35,7 @@ def _parse_response(*, response: httpx.Response) -> Optional[List[bool]]: def _build_response(*, response: httpx.Response) -> Response[List[bool]]: return Response( - status_code=response.status_code, + status_code=HTTPStatus(response.status_code), content=response.content, headers=response.headers, parsed=_parse_response(response=response), diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/tests/get_basic_list_of_floats.py b/end_to_end_tests/golden-record/my_test_api_client/api/tests/get_basic_list_of_floats.py index 083fc498e..54f5228c9 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/tests/get_basic_list_of_floats.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/tests/get_basic_list_of_floats.py @@ -1,3 +1,4 @@ +from http import HTTPStatus from typing import Any, Dict, List, Optional, cast import httpx @@ -25,7 +26,7 @@ def _get_kwargs( def _parse_response(*, response: httpx.Response) -> Optional[List[float]]: - if response.status_code == 200: + if response.status_code == HTTPStatus.OK: response_200 = cast(List[float], response.json()) return response_200 @@ -34,7 +35,7 @@ def _parse_response(*, response: httpx.Response) -> Optional[List[float]]: def _build_response(*, response: httpx.Response) -> Response[List[float]]: return Response( - status_code=response.status_code, + status_code=HTTPStatus(response.status_code), content=response.content, headers=response.headers, parsed=_parse_response(response=response), diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/tests/get_basic_list_of_integers.py b/end_to_end_tests/golden-record/my_test_api_client/api/tests/get_basic_list_of_integers.py index 21b9f4c4f..860c52dec 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/tests/get_basic_list_of_integers.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/tests/get_basic_list_of_integers.py @@ -1,3 +1,4 @@ +from http import HTTPStatus from typing import Any, Dict, List, Optional, cast import httpx @@ -25,7 +26,7 @@ def _get_kwargs( def _parse_response(*, response: httpx.Response) -> Optional[List[int]]: - if response.status_code == 200: + if response.status_code == HTTPStatus.OK: response_200 = cast(List[int], response.json()) return response_200 @@ -34,7 +35,7 @@ def _parse_response(*, response: httpx.Response) -> Optional[List[int]]: def _build_response(*, response: httpx.Response) -> Response[List[int]]: return Response( - status_code=response.status_code, + status_code=HTTPStatus(response.status_code), content=response.content, headers=response.headers, parsed=_parse_response(response=response), diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/tests/get_basic_list_of_strings.py b/end_to_end_tests/golden-record/my_test_api_client/api/tests/get_basic_list_of_strings.py index 7fb6a52d6..96ceb3b9b 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/tests/get_basic_list_of_strings.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/tests/get_basic_list_of_strings.py @@ -1,3 +1,4 @@ +from http import HTTPStatus from typing import Any, Dict, List, Optional, cast import httpx @@ -25,7 +26,7 @@ def _get_kwargs( def _parse_response(*, response: httpx.Response) -> Optional[List[str]]: - if response.status_code == 200: + if response.status_code == HTTPStatus.OK: response_200 = cast(List[str], response.json()) return response_200 @@ -34,7 +35,7 @@ def _parse_response(*, response: httpx.Response) -> Optional[List[str]]: def _build_response(*, response: httpx.Response) -> Response[List[str]]: return Response( - status_code=response.status_code, + status_code=HTTPStatus(response.status_code), content=response.content, headers=response.headers, parsed=_parse_response(response=response), diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/tests/get_user_list.py b/end_to_end_tests/golden-record/my_test_api_client/api/tests/get_user_list.py index e4ed22231..ba0a3351e 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/tests/get_user_list.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/tests/get_user_list.py @@ -1,4 +1,5 @@ import datetime +from http import HTTPStatus from typing import Any, Dict, List, Optional, Union import httpx @@ -69,7 +70,7 @@ def _get_kwargs( def _parse_response(*, response: httpx.Response) -> Optional[Union[HTTPValidationError, List[AModel]]]: - if response.status_code == 200: + if response.status_code == HTTPStatus.OK: response_200 = [] _response_200 = response.json() for response_200_item_data in _response_200: @@ -78,11 +79,11 @@ def _parse_response(*, response: httpx.Response) -> Optional[Union[HTTPValidatio response_200.append(response_200_item) return response_200 - if response.status_code == 422: + if response.status_code == HTTPStatus.UNPROCESSABLE_ENTITY: response_422 = HTTPValidationError.from_dict(response.json()) return response_422 - if response.status_code == 423: + if response.status_code == HTTPStatus.LOCKED: response_423 = HTTPValidationError.from_dict(response.json()) return response_423 @@ -91,7 +92,7 @@ def _parse_response(*, response: httpx.Response) -> Optional[Union[HTTPValidatio def _build_response(*, response: httpx.Response) -> Response[Union[HTTPValidationError, List[AModel]]]: return Response( - status_code=response.status_code, + status_code=HTTPStatus(response.status_code), content=response.content, headers=response.headers, parsed=_parse_response(response=response), diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/tests/int_enum_tests_int_enum_post.py b/end_to_end_tests/golden-record/my_test_api_client/api/tests/int_enum_tests_int_enum_post.py index a18f9cfef..6fe848bf8 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/tests/int_enum_tests_int_enum_post.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/tests/int_enum_tests_int_enum_post.py @@ -1,3 +1,4 @@ +from http import HTTPStatus from typing import Any, Dict, Optional, Union, cast import httpx @@ -36,10 +37,10 @@ def _get_kwargs( def _parse_response(*, response: httpx.Response) -> Optional[Union[Any, HTTPValidationError]]: - if response.status_code == 200: + if response.status_code == HTTPStatus.OK: response_200 = cast(Any, response.json()) return response_200 - if response.status_code == 422: + if response.status_code == HTTPStatus.UNPROCESSABLE_ENTITY: response_422 = HTTPValidationError.from_dict(response.json()) return response_422 @@ -48,7 +49,7 @@ def _parse_response(*, response: httpx.Response) -> Optional[Union[Any, HTTPVali def _build_response(*, response: httpx.Response) -> Response[Union[Any, HTTPValidationError]]: return Response( - status_code=response.status_code, + status_code=HTTPStatus(response.status_code), content=response.content, headers=response.headers, parsed=_parse_response(response=response), diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/tests/json_body_tests_json_body_post.py b/end_to_end_tests/golden-record/my_test_api_client/api/tests/json_body_tests_json_body_post.py index 5dfe0a79c..9d4f1d32a 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/tests/json_body_tests_json_body_post.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/tests/json_body_tests_json_body_post.py @@ -1,3 +1,4 @@ +from http import HTTPStatus from typing import Any, Dict, Optional, Union, cast import httpx @@ -31,10 +32,10 @@ def _get_kwargs( def _parse_response(*, response: httpx.Response) -> Optional[Union[Any, HTTPValidationError]]: - if response.status_code == 200: + if response.status_code == HTTPStatus.OK: response_200 = cast(Any, response.json()) return response_200 - if response.status_code == 422: + if response.status_code == HTTPStatus.UNPROCESSABLE_ENTITY: response_422 = HTTPValidationError.from_dict(response.json()) return response_422 @@ -43,7 +44,7 @@ def _parse_response(*, response: httpx.Response) -> Optional[Union[Any, HTTPVali def _build_response(*, response: httpx.Response) -> Response[Union[Any, HTTPValidationError]]: return Response( - status_code=response.status_code, + status_code=HTTPStatus(response.status_code), content=response.content, headers=response.headers, parsed=_parse_response(response=response), diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/tests/no_response_tests_no_response_get.py b/end_to_end_tests/golden-record/my_test_api_client/api/tests/no_response_tests_no_response_get.py index d30f9e651..1804a98dd 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/tests/no_response_tests_no_response_get.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/tests/no_response_tests_no_response_get.py @@ -1,3 +1,4 @@ +from http import HTTPStatus from typing import Any, Dict import httpx @@ -26,7 +27,7 @@ def _get_kwargs( def _build_response(*, response: httpx.Response) -> Response[Any]: return Response( - status_code=response.status_code, + status_code=HTTPStatus(response.status_code), content=response.content, headers=response.headers, parsed=None, diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/tests/octet_stream_tests_octet_stream_get.py b/end_to_end_tests/golden-record/my_test_api_client/api/tests/octet_stream_tests_octet_stream_get.py index cefaeabbb..abc7c6d40 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/tests/octet_stream_tests_octet_stream_get.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/tests/octet_stream_tests_octet_stream_get.py @@ -1,3 +1,4 @@ +from http import HTTPStatus from io import BytesIO from typing import Any, Dict, Optional @@ -26,7 +27,7 @@ def _get_kwargs( def _parse_response(*, response: httpx.Response) -> Optional[File]: - if response.status_code == 200: + if response.status_code == HTTPStatus.OK: response_200 = File(payload=BytesIO(response.content)) return response_200 @@ -35,7 +36,7 @@ def _parse_response(*, response: httpx.Response) -> Optional[File]: def _build_response(*, response: httpx.Response) -> Response[File]: return Response( - status_code=response.status_code, + status_code=HTTPStatus(response.status_code), content=response.content, headers=response.headers, parsed=_parse_response(response=response), diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/tests/post_form_data.py b/end_to_end_tests/golden-record/my_test_api_client/api/tests/post_form_data.py index c1e0021e8..78cc1c157 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/tests/post_form_data.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/tests/post_form_data.py @@ -1,3 +1,4 @@ +from http import HTTPStatus from typing import Any, Dict import httpx @@ -29,7 +30,7 @@ def _get_kwargs( def _build_response(*, response: httpx.Response) -> Response[Any]: return Response( - status_code=response.status_code, + status_code=HTTPStatus(response.status_code), content=response.content, headers=response.headers, parsed=None, diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/tests/post_form_data_inline.py b/end_to_end_tests/golden-record/my_test_api_client/api/tests/post_form_data_inline.py index f2412ee27..46352cb64 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/tests/post_form_data_inline.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/tests/post_form_data_inline.py @@ -1,3 +1,4 @@ +from http import HTTPStatus from typing import Any, Dict import httpx @@ -29,7 +30,7 @@ def _get_kwargs( def _build_response(*, response: httpx.Response) -> Response[Any]: return Response( - status_code=response.status_code, + status_code=HTTPStatus(response.status_code), content=response.content, headers=response.headers, parsed=None, diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/tests/post_tests_json_body_string.py b/end_to_end_tests/golden-record/my_test_api_client/api/tests/post_tests_json_body_string.py index 290cba783..cf8734816 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/tests/post_tests_json_body_string.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/tests/post_tests_json_body_string.py @@ -1,3 +1,4 @@ +from http import HTTPStatus from typing import Any, Dict, Optional, Union, cast import httpx @@ -30,10 +31,10 @@ def _get_kwargs( def _parse_response(*, response: httpx.Response) -> Optional[Union[HTTPValidationError, str]]: - if response.status_code == 200: + if response.status_code == HTTPStatus.OK: response_200 = cast(str, response.json()) return response_200 - if response.status_code == 422: + if response.status_code == HTTPStatus.UNPROCESSABLE_ENTITY: response_422 = HTTPValidationError.from_dict(response.json()) return response_422 @@ -42,7 +43,7 @@ def _parse_response(*, response: httpx.Response) -> Optional[Union[HTTPValidatio def _build_response(*, response: httpx.Response) -> Response[Union[HTTPValidationError, str]]: return Response( - status_code=response.status_code, + status_code=HTTPStatus(response.status_code), content=response.content, headers=response.headers, parsed=_parse_response(response=response), diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/tests/test_inline_objects.py b/end_to_end_tests/golden-record/my_test_api_client/api/tests/test_inline_objects.py index 64ae9b210..7ff96d63d 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/tests/test_inline_objects.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/tests/test_inline_objects.py @@ -1,3 +1,4 @@ +from http import HTTPStatus from typing import Any, Dict, Optional import httpx @@ -31,7 +32,7 @@ def _get_kwargs( def _parse_response(*, response: httpx.Response) -> Optional[TestInlineObjectsResponse200]: - if response.status_code == 200: + if response.status_code == HTTPStatus.OK: response_200 = TestInlineObjectsResponse200.from_dict(response.json()) return response_200 @@ -40,7 +41,7 @@ def _parse_response(*, response: httpx.Response) -> Optional[TestInlineObjectsRe def _build_response(*, response: httpx.Response) -> Response[TestInlineObjectsResponse200]: return Response( - status_code=response.status_code, + status_code=HTTPStatus(response.status_code), content=response.content, headers=response.headers, parsed=_parse_response(response=response), diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/tests/token_with_cookie_auth_token_with_cookie_get.py b/end_to_end_tests/golden-record/my_test_api_client/api/tests/token_with_cookie_auth_token_with_cookie_get.py index 337ad0603..38ac8c9b4 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/tests/token_with_cookie_auth_token_with_cookie_get.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/tests/token_with_cookie_auth_token_with_cookie_get.py @@ -1,3 +1,4 @@ +from http import HTTPStatus from typing import Any, Dict import httpx @@ -29,7 +30,7 @@ def _get_kwargs( def _build_response(*, response: httpx.Response) -> Response[Any]: return Response( - status_code=response.status_code, + status_code=HTTPStatus(response.status_code), content=response.content, headers=response.headers, parsed=None, diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/tests/unsupported_content_tests_unsupported_content_get.py b/end_to_end_tests/golden-record/my_test_api_client/api/tests/unsupported_content_tests_unsupported_content_get.py index e2dc56a7b..60a26957e 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/tests/unsupported_content_tests_unsupported_content_get.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/tests/unsupported_content_tests_unsupported_content_get.py @@ -1,3 +1,4 @@ +from http import HTTPStatus from typing import Any, Dict import httpx @@ -26,7 +27,7 @@ def _get_kwargs( def _build_response(*, response: httpx.Response) -> Response[Any]: return Response( - status_code=response.status_code, + status_code=HTTPStatus(response.status_code), content=response.content, headers=response.headers, parsed=None, diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/tests/upload_file_tests_upload_post.py b/end_to_end_tests/golden-record/my_test_api_client/api/tests/upload_file_tests_upload_post.py index d939f04fe..4a967179b 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/tests/upload_file_tests_upload_post.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/tests/upload_file_tests_upload_post.py @@ -1,3 +1,4 @@ +from http import HTTPStatus from typing import Any, Dict, Optional, Union, cast import httpx @@ -31,10 +32,10 @@ def _get_kwargs( def _parse_response(*, response: httpx.Response) -> Optional[Union[Any, HTTPValidationError]]: - if response.status_code == 200: + if response.status_code == HTTPStatus.OK: response_200 = cast(Any, response.json()) return response_200 - if response.status_code == 422: + if response.status_code == HTTPStatus.UNPROCESSABLE_ENTITY: response_422 = HTTPValidationError.from_dict(response.json()) return response_422 @@ -43,7 +44,7 @@ def _parse_response(*, response: httpx.Response) -> Optional[Union[Any, HTTPVali def _build_response(*, response: httpx.Response) -> Response[Union[Any, HTTPValidationError]]: return Response( - status_code=response.status_code, + status_code=HTTPStatus(response.status_code), content=response.content, headers=response.headers, parsed=_parse_response(response=response), diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/tests/upload_multiple_files_tests_upload_post.py b/end_to_end_tests/golden-record/my_test_api_client/api/tests/upload_multiple_files_tests_upload_post.py index c278f408b..58c3cef41 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/tests/upload_multiple_files_tests_upload_post.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/tests/upload_multiple_files_tests_upload_post.py @@ -1,3 +1,4 @@ +from http import HTTPStatus from typing import Any, Dict, List, Optional, Union, cast import httpx @@ -34,10 +35,10 @@ def _get_kwargs( def _parse_response(*, response: httpx.Response) -> Optional[Union[Any, HTTPValidationError]]: - if response.status_code == 200: + if response.status_code == HTTPStatus.OK: response_200 = cast(Any, response.json()) return response_200 - if response.status_code == 422: + if response.status_code == HTTPStatus.UNPROCESSABLE_ENTITY: response_422 = HTTPValidationError.from_dict(response.json()) return response_422 @@ -46,7 +47,7 @@ def _parse_response(*, response: httpx.Response) -> Optional[Union[Any, HTTPVali def _build_response(*, response: httpx.Response) -> Response[Union[Any, HTTPValidationError]]: return Response( - status_code=response.status_code, + status_code=HTTPStatus(response.status_code), content=response.content, headers=response.headers, parsed=_parse_response(response=response), diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/true_/false_.py b/end_to_end_tests/golden-record/my_test_api_client/api/true_/false_.py index 2007bd6bd..adc27ae4a 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/true_/false_.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/true_/false_.py @@ -1,3 +1,4 @@ +from http import HTTPStatus from typing import Any, Dict import httpx @@ -33,7 +34,7 @@ def _get_kwargs( def _build_response(*, response: httpx.Response) -> Response[Any]: return Response( - status_code=response.status_code, + status_code=HTTPStatus(response.status_code), content=response.content, headers=response.headers, parsed=None, diff --git a/end_to_end_tests/golden-record/my_test_api_client/types.py b/end_to_end_tests/golden-record/my_test_api_client/types.py index d8727579f..230efea92 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/types.py +++ b/end_to_end_tests/golden-record/my_test_api_client/types.py @@ -1,4 +1,5 @@ """ Contains some shared types for properties """ +from http import HTTPStatus from typing import BinaryIO, Generic, MutableMapping, Optional, Tuple, TypeVar import attr @@ -34,7 +35,7 @@ def to_tuple(self) -> FileJsonType: class Response(Generic[T]): """A response from an endpoint""" - status_code: int + status_code: HTTPStatus content: bytes headers: MutableMapping[str, str] parsed: Optional[T] diff --git a/integration-tests/integration_tests/api/body/post_body_multipart.py b/integration-tests/integration_tests/api/body/post_body_multipart.py index b582d9bfc..fd73dcafa 100644 --- a/integration-tests/integration_tests/api/body/post_body_multipart.py +++ b/integration-tests/integration_tests/api/body/post_body_multipart.py @@ -1,3 +1,4 @@ +from http import HTTPStatus from typing import Any, Dict, Optional, Union import httpx @@ -32,11 +33,11 @@ def _get_kwargs( def _parse_response(*, response: httpx.Response) -> Optional[Union[PostBodyMultipartResponse200, PublicError]]: - if response.status_code == 200: + if response.status_code == HTTPStatus.OK: response_200 = PostBodyMultipartResponse200.from_dict(response.json()) return response_200 - if response.status_code == 400: + if response.status_code == HTTPStatus.BAD_REQUEST: response_400 = PublicError.from_dict(response.json()) return response_400 @@ -45,7 +46,7 @@ def _parse_response(*, response: httpx.Response) -> Optional[Union[PostBodyMulti def _build_response(*, response: httpx.Response) -> Response[Union[PostBodyMultipartResponse200, PublicError]]: return Response( - status_code=response.status_code, + status_code=HTTPStatus(response.status_code), content=response.content, headers=response.headers, parsed=_parse_response(response=response), diff --git a/integration-tests/integration_tests/api/parameters/post_parameters_header.py b/integration-tests/integration_tests/api/parameters/post_parameters_header.py index 1d12d6f8b..22879a766 100644 --- a/integration-tests/integration_tests/api/parameters/post_parameters_header.py +++ b/integration-tests/integration_tests/api/parameters/post_parameters_header.py @@ -1,3 +1,4 @@ +from http import HTTPStatus from typing import Any, Dict, Optional, Union import httpx @@ -39,11 +40,11 @@ def _get_kwargs( def _parse_response(*, response: httpx.Response) -> Optional[Union[PostParametersHeaderResponse200, PublicError]]: - if response.status_code == 200: + if response.status_code == HTTPStatus.OK: response_200 = PostParametersHeaderResponse200.from_dict(response.json()) return response_200 - if response.status_code == 400: + if response.status_code == HTTPStatus.BAD_REQUEST: response_400 = PublicError.from_dict(response.json()) return response_400 @@ -52,7 +53,7 @@ def _parse_response(*, response: httpx.Response) -> Optional[Union[PostParameter def _build_response(*, response: httpx.Response) -> Response[Union[PostParametersHeaderResponse200, PublicError]]: return Response( - status_code=response.status_code, + status_code=HTTPStatus(response.status_code), content=response.content, headers=response.headers, parsed=_parse_response(response=response), diff --git a/integration-tests/integration_tests/types.py b/integration-tests/integration_tests/types.py index d8727579f..230efea92 100644 --- a/integration-tests/integration_tests/types.py +++ b/integration-tests/integration_tests/types.py @@ -1,4 +1,5 @@ """ Contains some shared types for properties """ +from http import HTTPStatus from typing import BinaryIO, Generic, MutableMapping, Optional, Tuple, TypeVar import attr @@ -34,7 +35,7 @@ def to_tuple(self) -> FileJsonType: class Response(Generic[T]): """A response from an endpoint""" - status_code: int + status_code: HTTPStatus content: bytes headers: MutableMapping[str, str] parsed: Optional[T] diff --git a/openapi_python_client/parser/openapi.py b/openapi_python_client/parser/openapi.py index 8ebf02a39..b6c2a5411 100644 --- a/openapi_python_client/parser/openapi.py +++ b/openapi_python_client/parser/openapi.py @@ -2,6 +2,7 @@ from collections import OrderedDict from copy import deepcopy from dataclasses import dataclass, field +from http import HTTPStatus from typing import Any, Dict, Iterator, List, Optional, Set, Tuple, Union import attr @@ -256,15 +257,16 @@ def _add_responses( endpoint = deepcopy(endpoint) for code, response_data in data.items(): - status_code: int + status_code: HTTPStatus try: - status_code = int(code) + status_code = HTTPStatus(int(code)) except ValueError: endpoint.errors.append( ParseError( detail=( - f"Invalid response status code {code} (not a number), " - f"response will be ommitted from generated client" + f"Invalid response status code {code} (not a valid HTTP " + f"status code), response will be ommitted from generated " + f"client" ) ) ) diff --git a/openapi_python_client/parser/responses.py b/openapi_python_client/parser/responses.py index 2aaa112d5..f642cfb11 100644 --- a/openapi_python_client/parser/responses.py +++ b/openapi_python_client/parser/responses.py @@ -1,5 +1,6 @@ __all__ = ["Response", "response_from_data"] +from http import HTTPStatus from typing import Optional, Tuple, Union import attr @@ -15,7 +16,7 @@ class Response: """Describes a single response for an endpoint""" - status_code: int + status_code: HTTPStatus prop: Property source: str @@ -28,7 +29,9 @@ class Response: } -def empty_response(*, status_code: int, response_name: str, config: Config, description: Optional[str]) -> Response: +def empty_response( + *, status_code: HTTPStatus, response_name: str, config: Config, description: Optional[str] +) -> Response: """Return an untyped response, for when no response type is defined""" return Response( status_code=status_code, @@ -46,7 +49,12 @@ def empty_response(*, status_code: int, response_name: str, config: Config, desc def response_from_data( - *, status_code: int, data: Union[oai.Response, oai.Reference], schemas: Schemas, parent_name: str, config: Config + *, + status_code: HTTPStatus, + data: Union[oai.Response, oai.Reference], + schemas: Schemas, + parent_name: str, + config: Config, ) -> Tuple[Union[Response, ParseError], Schemas]: """Generate a Response from the OpenAPI dictionary representation of it""" diff --git a/openapi_python_client/templates/endpoint_module.py.jinja b/openapi_python_client/templates/endpoint_module.py.jinja index ab801e2bd..cd0830dd3 100644 --- a/openapi_python_client/templates/endpoint_module.py.jinja +++ b/openapi_python_client/templates/endpoint_module.py.jinja @@ -1,3 +1,4 @@ +from http import HTTPStatus from typing import Any, Dict, List, Optional, Union, cast import httpx @@ -75,7 +76,7 @@ def _parse_response(*, response: httpx.Response) -> Optional[{{ return_string }} def _build_response(*, response: httpx.Response) -> Response[{{ return_string }}]: return Response( - status_code=response.status_code, + status_code=HTTPStatus(response.status_code), content=response.content, headers=response.headers, {% if parsed_responses %} diff --git a/openapi_python_client/templates/types.py.jinja b/openapi_python_client/templates/types.py.jinja index bf90d01fd..c746db6e1 100644 --- a/openapi_python_client/templates/types.py.jinja +++ b/openapi_python_client/templates/types.py.jinja @@ -1,4 +1,5 @@ """ Contains some shared types for properties """ +from http import HTTPStatus from typing import Any, BinaryIO, Generic, MutableMapping, Optional, Tuple, TypeVar import attr @@ -35,7 +36,7 @@ T = TypeVar("T") class Response(Generic[T]): """ A response from an endpoint """ - status_code: int + status_code: HTTPStatus content: bytes headers: MutableMapping[str, str] parsed: Optional[T] diff --git a/tests/test_parser/test_openapi.py b/tests/test_parser/test_openapi.py index d2bb448e0..a844e4172 100644 --- a/tests/test_parser/test_openapi.py +++ b/tests/test_parser/test_openapi.py @@ -427,13 +427,14 @@ def test_add_body_happy(self, mocker): assert endpoint.form_body == form_body assert endpoint.multipart_body == multipart_body - def test__add_responses_status_code_error(self, mocker): + @pytest.mark.parametrize("response_status_code", ["not_a_number", 499]) + def test__add_responses_status_code_error(self, response_status_code, mocker): from openapi_python_client.parser.openapi import Endpoint, Schemas schemas = Schemas() response_1_data = mocker.MagicMock() data = { - "not_a_number": response_1_data, + response_status_code: response_1_data, } endpoint = self.make_endpoint() parse_error = ParseError(data=mocker.MagicMock()) @@ -444,7 +445,7 @@ def test__add_responses_status_code_error(self, mocker): assert response.errors == [ ParseError( - detail=f"Invalid response status code not_a_number (not a number), response will be ommitted from generated client" + detail=f"Invalid response status code {response_status_code} (not a valid HTTP status code), response will be ommitted from generated client" ) ] response_from_data.assert_not_called()