From 35b831abe018f45faf635c8d28cf4bf1e777c947 Mon Sep 17 00:00:00 2001 From: Forest Tong Date: Fri, 7 May 2021 13:57:37 -0400 Subject: [PATCH 1/6] Support AnyProperty --- .../api/tests/defaults_tests_defaults_post.py | 16 +++--- .../api/tests/get_basic_list_of_booleans.py | 4 +- .../api/tests/get_basic_list_of_floats.py | 4 +- .../api/tests/get_basic_list_of_integers.py | 4 +- .../api/tests/get_basic_list_of_strings.py | 4 +- .../api/tests/get_user_list.py | 4 +- .../api/tests/int_enum_tests_int_enum_post.py | 16 +++--- .../tests/json_body_tests_json_body_post.py | 16 +++--- .../no_response_tests_no_response_get.py | 42 ++++++++++++++-- .../octet_stream_tests_octet_stream_get.py | 4 +- ...tional_value_tests_optional_query_param.py | 16 +++--- .../api/tests/test_inline_objects.py | 4 +- ..._with_cookie_auth_token_with_cookie_get.py | 50 +++++++++++++++++-- ...d_content_tests_unsupported_content_get.py | 42 ++++++++++++++-- .../tests/upload_file_tests_upload_post.py | 16 +++--- .../my_test_api_client/client.py | 14 +++--- .../my_test_api_client/models/a_model.py | 2 +- .../models/all_of_sub_model.py | 2 +- .../models/another_all_of_sub_model.py | 2 +- .../body_upload_file_tests_upload_post.py | 2 +- .../models/free_form_model.py | 2 +- .../models/http_validation_error.py | 2 +- .../models/model_from_all_of.py | 2 +- .../my_test_api_client/models/model_name.py | 2 +- ...odel_with_additional_properties_inlined.py | 2 +- ..._properties_inlined_additional_property.py | 2 +- .../model_with_additional_properties_refed.py | 2 +- .../models/model_with_any_json_properties.py | 2 +- ...n_properties_additional_property_type_0.py | 2 +- ...el_with_primitive_additional_properties.py | 2 +- ...ive_additional_properties_a_date_holder.py | 2 +- .../models/model_with_property_ref.py | 2 +- .../models/model_with_union_property.py | 2 +- .../model_with_union_property_inlined.py | 2 +- ...ith_union_property_inlined_fruit_type_0.py | 2 +- ...ith_union_property_inlined_fruit_type_1.py | 2 +- .../models/test_inline_objects_json_body.py | 2 +- .../test_inline_objects_response_200.py | 2 +- .../models/validation_error.py | 2 +- .../golden-record/my_test_api_client/types.py | 6 +-- .../parser/properties/__init__.py | 14 +++++- .../property_templates/any_property.py.jinja | 9 ++++ .../test_parser/test_properties/test_init.py | 4 +- 43 files changed, 229 insertions(+), 106 deletions(-) create mode 100644 openapi_python_client/templates/property_templates/any_property.py.jinja 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 937d903a3..49d7492f8 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 @@ -131,7 +131,7 @@ def _get_kwargs( } -def _parse_response(*, response: httpx.Response) -> Optional[Union[HTTPValidationError, None]]: +def _parse_response(*, response: httpx.Response) -> Optional[Union[Any, HTTPValidationError]]: if response.status_code == 200: response_200 = None @@ -143,7 +143,7 @@ def _parse_response(*, response: httpx.Response) -> Optional[Union[HTTPValidatio return None -def _build_response(*, response: httpx.Response) -> Response[Union[HTTPValidationError, None]]: +def _build_response(*, response: httpx.Response) -> Response[Union[Any, HTTPValidationError]]: return Response( status_code=response.status_code, content=response.content, @@ -172,7 +172,7 @@ def sync_detailed( required_model_prop: ModelWithUnionProperty, nullable_model_prop: Union[Unset, None, ModelWithUnionProperty] = UNSET, nullable_required_model_prop: Optional[ModelWithUnionProperty], -) -> Response[Union[HTTPValidationError, None]]: +) -> Response[Union[Any, HTTPValidationError]]: kwargs = _get_kwargs( client=client, string_prop=string_prop, @@ -221,8 +221,8 @@ def sync( required_model_prop: ModelWithUnionProperty, nullable_model_prop: Union[Unset, None, ModelWithUnionProperty] = UNSET, nullable_required_model_prop: Optional[ModelWithUnionProperty], -) -> Optional[Union[HTTPValidationError, None]]: - """ """ +) -> Optional[Union[Any, HTTPValidationError]]: + """ """ return sync_detailed( client=client, @@ -266,7 +266,7 @@ async def asyncio_detailed( required_model_prop: ModelWithUnionProperty, nullable_model_prop: Union[Unset, None, ModelWithUnionProperty] = UNSET, nullable_required_model_prop: Optional[ModelWithUnionProperty], -) -> Response[Union[HTTPValidationError, None]]: +) -> Response[Union[Any, HTTPValidationError]]: kwargs = _get_kwargs( client=client, string_prop=string_prop, @@ -314,8 +314,8 @@ async def asyncio( required_model_prop: ModelWithUnionProperty, nullable_model_prop: Union[Unset, None, ModelWithUnionProperty] = UNSET, nullable_required_model_prop: Optional[ModelWithUnionProperty], -) -> Optional[Union[HTTPValidationError, None]]: - """ """ +) -> Optional[Union[Any, HTTPValidationError]]: + """ """ return ( await asyncio_detailed( 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 08c26dcdb..d025860ec 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 @@ -59,7 +59,7 @@ def sync( *, client: Client, ) -> Optional[List[bool]]: - """Get a list of booleans""" + """ Get a list of booleans """ return sync_detailed( client=client, @@ -84,7 +84,7 @@ async def asyncio( *, client: Client, ) -> Optional[List[bool]]: - """Get a list of booleans""" + """ Get a list of booleans """ return ( await asyncio_detailed( 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 4cd722164..e2199a3b9 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 @@ -59,7 +59,7 @@ def sync( *, client: Client, ) -> Optional[List[float]]: - """Get a list of floats""" + """ Get a list of floats """ return sync_detailed( client=client, @@ -84,7 +84,7 @@ async def asyncio( *, client: Client, ) -> Optional[List[float]]: - """Get a list of floats""" + """ Get a list of floats """ return ( await asyncio_detailed( 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 badffd2a8..dc3c6af6a 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 @@ -59,7 +59,7 @@ def sync( *, client: Client, ) -> Optional[List[int]]: - """Get a list of integers""" + """ Get a list of integers """ return sync_detailed( client=client, @@ -84,7 +84,7 @@ async def asyncio( *, client: Client, ) -> Optional[List[int]]: - """Get a list of integers""" + """ Get a list of integers """ return ( await asyncio_detailed( 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 fa040b04b..150ab9a22 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 @@ -59,7 +59,7 @@ def sync( *, client: Client, ) -> Optional[List[str]]: - """Get a list of strings""" + """ Get a list of strings """ return sync_detailed( client=client, @@ -84,7 +84,7 @@ async def asyncio( *, client: Client, ) -> Optional[List[str]]: - """Get a list of strings""" + """ Get a list of strings """ return ( await asyncio_detailed( 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 96ca18884..095f4be9d 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 @@ -102,7 +102,7 @@ def sync( an_enum_value: List[AnEnum], some_date: Union[datetime.date, datetime.datetime], ) -> Optional[Union[HTTPValidationError, List[AModel]]]: - """Get a list of things""" + """ Get a list of things """ return sync_detailed( client=client, @@ -135,7 +135,7 @@ async def asyncio( an_enum_value: List[AnEnum], some_date: Union[datetime.date, datetime.datetime], ) -> Optional[Union[HTTPValidationError, List[AModel]]]: - """Get a list of things""" + """ Get a list of things """ return ( await asyncio_detailed( 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 aebbccebc..6b581b2c4 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 @@ -34,7 +34,7 @@ def _get_kwargs( } -def _parse_response(*, response: httpx.Response) -> Optional[Union[HTTPValidationError, None]]: +def _parse_response(*, response: httpx.Response) -> Optional[Union[Any, HTTPValidationError]]: if response.status_code == 200: response_200 = None @@ -46,7 +46,7 @@ def _parse_response(*, response: httpx.Response) -> Optional[Union[HTTPValidatio return None -def _build_response(*, response: httpx.Response) -> Response[Union[HTTPValidationError, None]]: +def _build_response(*, response: httpx.Response) -> Response[Union[Any, HTTPValidationError]]: return Response( status_code=response.status_code, content=response.content, @@ -59,7 +59,7 @@ def sync_detailed( *, client: Client, int_enum: AnIntEnum, -) -> Response[Union[HTTPValidationError, None]]: +) -> Response[Union[Any, HTTPValidationError]]: kwargs = _get_kwargs( client=client, int_enum=int_enum, @@ -76,8 +76,8 @@ def sync( *, client: Client, int_enum: AnIntEnum, -) -> Optional[Union[HTTPValidationError, None]]: - """ """ +) -> Optional[Union[Any, HTTPValidationError]]: + """ """ return sync_detailed( client=client, @@ -89,7 +89,7 @@ async def asyncio_detailed( *, client: Client, int_enum: AnIntEnum, -) -> Response[Union[HTTPValidationError, None]]: +) -> Response[Union[Any, HTTPValidationError]]: kwargs = _get_kwargs( client=client, int_enum=int_enum, @@ -105,8 +105,8 @@ async def asyncio( *, client: Client, int_enum: AnIntEnum, -) -> Optional[Union[HTTPValidationError, None]]: - """ """ +) -> Optional[Union[Any, HTTPValidationError]]: + """ """ return ( await asyncio_detailed( 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 14c81c0d1..ccfd7d619 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 @@ -29,7 +29,7 @@ def _get_kwargs( } -def _parse_response(*, response: httpx.Response) -> Optional[Union[HTTPValidationError, None]]: +def _parse_response(*, response: httpx.Response) -> Optional[Union[Any, HTTPValidationError]]: if response.status_code == 200: response_200 = None @@ -41,7 +41,7 @@ def _parse_response(*, response: httpx.Response) -> Optional[Union[HTTPValidatio return None -def _build_response(*, response: httpx.Response) -> Response[Union[HTTPValidationError, None]]: +def _build_response(*, response: httpx.Response) -> Response[Union[Any, HTTPValidationError]]: return Response( status_code=response.status_code, content=response.content, @@ -54,7 +54,7 @@ def sync_detailed( *, client: Client, json_body: AModel, -) -> Response[Union[HTTPValidationError, None]]: +) -> Response[Union[Any, HTTPValidationError]]: kwargs = _get_kwargs( client=client, json_body=json_body, @@ -71,8 +71,8 @@ def sync( *, client: Client, json_body: AModel, -) -> Optional[Union[HTTPValidationError, None]]: - """Try sending a JSON body""" +) -> Optional[Union[Any, HTTPValidationError]]: + """ Try sending a JSON body """ return sync_detailed( client=client, @@ -84,7 +84,7 @@ async def asyncio_detailed( *, client: Client, json_body: AModel, -) -> Response[Union[HTTPValidationError, None]]: +) -> Response[Union[Any, HTTPValidationError]]: kwargs = _get_kwargs( client=client, json_body=json_body, @@ -100,8 +100,8 @@ async def asyncio( *, client: Client, json_body: AModel, -) -> Optional[Union[HTTPValidationError, None]]: - """Try sending a JSON body""" +) -> Optional[Union[Any, HTTPValidationError]]: + """ Try sending a JSON body """ return ( await asyncio_detailed( 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 f1e02671d..fb81baafd 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,4 +1,4 @@ -from typing import Any, Dict +from typing import Any, Dict, Optional import httpx @@ -23,19 +23,27 @@ def _get_kwargs( } -def _build_response(*, response: httpx.Response) -> Response[None]: +def _parse_response(*, response: httpx.Response) -> Optional[Any]: + if response.status_code == 200: + response_200 = None + + return response_200 + return None + + +def _build_response(*, response: httpx.Response) -> Response[Any]: return Response( status_code=response.status_code, content=response.content, headers=response.headers, - parsed=None, + parsed=_parse_response(response=response), ) def sync_detailed( *, client: Client, -) -> Response[None]: +) -> Response[Any]: kwargs = _get_kwargs( client=client, ) @@ -47,10 +55,21 @@ def sync_detailed( return _build_response(response=response) +def sync( + *, + client: Client, +) -> Optional[Any]: + """ """ + + return sync_detailed( + client=client, + ).parsed + + async def asyncio_detailed( *, client: Client, -) -> Response[None]: +) -> Response[Any]: kwargs = _get_kwargs( client=client, ) @@ -59,3 +78,16 @@ async def asyncio_detailed( response = await _client.get(**kwargs) return _build_response(response=response) + + +async def asyncio( + *, + client: Client, +) -> Optional[Any]: + """ """ + + return ( + await asyncio_detailed( + client=client, + ) + ).parsed 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 f399df6b5..b1e3a0cf7 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 @@ -60,7 +60,7 @@ def sync( *, client: Client, ) -> Optional[File]: - """ """ + """ """ return sync_detailed( client=client, @@ -85,7 +85,7 @@ async def asyncio( *, client: Client, ) -> Optional[File]: - """ """ + """ """ return ( await asyncio_detailed( diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/tests/optional_value_tests_optional_query_param.py b/end_to_end_tests/golden-record/my_test_api_client/api/tests/optional_value_tests_optional_query_param.py index 55e040f3c..5887f9429 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/tests/optional_value_tests_optional_query_param.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/tests/optional_value_tests_optional_query_param.py @@ -35,7 +35,7 @@ def _get_kwargs( } -def _parse_response(*, response: httpx.Response) -> Optional[Union[HTTPValidationError, None]]: +def _parse_response(*, response: httpx.Response) -> Optional[Union[Any, HTTPValidationError]]: if response.status_code == 200: response_200 = None @@ -47,7 +47,7 @@ def _parse_response(*, response: httpx.Response) -> Optional[Union[HTTPValidatio return None -def _build_response(*, response: httpx.Response) -> Response[Union[HTTPValidationError, None]]: +def _build_response(*, response: httpx.Response) -> Response[Union[Any, HTTPValidationError]]: return Response( status_code=response.status_code, content=response.content, @@ -60,7 +60,7 @@ def sync_detailed( *, client: Client, query_param: Union[Unset, List[str]] = UNSET, -) -> Response[Union[HTTPValidationError, None]]: +) -> Response[Union[Any, HTTPValidationError]]: kwargs = _get_kwargs( client=client, query_param=query_param, @@ -77,8 +77,8 @@ def sync( *, client: Client, query_param: Union[Unset, List[str]] = UNSET, -) -> Optional[Union[HTTPValidationError, None]]: - """Test optional query parameters""" +) -> Optional[Union[Any, HTTPValidationError]]: + """ Test optional query parameters """ return sync_detailed( client=client, @@ -90,7 +90,7 @@ async def asyncio_detailed( *, client: Client, query_param: Union[Unset, List[str]] = UNSET, -) -> Response[Union[HTTPValidationError, None]]: +) -> Response[Union[Any, HTTPValidationError]]: kwargs = _get_kwargs( client=client, query_param=query_param, @@ -106,8 +106,8 @@ async def asyncio( *, client: Client, query_param: Union[Unset, List[str]] = UNSET, -) -> Optional[Union[HTTPValidationError, None]]: - """Test optional query parameters""" +) -> Optional[Union[Any, HTTPValidationError]]: + """ Test optional query parameters """ return ( await asyncio_detailed( 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 59d12f3d6..04fc372c4 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 @@ -68,7 +68,7 @@ def sync( client: Client, json_body: TestInlineObjectsJsonBody, ) -> Optional[TestInlineObjectsResponse200]: - """ """ + """ """ return sync_detailed( client=client, @@ -97,7 +97,7 @@ async def asyncio( client: Client, json_body: TestInlineObjectsJsonBody, ) -> Optional[TestInlineObjectsResponse200]: - """ """ + """ """ return ( await asyncio_detailed( 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 1ca44278f..55ce6a120 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,4 +1,4 @@ -from typing import Any, Dict +from typing import Any, Dict, Optional, Union import httpx @@ -26,12 +26,24 @@ def _get_kwargs( } -def _build_response(*, response: httpx.Response) -> Response[None]: +def _parse_response(*, response: httpx.Response) -> Optional[Union[Any, None]]: + if response.status_code == 200: + response_200 = None + + return response_200 + if response.status_code == 401: + response_401 = None + + return response_401 + return None + + +def _build_response(*, response: httpx.Response) -> Response[Union[Any, None]]: return Response( status_code=response.status_code, content=response.content, headers=response.headers, - parsed=None, + parsed=_parse_response(response=response), ) @@ -39,7 +51,7 @@ def sync_detailed( *, client: Client, my_token: str, -) -> Response[None]: +) -> Response[Union[Any, None]]: kwargs = _get_kwargs( client=client, my_token=my_token, @@ -52,11 +64,24 @@ def sync_detailed( return _build_response(response=response) +def sync( + *, + client: Client, + my_token: str, +) -> Optional[Union[Any, None]]: + """ Test optional cookie parameters """ + + return sync_detailed( + client=client, + my_token=my_token, + ).parsed + + async def asyncio_detailed( *, client: Client, my_token: str, -) -> Response[None]: +) -> Response[Union[Any, None]]: kwargs = _get_kwargs( client=client, my_token=my_token, @@ -66,3 +91,18 @@ async def asyncio_detailed( response = await _client.get(**kwargs) return _build_response(response=response) + + +async def asyncio( + *, + client: Client, + my_token: str, +) -> Optional[Union[Any, None]]: + """ Test optional cookie parameters """ + + return ( + await asyncio_detailed( + client=client, + my_token=my_token, + ) + ).parsed 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 a1d5d5a0d..5e9193740 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,4 +1,4 @@ -from typing import Any, Dict +from typing import Any, Dict, Optional import httpx @@ -23,19 +23,27 @@ def _get_kwargs( } -def _build_response(*, response: httpx.Response) -> Response[None]: +def _parse_response(*, response: httpx.Response) -> Optional[Any]: + if response.status_code == 200: + response_200 = None + + return response_200 + return None + + +def _build_response(*, response: httpx.Response) -> Response[Any]: return Response( status_code=response.status_code, content=response.content, headers=response.headers, - parsed=None, + parsed=_parse_response(response=response), ) def sync_detailed( *, client: Client, -) -> Response[None]: +) -> Response[Any]: kwargs = _get_kwargs( client=client, ) @@ -47,10 +55,21 @@ def sync_detailed( return _build_response(response=response) +def sync( + *, + client: Client, +) -> Optional[Any]: + """ """ + + return sync_detailed( + client=client, + ).parsed + + async def asyncio_detailed( *, client: Client, -) -> Response[None]: +) -> Response[Any]: kwargs = _get_kwargs( client=client, ) @@ -59,3 +78,16 @@ async def asyncio_detailed( response = await _client.get(**kwargs) return _build_response(response=response) + + +async def asyncio( + *, + client: Client, +) -> Optional[Any]: + """ """ + + return ( + await asyncio_detailed( + client=client, + ) + ).parsed 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 7148ce5f3..9c6a8a460 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 @@ -40,7 +40,7 @@ def _get_kwargs( } -def _parse_response(*, response: httpx.Response) -> Optional[Union[HTTPValidationError, None]]: +def _parse_response(*, response: httpx.Response) -> Optional[Union[Any, HTTPValidationError]]: if response.status_code == 200: response_200 = None @@ -52,7 +52,7 @@ def _parse_response(*, response: httpx.Response) -> Optional[Union[HTTPValidatio return None -def _build_response(*, response: httpx.Response) -> Response[Union[HTTPValidationError, None]]: +def _build_response(*, response: httpx.Response) -> Response[Union[Any, HTTPValidationError]]: return Response( status_code=response.status_code, content=response.content, @@ -66,7 +66,7 @@ def sync_detailed( client: Client, multipart_data: BodyUploadFileTestsUploadPost, keep_alive: Union[Unset, bool] = UNSET, -) -> Response[Union[HTTPValidationError, None]]: +) -> Response[Union[Any, HTTPValidationError]]: kwargs = _get_kwargs( client=client, multipart_data=multipart_data, @@ -85,8 +85,8 @@ def sync( client: Client, multipart_data: BodyUploadFileTestsUploadPost, keep_alive: Union[Unset, bool] = UNSET, -) -> Optional[Union[HTTPValidationError, None]]: - """Upload a file""" +) -> Optional[Union[Any, HTTPValidationError]]: + """ Upload a file """ return sync_detailed( client=client, @@ -100,7 +100,7 @@ async def asyncio_detailed( client: Client, multipart_data: BodyUploadFileTestsUploadPost, keep_alive: Union[Unset, bool] = UNSET, -) -> Response[Union[HTTPValidationError, None]]: +) -> Response[Union[Any, HTTPValidationError]]: kwargs = _get_kwargs( client=client, multipart_data=multipart_data, @@ -118,8 +118,8 @@ async def asyncio( client: Client, multipart_data: BodyUploadFileTestsUploadPost, keep_alive: Union[Unset, bool] = UNSET, -) -> Optional[Union[HTTPValidationError, None]]: - """Upload a file""" +) -> Optional[Union[Any, HTTPValidationError]]: + """ Upload a file """ return ( await asyncio_detailed( diff --git a/end_to_end_tests/golden-record/my_test_api_client/client.py b/end_to_end_tests/golden-record/my_test_api_client/client.py index 36fa529e0..c3074040c 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/client.py +++ b/end_to_end_tests/golden-record/my_test_api_client/client.py @@ -5,7 +5,7 @@ @attr.s(auto_attribs=True) class Client: - """A class for keeping track of data related to the API""" + """ A class for keeping track of data related to the API """ base_url: str cookies: Dict[str, str] = attr.ib(factory=dict, kw_only=True) @@ -13,34 +13,34 @@ class Client: timeout: float = attr.ib(5.0, kw_only=True) def get_headers(self) -> Dict[str, str]: - """Get headers to be used in all endpoints""" + """ Get headers to be used in all endpoints """ return {**self.headers} def with_headers(self, headers: Dict[str, str]) -> "Client": - """Get a new client matching this one with additional headers""" + """ Get a new client matching this one with additional headers """ return attr.evolve(self, headers={**self.headers, **headers}) def get_cookies(self) -> Dict[str, str]: return {**self.cookies} def with_cookies(self, cookies: Dict[str, str]) -> "Client": - """Get a new client matching this one with additional cookies""" + """ Get a new client matching this one with additional cookies """ return attr.evolve(self, cookies={**self.cookies, **cookies}) def get_timeout(self) -> float: return self.timeout def with_timeout(self, timeout: float) -> "Client": - """Get a new client matching this one with a new timeout (in seconds)""" + """ Get a new client matching this one with a new timeout (in seconds) """ return attr.evolve(self, timeout=timeout) @attr.s(auto_attribs=True) class AuthenticatedClient(Client): - """A Client which has been authenticated for use on secured endpoints""" + """ A Client which has been authenticated for use on secured endpoints """ token: str def get_headers(self) -> Dict[str, str]: - """Get headers to be used in authenticated endpoints""" + """ Get headers to be used in authenticated endpoints """ return {"Authorization": f"Bearer {self.token}", **self.headers} diff --git a/end_to_end_tests/golden-record/my_test_api_client/models/a_model.py b/end_to_end_tests/golden-record/my_test_api_client/models/a_model.py index 38ce8d114..c058bf291 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/models/a_model.py +++ b/end_to_end_tests/golden-record/my_test_api_client/models/a_model.py @@ -16,7 +16,7 @@ @attr.s(auto_attribs=True) class AModel: - """A Model for testing all the ways custom objects can be used""" + """ A Model for testing all the ways custom objects can be used """ an_enum_value: AnEnum a_camel_date_time: Union[datetime.date, datetime.datetime] diff --git a/end_to_end_tests/golden-record/my_test_api_client/models/all_of_sub_model.py b/end_to_end_tests/golden-record/my_test_api_client/models/all_of_sub_model.py index 8945c70ab..baa59d06a 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/models/all_of_sub_model.py +++ b/end_to_end_tests/golden-record/my_test_api_client/models/all_of_sub_model.py @@ -9,7 +9,7 @@ @attr.s(auto_attribs=True) class AllOfSubModel: - """ """ + """ """ a_sub_property: Union[Unset, str] = UNSET additional_properties: Dict[str, Any] = attr.ib(init=False, factory=dict) diff --git a/end_to_end_tests/golden-record/my_test_api_client/models/another_all_of_sub_model.py b/end_to_end_tests/golden-record/my_test_api_client/models/another_all_of_sub_model.py index 2ecc464a8..3949852c6 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/models/another_all_of_sub_model.py +++ b/end_to_end_tests/golden-record/my_test_api_client/models/another_all_of_sub_model.py @@ -9,7 +9,7 @@ @attr.s(auto_attribs=True) class AnotherAllOfSubModel: - """ """ + """ """ another_sub_property: Union[Unset, str] = UNSET additional_properties: Dict[str, Any] = attr.ib(init=False, factory=dict) diff --git a/end_to_end_tests/golden-record/my_test_api_client/models/body_upload_file_tests_upload_post.py b/end_to_end_tests/golden-record/my_test_api_client/models/body_upload_file_tests_upload_post.py index d2d263353..a250dbb37 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/models/body_upload_file_tests_upload_post.py +++ b/end_to_end_tests/golden-record/my_test_api_client/models/body_upload_file_tests_upload_post.py @@ -10,7 +10,7 @@ @attr.s(auto_attribs=True) class BodyUploadFileTestsUploadPost: - """ """ + """ """ some_file: File some_string: Union[Unset, str] = "some_default_string" diff --git a/end_to_end_tests/golden-record/my_test_api_client/models/free_form_model.py b/end_to_end_tests/golden-record/my_test_api_client/models/free_form_model.py index f8cc2151c..1a86b6bac 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/models/free_form_model.py +++ b/end_to_end_tests/golden-record/my_test_api_client/models/free_form_model.py @@ -7,7 +7,7 @@ @attr.s(auto_attribs=True) class FreeFormModel: - """ """ + """ """ additional_properties: Dict[str, Any] = attr.ib(init=False, factory=dict) diff --git a/end_to_end_tests/golden-record/my_test_api_client/models/http_validation_error.py b/end_to_end_tests/golden-record/my_test_api_client/models/http_validation_error.py index e777fcc87..feb2cdd6b 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/models/http_validation_error.py +++ b/end_to_end_tests/golden-record/my_test_api_client/models/http_validation_error.py @@ -10,7 +10,7 @@ @attr.s(auto_attribs=True) class HTTPValidationError: - """ """ + """ """ detail: Union[Unset, List[ValidationError]] = UNSET diff --git a/end_to_end_tests/golden-record/my_test_api_client/models/model_from_all_of.py b/end_to_end_tests/golden-record/my_test_api_client/models/model_from_all_of.py index 60406f46d..ce26a3bbb 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/models/model_from_all_of.py +++ b/end_to_end_tests/golden-record/my_test_api_client/models/model_from_all_of.py @@ -9,7 +9,7 @@ @attr.s(auto_attribs=True) class ModelFromAllOf: - """ """ + """ """ a_sub_property: Union[Unset, str] = UNSET another_sub_property: Union[Unset, str] = UNSET diff --git a/end_to_end_tests/golden-record/my_test_api_client/models/model_name.py b/end_to_end_tests/golden-record/my_test_api_client/models/model_name.py index c87d4c208..75b12f284 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/models/model_name.py +++ b/end_to_end_tests/golden-record/my_test_api_client/models/model_name.py @@ -7,7 +7,7 @@ @attr.s(auto_attribs=True) class ModelName: - """ """ + """ """ additional_properties: Dict[str, Any] = attr.ib(init=False, factory=dict) diff --git a/end_to_end_tests/golden-record/my_test_api_client/models/model_with_additional_properties_inlined.py b/end_to_end_tests/golden-record/my_test_api_client/models/model_with_additional_properties_inlined.py index a2e168758..a81e57a8e 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/models/model_with_additional_properties_inlined.py +++ b/end_to_end_tests/golden-record/my_test_api_client/models/model_with_additional_properties_inlined.py @@ -12,7 +12,7 @@ @attr.s(auto_attribs=True) class ModelWithAdditionalPropertiesInlined: - """ """ + """ """ a_number: Union[Unset, float] = UNSET additional_properties: Dict[str, ModelWithAdditionalPropertiesInlinedAdditionalProperty] = attr.ib( diff --git a/end_to_end_tests/golden-record/my_test_api_client/models/model_with_additional_properties_inlined_additional_property.py b/end_to_end_tests/golden-record/my_test_api_client/models/model_with_additional_properties_inlined_additional_property.py index 490f6e34c..baedb6193 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/models/model_with_additional_properties_inlined_additional_property.py +++ b/end_to_end_tests/golden-record/my_test_api_client/models/model_with_additional_properties_inlined_additional_property.py @@ -9,7 +9,7 @@ @attr.s(auto_attribs=True) class ModelWithAdditionalPropertiesInlinedAdditionalProperty: - """ """ + """ """ extra_props_prop: Union[Unset, str] = UNSET additional_properties: Dict[str, Any] = attr.ib(init=False, factory=dict) diff --git a/end_to_end_tests/golden-record/my_test_api_client/models/model_with_additional_properties_refed.py b/end_to_end_tests/golden-record/my_test_api_client/models/model_with_additional_properties_refed.py index d51c5d72c..b265db582 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/models/model_with_additional_properties_refed.py +++ b/end_to_end_tests/golden-record/my_test_api_client/models/model_with_additional_properties_refed.py @@ -9,7 +9,7 @@ @attr.s(auto_attribs=True) class ModelWithAdditionalPropertiesRefed: - """ """ + """ """ additional_properties: Dict[str, AnEnum] = attr.ib(init=False, factory=dict) diff --git a/end_to_end_tests/golden-record/my_test_api_client/models/model_with_any_json_properties.py b/end_to_end_tests/golden-record/my_test_api_client/models/model_with_any_json_properties.py index ecfa97b10..9b22f9154 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/models/model_with_any_json_properties.py +++ b/end_to_end_tests/golden-record/my_test_api_client/models/model_with_any_json_properties.py @@ -11,7 +11,7 @@ @attr.s(auto_attribs=True) class ModelWithAnyJsonProperties: - """ """ + """ """ additional_properties: Dict[ str, Union[List[str], ModelWithAnyJsonPropertiesAdditionalPropertyType0, bool, float, int, str] diff --git a/end_to_end_tests/golden-record/my_test_api_client/models/model_with_any_json_properties_additional_property_type_0.py b/end_to_end_tests/golden-record/my_test_api_client/models/model_with_any_json_properties_additional_property_type_0.py index 19e863fc4..5d271b266 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/models/model_with_any_json_properties_additional_property_type_0.py +++ b/end_to_end_tests/golden-record/my_test_api_client/models/model_with_any_json_properties_additional_property_type_0.py @@ -7,7 +7,7 @@ @attr.s(auto_attribs=True) class ModelWithAnyJsonPropertiesAdditionalPropertyType0: - """ """ + """ """ additional_properties: Dict[str, str] = attr.ib(init=False, factory=dict) diff --git a/end_to_end_tests/golden-record/my_test_api_client/models/model_with_primitive_additional_properties.py b/end_to_end_tests/golden-record/my_test_api_client/models/model_with_primitive_additional_properties.py index 5dc264152..68e2238dd 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/models/model_with_primitive_additional_properties.py +++ b/end_to_end_tests/golden-record/my_test_api_client/models/model_with_primitive_additional_properties.py @@ -12,7 +12,7 @@ @attr.s(auto_attribs=True) class ModelWithPrimitiveAdditionalProperties: - """ """ + """ """ a_date_holder: Union[Unset, ModelWithPrimitiveAdditionalPropertiesADateHolder] = UNSET additional_properties: Dict[str, str] = attr.ib(init=False, factory=dict) diff --git a/end_to_end_tests/golden-record/my_test_api_client/models/model_with_primitive_additional_properties_a_date_holder.py b/end_to_end_tests/golden-record/my_test_api_client/models/model_with_primitive_additional_properties_a_date_holder.py index aa8a25252..3df34635f 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/models/model_with_primitive_additional_properties_a_date_holder.py +++ b/end_to_end_tests/golden-record/my_test_api_client/models/model_with_primitive_additional_properties_a_date_holder.py @@ -9,7 +9,7 @@ @attr.s(auto_attribs=True) class ModelWithPrimitiveAdditionalPropertiesADateHolder: - """ """ + """ """ additional_properties: Dict[str, datetime.datetime] = attr.ib(init=False, factory=dict) diff --git a/end_to_end_tests/golden-record/my_test_api_client/models/model_with_property_ref.py b/end_to_end_tests/golden-record/my_test_api_client/models/model_with_property_ref.py index 6ebba75a6..1553914ba 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/models/model_with_property_ref.py +++ b/end_to_end_tests/golden-record/my_test_api_client/models/model_with_property_ref.py @@ -10,7 +10,7 @@ @attr.s(auto_attribs=True) class ModelWithPropertyRef: - """ """ + """ """ inner: Union[Unset, ModelName] = UNSET additional_properties: Dict[str, Any] = attr.ib(init=False, factory=dict) diff --git a/end_to_end_tests/golden-record/my_test_api_client/models/model_with_union_property.py b/end_to_end_tests/golden-record/my_test_api_client/models/model_with_union_property.py index 87034d5e7..5981b8c74 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/models/model_with_union_property.py +++ b/end_to_end_tests/golden-record/my_test_api_client/models/model_with_union_property.py @@ -11,7 +11,7 @@ @attr.s(auto_attribs=True) class ModelWithUnionProperty: - """ """ + """ """ a_property: Union[AnEnum, AnIntEnum, Unset] = UNSET diff --git a/end_to_end_tests/golden-record/my_test_api_client/models/model_with_union_property_inlined.py b/end_to_end_tests/golden-record/my_test_api_client/models/model_with_union_property_inlined.py index 822f45cc2..a9607f999 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/models/model_with_union_property_inlined.py +++ b/end_to_end_tests/golden-record/my_test_api_client/models/model_with_union_property_inlined.py @@ -11,7 +11,7 @@ @attr.s(auto_attribs=True) class ModelWithUnionPropertyInlined: - """ """ + """ """ fruit: Union[ModelWithUnionPropertyInlinedFruitType0, ModelWithUnionPropertyInlinedFruitType1, Unset] = UNSET diff --git a/end_to_end_tests/golden-record/my_test_api_client/models/model_with_union_property_inlined_fruit_type_0.py b/end_to_end_tests/golden-record/my_test_api_client/models/model_with_union_property_inlined_fruit_type_0.py index 333d822c7..8a8739465 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/models/model_with_union_property_inlined_fruit_type_0.py +++ b/end_to_end_tests/golden-record/my_test_api_client/models/model_with_union_property_inlined_fruit_type_0.py @@ -9,7 +9,7 @@ @attr.s(auto_attribs=True) class ModelWithUnionPropertyInlinedFruitType0: - """ """ + """ """ apples: Union[Unset, str] = UNSET additional_properties: Dict[str, Any] = attr.ib(init=False, factory=dict) diff --git a/end_to_end_tests/golden-record/my_test_api_client/models/model_with_union_property_inlined_fruit_type_1.py b/end_to_end_tests/golden-record/my_test_api_client/models/model_with_union_property_inlined_fruit_type_1.py index d2020747c..7b1792f5e 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/models/model_with_union_property_inlined_fruit_type_1.py +++ b/end_to_end_tests/golden-record/my_test_api_client/models/model_with_union_property_inlined_fruit_type_1.py @@ -9,7 +9,7 @@ @attr.s(auto_attribs=True) class ModelWithUnionPropertyInlinedFruitType1: - """ """ + """ """ bananas: Union[Unset, str] = UNSET additional_properties: Dict[str, Any] = attr.ib(init=False, factory=dict) diff --git a/end_to_end_tests/golden-record/my_test_api_client/models/test_inline_objects_json_body.py b/end_to_end_tests/golden-record/my_test_api_client/models/test_inline_objects_json_body.py index e74ed557b..1ee542873 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/models/test_inline_objects_json_body.py +++ b/end_to_end_tests/golden-record/my_test_api_client/models/test_inline_objects_json_body.py @@ -9,7 +9,7 @@ @attr.s(auto_attribs=True) class TestInlineObjectsJsonBody: - """ """ + """ """ a_property: Union[Unset, str] = UNSET diff --git a/end_to_end_tests/golden-record/my_test_api_client/models/test_inline_objects_response_200.py b/end_to_end_tests/golden-record/my_test_api_client/models/test_inline_objects_response_200.py index 7c6aa6fb2..9b1a6fa58 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/models/test_inline_objects_response_200.py +++ b/end_to_end_tests/golden-record/my_test_api_client/models/test_inline_objects_response_200.py @@ -9,7 +9,7 @@ @attr.s(auto_attribs=True) class TestInlineObjectsResponse200: - """ """ + """ """ a_property: Union[Unset, str] = UNSET diff --git a/end_to_end_tests/golden-record/my_test_api_client/models/validation_error.py b/end_to_end_tests/golden-record/my_test_api_client/models/validation_error.py index 8bbb20c76..a0cd07b51 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/models/validation_error.py +++ b/end_to_end_tests/golden-record/my_test_api_client/models/validation_error.py @@ -7,7 +7,7 @@ @attr.s(auto_attribs=True) class ValidationError: - """ """ + """ """ loc: List[str] msg: str 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 2b1cfc5b8..0739e2197 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 @@ -16,14 +16,14 @@ def __bool__(self) -> bool: @attr.s(auto_attribs=True) class File: - """Contains information for file uploads""" + """ Contains information for file uploads """ payload: Union[BinaryIO, TextIO] file_name: Optional[str] = None mime_type: Optional[str] = None def to_tuple(self) -> FileJsonType: - """Return a tuple representation that httpx will accept for multipart/form-data""" + """ Return a tuple representation that httpx will accept for multipart/form-data """ return self.file_name, self.payload, self.mime_type @@ -32,7 +32,7 @@ def to_tuple(self) -> FileJsonType: @attr.s(auto_attribs=True) class Response(Generic[T]): - """A response from an endpoint""" + """ A response from an endpoint """ status_code: int content: bytes diff --git a/openapi_python_client/parser/properties/__init__.py b/openapi_python_client/parser/properties/__init__.py index 908745a6a..920963168 100644 --- a/openapi_python_client/parser/properties/__init__.py +++ b/openapi_python_client/parser/properties/__init__.py @@ -1,4 +1,5 @@ __all__ = [ + "AnyProperty", "Class", "EnumProperty", "ModelProperty", @@ -27,13 +28,22 @@ @attr.s(auto_attribs=True, frozen=True) class NoneProperty(Property): - """A property that is always None (used for empty schemas)""" + """A property that is always None""" _type_string: ClassVar[str] = "None" _json_type_string: ClassVar[str] = "None" template: ClassVar[Optional[str]] = "none_property.py.jinja" +@attr.s(auto_attribs=True, frozen=True) +class AnyProperty(Property): + """A property that can be any type (used for empty schemas)""" + + _type_string: ClassVar[str] = "Any" + _json_type_string: ClassVar[str] = "Any" + template: ClassVar[Optional[str]] = "any_property.py.jinja" + + @attr.s(auto_attribs=True, frozen=True) class StringProperty(Property): """A property of type str""" @@ -499,7 +509,7 @@ def _property_from_data( data=data, name=name, schemas=schemas, required=required, parent_name=parent_name, config=config ) elif not data.type: - return NoneProperty(name=name, required=required, nullable=False, default=None), schemas + return AnyProperty(name=name, required=required, nullable=False, default=None), schemas return PropertyError(data=data, detail=f"unknown type {data.type}"), schemas diff --git a/openapi_python_client/templates/property_templates/any_property.py.jinja b/openapi_python_client/templates/property_templates/any_property.py.jinja new file mode 100644 index 000000000..bdcdc72c4 --- /dev/null +++ b/openapi_python_client/templates/property_templates/any_property.py.jinja @@ -0,0 +1,9 @@ +{% macro construct(property, source, initial_value="None") %} +{{ property.python_name }} = {{ initial_value }} +{% endmacro %} + +{% macro check_type_for_construct(property, source) %}True{% endmacro %} + +{% macro transform(property, source, destination, declare_type=True) %} +{{ destination }} = source +{% endmacro %} diff --git a/tests/test_parser/test_properties/test_init.py b/tests/test_parser/test_properties/test_init.py index 1f5646d74..218352095 100644 --- a/tests/test_parser/test_properties/test_init.py +++ b/tests/test_parser/test_properties/test_init.py @@ -850,7 +850,7 @@ def test_property_from_data_unsupported_type(self, mocker): ) def test_property_from_data_no_valid_props_in_data(self): - from openapi_python_client.parser.properties import NoneProperty, Schemas, property_from_data + from openapi_python_client.parser.properties import AnyProperty, Schemas, property_from_data schemas = Schemas() data = oai.Schema() @@ -859,7 +859,7 @@ def test_property_from_data_no_valid_props_in_data(self): name="blah", required=True, data=data, schemas=schemas, parent_name="parent", config=MagicMock() ) - assert prop == NoneProperty(name="blah", required=True, nullable=False, default=None) + assert prop == AnyProperty(name="blah", required=True, nullable=False, default=None) assert new_schemas == schemas def test_property_from_data_validation_error(self, mocker): From 70085ff565386dd56190bb4a8205973ffc99c799 Mon Sep 17 00:00:00 2001 From: Forest Tong Date: Fri, 7 May 2021 14:02:06 -0400 Subject: [PATCH 2/6] Install Poetry requirements and re --- .../api/tests/defaults_tests_defaults_post.py | 4 ++-- .../api/tests/get_basic_list_of_booleans.py | 4 ++-- .../api/tests/get_basic_list_of_floats.py | 4 ++-- .../api/tests/get_basic_list_of_integers.py | 4 ++-- .../api/tests/get_basic_list_of_strings.py | 4 ++-- .../my_test_api_client/api/tests/get_user_list.py | 4 ++-- .../api/tests/int_enum_tests_int_enum_post.py | 4 ++-- .../api/tests/json_body_tests_json_body_post.py | 4 ++-- .../api/tests/no_response_tests_no_response_get.py | 4 ++-- .../tests/octet_stream_tests_octet_stream_get.py | 4 ++-- .../optional_value_tests_optional_query_param.py | 4 ++-- .../api/tests/test_inline_objects.py | 4 ++-- ...token_with_cookie_auth_token_with_cookie_get.py | 4 ++-- ...ported_content_tests_unsupported_content_get.py | 4 ++-- .../api/tests/upload_file_tests_upload_post.py | 4 ++-- .../golden-record/my_test_api_client/client.py | 14 +++++++------- .../my_test_api_client/models/a_model.py | 2 +- .../my_test_api_client/models/all_of_sub_model.py | 2 +- .../models/another_all_of_sub_model.py | 2 +- .../models/body_upload_file_tests_upload_post.py | 2 +- .../my_test_api_client/models/free_form_model.py | 2 +- .../models/http_validation_error.py | 2 +- .../my_test_api_client/models/model_from_all_of.py | 2 +- .../my_test_api_client/models/model_name.py | 2 +- .../model_with_additional_properties_inlined.py | 2 +- ...ional_properties_inlined_additional_property.py | 2 +- .../model_with_additional_properties_refed.py | 2 +- .../models/model_with_any_json_properties.py | 2 +- ...y_json_properties_additional_property_type_0.py | 2 +- .../model_with_primitive_additional_properties.py | 2 +- ...rimitive_additional_properties_a_date_holder.py | 2 +- .../models/model_with_property_ref.py | 2 +- .../models/model_with_union_property.py | 2 +- .../models/model_with_union_property_inlined.py | 2 +- ...del_with_union_property_inlined_fruit_type_0.py | 2 +- ...del_with_union_property_inlined_fruit_type_1.py | 2 +- .../models/test_inline_objects_json_body.py | 2 +- .../models/test_inline_objects_response_200.py | 2 +- .../my_test_api_client/models/validation_error.py | 2 +- .../golden-record/my_test_api_client/types.py | 6 +++--- 40 files changed, 63 insertions(+), 63 deletions(-) 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 49d7492f8..ab4057df2 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 @@ -222,7 +222,7 @@ def sync( nullable_model_prop: Union[Unset, None, ModelWithUnionProperty] = UNSET, nullable_required_model_prop: Optional[ModelWithUnionProperty], ) -> Optional[Union[Any, HTTPValidationError]]: - """ """ + """ """ return sync_detailed( client=client, @@ -315,7 +315,7 @@ async def asyncio( nullable_model_prop: Union[Unset, None, ModelWithUnionProperty] = UNSET, nullable_required_model_prop: Optional[ModelWithUnionProperty], ) -> Optional[Union[Any, HTTPValidationError]]: - """ """ + """ """ return ( await asyncio_detailed( 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 d025860ec..08c26dcdb 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 @@ -59,7 +59,7 @@ def sync( *, client: Client, ) -> Optional[List[bool]]: - """ Get a list of booleans """ + """Get a list of booleans""" return sync_detailed( client=client, @@ -84,7 +84,7 @@ async def asyncio( *, client: Client, ) -> Optional[List[bool]]: - """ Get a list of booleans """ + """Get a list of booleans""" return ( await asyncio_detailed( 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 e2199a3b9..4cd722164 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 @@ -59,7 +59,7 @@ def sync( *, client: Client, ) -> Optional[List[float]]: - """ Get a list of floats """ + """Get a list of floats""" return sync_detailed( client=client, @@ -84,7 +84,7 @@ async def asyncio( *, client: Client, ) -> Optional[List[float]]: - """ Get a list of floats """ + """Get a list of floats""" return ( await asyncio_detailed( 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 dc3c6af6a..badffd2a8 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 @@ -59,7 +59,7 @@ def sync( *, client: Client, ) -> Optional[List[int]]: - """ Get a list of integers """ + """Get a list of integers""" return sync_detailed( client=client, @@ -84,7 +84,7 @@ async def asyncio( *, client: Client, ) -> Optional[List[int]]: - """ Get a list of integers """ + """Get a list of integers""" return ( await asyncio_detailed( 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 150ab9a22..fa040b04b 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 @@ -59,7 +59,7 @@ def sync( *, client: Client, ) -> Optional[List[str]]: - """ Get a list of strings """ + """Get a list of strings""" return sync_detailed( client=client, @@ -84,7 +84,7 @@ async def asyncio( *, client: Client, ) -> Optional[List[str]]: - """ Get a list of strings """ + """Get a list of strings""" return ( await asyncio_detailed( 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 095f4be9d..96ca18884 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 @@ -102,7 +102,7 @@ def sync( an_enum_value: List[AnEnum], some_date: Union[datetime.date, datetime.datetime], ) -> Optional[Union[HTTPValidationError, List[AModel]]]: - """ Get a list of things """ + """Get a list of things""" return sync_detailed( client=client, @@ -135,7 +135,7 @@ async def asyncio( an_enum_value: List[AnEnum], some_date: Union[datetime.date, datetime.datetime], ) -> Optional[Union[HTTPValidationError, List[AModel]]]: - """ Get a list of things """ + """Get a list of things""" return ( await asyncio_detailed( 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 6b581b2c4..a1ab36a18 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 @@ -77,7 +77,7 @@ def sync( client: Client, int_enum: AnIntEnum, ) -> Optional[Union[Any, HTTPValidationError]]: - """ """ + """ """ return sync_detailed( client=client, @@ -106,7 +106,7 @@ async def asyncio( client: Client, int_enum: AnIntEnum, ) -> Optional[Union[Any, HTTPValidationError]]: - """ """ + """ """ return ( await asyncio_detailed( 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 ccfd7d619..748a89593 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 @@ -72,7 +72,7 @@ def sync( client: Client, json_body: AModel, ) -> Optional[Union[Any, HTTPValidationError]]: - """ Try sending a JSON body """ + """Try sending a JSON body""" return sync_detailed( client=client, @@ -101,7 +101,7 @@ async def asyncio( client: Client, json_body: AModel, ) -> Optional[Union[Any, HTTPValidationError]]: - """ Try sending a JSON body """ + """Try sending a JSON body""" return ( await asyncio_detailed( 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 fb81baafd..ba5a580e9 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 @@ -59,7 +59,7 @@ def sync( *, client: Client, ) -> Optional[Any]: - """ """ + """ """ return sync_detailed( client=client, @@ -84,7 +84,7 @@ async def asyncio( *, client: Client, ) -> Optional[Any]: - """ """ + """ """ return ( await asyncio_detailed( 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 b1e3a0cf7..f399df6b5 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 @@ -60,7 +60,7 @@ def sync( *, client: Client, ) -> Optional[File]: - """ """ + """ """ return sync_detailed( client=client, @@ -85,7 +85,7 @@ async def asyncio( *, client: Client, ) -> Optional[File]: - """ """ + """ """ return ( await asyncio_detailed( diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/tests/optional_value_tests_optional_query_param.py b/end_to_end_tests/golden-record/my_test_api_client/api/tests/optional_value_tests_optional_query_param.py index 5887f9429..57b6a7ccd 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/tests/optional_value_tests_optional_query_param.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/tests/optional_value_tests_optional_query_param.py @@ -78,7 +78,7 @@ def sync( client: Client, query_param: Union[Unset, List[str]] = UNSET, ) -> Optional[Union[Any, HTTPValidationError]]: - """ Test optional query parameters """ + """Test optional query parameters""" return sync_detailed( client=client, @@ -107,7 +107,7 @@ async def asyncio( client: Client, query_param: Union[Unset, List[str]] = UNSET, ) -> Optional[Union[Any, HTTPValidationError]]: - """ Test optional query parameters """ + """Test optional query parameters""" return ( await asyncio_detailed( 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 04fc372c4..59d12f3d6 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 @@ -68,7 +68,7 @@ def sync( client: Client, json_body: TestInlineObjectsJsonBody, ) -> Optional[TestInlineObjectsResponse200]: - """ """ + """ """ return sync_detailed( client=client, @@ -97,7 +97,7 @@ async def asyncio( client: Client, json_body: TestInlineObjectsJsonBody, ) -> Optional[TestInlineObjectsResponse200]: - """ """ + """ """ return ( await asyncio_detailed( 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 55ce6a120..10eaea4c1 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 @@ -69,7 +69,7 @@ def sync( client: Client, my_token: str, ) -> Optional[Union[Any, None]]: - """ Test optional cookie parameters """ + """Test optional cookie parameters""" return sync_detailed( client=client, @@ -98,7 +98,7 @@ async def asyncio( client: Client, my_token: str, ) -> Optional[Union[Any, None]]: - """ Test optional cookie parameters """ + """Test optional cookie parameters""" return ( await asyncio_detailed( 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 5e9193740..6d2a233fb 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 @@ -59,7 +59,7 @@ def sync( *, client: Client, ) -> Optional[Any]: - """ """ + """ """ return sync_detailed( client=client, @@ -84,7 +84,7 @@ async def asyncio( *, client: Client, ) -> Optional[Any]: - """ """ + """ """ return ( await asyncio_detailed( 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 9c6a8a460..7e789b6d6 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 @@ -86,7 +86,7 @@ def sync( multipart_data: BodyUploadFileTestsUploadPost, keep_alive: Union[Unset, bool] = UNSET, ) -> Optional[Union[Any, HTTPValidationError]]: - """ Upload a file """ + """Upload a file""" return sync_detailed( client=client, @@ -119,7 +119,7 @@ async def asyncio( multipart_data: BodyUploadFileTestsUploadPost, keep_alive: Union[Unset, bool] = UNSET, ) -> Optional[Union[Any, HTTPValidationError]]: - """ Upload a file """ + """Upload a file""" return ( await asyncio_detailed( diff --git a/end_to_end_tests/golden-record/my_test_api_client/client.py b/end_to_end_tests/golden-record/my_test_api_client/client.py index c3074040c..36fa529e0 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/client.py +++ b/end_to_end_tests/golden-record/my_test_api_client/client.py @@ -5,7 +5,7 @@ @attr.s(auto_attribs=True) class Client: - """ A class for keeping track of data related to the API """ + """A class for keeping track of data related to the API""" base_url: str cookies: Dict[str, str] = attr.ib(factory=dict, kw_only=True) @@ -13,34 +13,34 @@ class Client: timeout: float = attr.ib(5.0, kw_only=True) def get_headers(self) -> Dict[str, str]: - """ Get headers to be used in all endpoints """ + """Get headers to be used in all endpoints""" return {**self.headers} def with_headers(self, headers: Dict[str, str]) -> "Client": - """ Get a new client matching this one with additional headers """ + """Get a new client matching this one with additional headers""" return attr.evolve(self, headers={**self.headers, **headers}) def get_cookies(self) -> Dict[str, str]: return {**self.cookies} def with_cookies(self, cookies: Dict[str, str]) -> "Client": - """ Get a new client matching this one with additional cookies """ + """Get a new client matching this one with additional cookies""" return attr.evolve(self, cookies={**self.cookies, **cookies}) def get_timeout(self) -> float: return self.timeout def with_timeout(self, timeout: float) -> "Client": - """ Get a new client matching this one with a new timeout (in seconds) """ + """Get a new client matching this one with a new timeout (in seconds)""" return attr.evolve(self, timeout=timeout) @attr.s(auto_attribs=True) class AuthenticatedClient(Client): - """ A Client which has been authenticated for use on secured endpoints """ + """A Client which has been authenticated for use on secured endpoints""" token: str def get_headers(self) -> Dict[str, str]: - """ Get headers to be used in authenticated endpoints """ + """Get headers to be used in authenticated endpoints""" return {"Authorization": f"Bearer {self.token}", **self.headers} diff --git a/end_to_end_tests/golden-record/my_test_api_client/models/a_model.py b/end_to_end_tests/golden-record/my_test_api_client/models/a_model.py index c058bf291..38ce8d114 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/models/a_model.py +++ b/end_to_end_tests/golden-record/my_test_api_client/models/a_model.py @@ -16,7 +16,7 @@ @attr.s(auto_attribs=True) class AModel: - """ A Model for testing all the ways custom objects can be used """ + """A Model for testing all the ways custom objects can be used""" an_enum_value: AnEnum a_camel_date_time: Union[datetime.date, datetime.datetime] diff --git a/end_to_end_tests/golden-record/my_test_api_client/models/all_of_sub_model.py b/end_to_end_tests/golden-record/my_test_api_client/models/all_of_sub_model.py index baa59d06a..8945c70ab 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/models/all_of_sub_model.py +++ b/end_to_end_tests/golden-record/my_test_api_client/models/all_of_sub_model.py @@ -9,7 +9,7 @@ @attr.s(auto_attribs=True) class AllOfSubModel: - """ """ + """ """ a_sub_property: Union[Unset, str] = UNSET additional_properties: Dict[str, Any] = attr.ib(init=False, factory=dict) diff --git a/end_to_end_tests/golden-record/my_test_api_client/models/another_all_of_sub_model.py b/end_to_end_tests/golden-record/my_test_api_client/models/another_all_of_sub_model.py index 3949852c6..2ecc464a8 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/models/another_all_of_sub_model.py +++ b/end_to_end_tests/golden-record/my_test_api_client/models/another_all_of_sub_model.py @@ -9,7 +9,7 @@ @attr.s(auto_attribs=True) class AnotherAllOfSubModel: - """ """ + """ """ another_sub_property: Union[Unset, str] = UNSET additional_properties: Dict[str, Any] = attr.ib(init=False, factory=dict) diff --git a/end_to_end_tests/golden-record/my_test_api_client/models/body_upload_file_tests_upload_post.py b/end_to_end_tests/golden-record/my_test_api_client/models/body_upload_file_tests_upload_post.py index a250dbb37..d2d263353 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/models/body_upload_file_tests_upload_post.py +++ b/end_to_end_tests/golden-record/my_test_api_client/models/body_upload_file_tests_upload_post.py @@ -10,7 +10,7 @@ @attr.s(auto_attribs=True) class BodyUploadFileTestsUploadPost: - """ """ + """ """ some_file: File some_string: Union[Unset, str] = "some_default_string" diff --git a/end_to_end_tests/golden-record/my_test_api_client/models/free_form_model.py b/end_to_end_tests/golden-record/my_test_api_client/models/free_form_model.py index 1a86b6bac..f8cc2151c 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/models/free_form_model.py +++ b/end_to_end_tests/golden-record/my_test_api_client/models/free_form_model.py @@ -7,7 +7,7 @@ @attr.s(auto_attribs=True) class FreeFormModel: - """ """ + """ """ additional_properties: Dict[str, Any] = attr.ib(init=False, factory=dict) diff --git a/end_to_end_tests/golden-record/my_test_api_client/models/http_validation_error.py b/end_to_end_tests/golden-record/my_test_api_client/models/http_validation_error.py index feb2cdd6b..e777fcc87 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/models/http_validation_error.py +++ b/end_to_end_tests/golden-record/my_test_api_client/models/http_validation_error.py @@ -10,7 +10,7 @@ @attr.s(auto_attribs=True) class HTTPValidationError: - """ """ + """ """ detail: Union[Unset, List[ValidationError]] = UNSET diff --git a/end_to_end_tests/golden-record/my_test_api_client/models/model_from_all_of.py b/end_to_end_tests/golden-record/my_test_api_client/models/model_from_all_of.py index ce26a3bbb..60406f46d 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/models/model_from_all_of.py +++ b/end_to_end_tests/golden-record/my_test_api_client/models/model_from_all_of.py @@ -9,7 +9,7 @@ @attr.s(auto_attribs=True) class ModelFromAllOf: - """ """ + """ """ a_sub_property: Union[Unset, str] = UNSET another_sub_property: Union[Unset, str] = UNSET diff --git a/end_to_end_tests/golden-record/my_test_api_client/models/model_name.py b/end_to_end_tests/golden-record/my_test_api_client/models/model_name.py index 75b12f284..c87d4c208 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/models/model_name.py +++ b/end_to_end_tests/golden-record/my_test_api_client/models/model_name.py @@ -7,7 +7,7 @@ @attr.s(auto_attribs=True) class ModelName: - """ """ + """ """ additional_properties: Dict[str, Any] = attr.ib(init=False, factory=dict) diff --git a/end_to_end_tests/golden-record/my_test_api_client/models/model_with_additional_properties_inlined.py b/end_to_end_tests/golden-record/my_test_api_client/models/model_with_additional_properties_inlined.py index a81e57a8e..a2e168758 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/models/model_with_additional_properties_inlined.py +++ b/end_to_end_tests/golden-record/my_test_api_client/models/model_with_additional_properties_inlined.py @@ -12,7 +12,7 @@ @attr.s(auto_attribs=True) class ModelWithAdditionalPropertiesInlined: - """ """ + """ """ a_number: Union[Unset, float] = UNSET additional_properties: Dict[str, ModelWithAdditionalPropertiesInlinedAdditionalProperty] = attr.ib( diff --git a/end_to_end_tests/golden-record/my_test_api_client/models/model_with_additional_properties_inlined_additional_property.py b/end_to_end_tests/golden-record/my_test_api_client/models/model_with_additional_properties_inlined_additional_property.py index baedb6193..490f6e34c 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/models/model_with_additional_properties_inlined_additional_property.py +++ b/end_to_end_tests/golden-record/my_test_api_client/models/model_with_additional_properties_inlined_additional_property.py @@ -9,7 +9,7 @@ @attr.s(auto_attribs=True) class ModelWithAdditionalPropertiesInlinedAdditionalProperty: - """ """ + """ """ extra_props_prop: Union[Unset, str] = UNSET additional_properties: Dict[str, Any] = attr.ib(init=False, factory=dict) diff --git a/end_to_end_tests/golden-record/my_test_api_client/models/model_with_additional_properties_refed.py b/end_to_end_tests/golden-record/my_test_api_client/models/model_with_additional_properties_refed.py index b265db582..d51c5d72c 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/models/model_with_additional_properties_refed.py +++ b/end_to_end_tests/golden-record/my_test_api_client/models/model_with_additional_properties_refed.py @@ -9,7 +9,7 @@ @attr.s(auto_attribs=True) class ModelWithAdditionalPropertiesRefed: - """ """ + """ """ additional_properties: Dict[str, AnEnum] = attr.ib(init=False, factory=dict) diff --git a/end_to_end_tests/golden-record/my_test_api_client/models/model_with_any_json_properties.py b/end_to_end_tests/golden-record/my_test_api_client/models/model_with_any_json_properties.py index 9b22f9154..ecfa97b10 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/models/model_with_any_json_properties.py +++ b/end_to_end_tests/golden-record/my_test_api_client/models/model_with_any_json_properties.py @@ -11,7 +11,7 @@ @attr.s(auto_attribs=True) class ModelWithAnyJsonProperties: - """ """ + """ """ additional_properties: Dict[ str, Union[List[str], ModelWithAnyJsonPropertiesAdditionalPropertyType0, bool, float, int, str] diff --git a/end_to_end_tests/golden-record/my_test_api_client/models/model_with_any_json_properties_additional_property_type_0.py b/end_to_end_tests/golden-record/my_test_api_client/models/model_with_any_json_properties_additional_property_type_0.py index 5d271b266..19e863fc4 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/models/model_with_any_json_properties_additional_property_type_0.py +++ b/end_to_end_tests/golden-record/my_test_api_client/models/model_with_any_json_properties_additional_property_type_0.py @@ -7,7 +7,7 @@ @attr.s(auto_attribs=True) class ModelWithAnyJsonPropertiesAdditionalPropertyType0: - """ """ + """ """ additional_properties: Dict[str, str] = attr.ib(init=False, factory=dict) diff --git a/end_to_end_tests/golden-record/my_test_api_client/models/model_with_primitive_additional_properties.py b/end_to_end_tests/golden-record/my_test_api_client/models/model_with_primitive_additional_properties.py index 68e2238dd..5dc264152 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/models/model_with_primitive_additional_properties.py +++ b/end_to_end_tests/golden-record/my_test_api_client/models/model_with_primitive_additional_properties.py @@ -12,7 +12,7 @@ @attr.s(auto_attribs=True) class ModelWithPrimitiveAdditionalProperties: - """ """ + """ """ a_date_holder: Union[Unset, ModelWithPrimitiveAdditionalPropertiesADateHolder] = UNSET additional_properties: Dict[str, str] = attr.ib(init=False, factory=dict) diff --git a/end_to_end_tests/golden-record/my_test_api_client/models/model_with_primitive_additional_properties_a_date_holder.py b/end_to_end_tests/golden-record/my_test_api_client/models/model_with_primitive_additional_properties_a_date_holder.py index 3df34635f..aa8a25252 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/models/model_with_primitive_additional_properties_a_date_holder.py +++ b/end_to_end_tests/golden-record/my_test_api_client/models/model_with_primitive_additional_properties_a_date_holder.py @@ -9,7 +9,7 @@ @attr.s(auto_attribs=True) class ModelWithPrimitiveAdditionalPropertiesADateHolder: - """ """ + """ """ additional_properties: Dict[str, datetime.datetime] = attr.ib(init=False, factory=dict) diff --git a/end_to_end_tests/golden-record/my_test_api_client/models/model_with_property_ref.py b/end_to_end_tests/golden-record/my_test_api_client/models/model_with_property_ref.py index 1553914ba..6ebba75a6 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/models/model_with_property_ref.py +++ b/end_to_end_tests/golden-record/my_test_api_client/models/model_with_property_ref.py @@ -10,7 +10,7 @@ @attr.s(auto_attribs=True) class ModelWithPropertyRef: - """ """ + """ """ inner: Union[Unset, ModelName] = UNSET additional_properties: Dict[str, Any] = attr.ib(init=False, factory=dict) diff --git a/end_to_end_tests/golden-record/my_test_api_client/models/model_with_union_property.py b/end_to_end_tests/golden-record/my_test_api_client/models/model_with_union_property.py index 5981b8c74..87034d5e7 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/models/model_with_union_property.py +++ b/end_to_end_tests/golden-record/my_test_api_client/models/model_with_union_property.py @@ -11,7 +11,7 @@ @attr.s(auto_attribs=True) class ModelWithUnionProperty: - """ """ + """ """ a_property: Union[AnEnum, AnIntEnum, Unset] = UNSET diff --git a/end_to_end_tests/golden-record/my_test_api_client/models/model_with_union_property_inlined.py b/end_to_end_tests/golden-record/my_test_api_client/models/model_with_union_property_inlined.py index a9607f999..822f45cc2 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/models/model_with_union_property_inlined.py +++ b/end_to_end_tests/golden-record/my_test_api_client/models/model_with_union_property_inlined.py @@ -11,7 +11,7 @@ @attr.s(auto_attribs=True) class ModelWithUnionPropertyInlined: - """ """ + """ """ fruit: Union[ModelWithUnionPropertyInlinedFruitType0, ModelWithUnionPropertyInlinedFruitType1, Unset] = UNSET diff --git a/end_to_end_tests/golden-record/my_test_api_client/models/model_with_union_property_inlined_fruit_type_0.py b/end_to_end_tests/golden-record/my_test_api_client/models/model_with_union_property_inlined_fruit_type_0.py index 8a8739465..333d822c7 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/models/model_with_union_property_inlined_fruit_type_0.py +++ b/end_to_end_tests/golden-record/my_test_api_client/models/model_with_union_property_inlined_fruit_type_0.py @@ -9,7 +9,7 @@ @attr.s(auto_attribs=True) class ModelWithUnionPropertyInlinedFruitType0: - """ """ + """ """ apples: Union[Unset, str] = UNSET additional_properties: Dict[str, Any] = attr.ib(init=False, factory=dict) diff --git a/end_to_end_tests/golden-record/my_test_api_client/models/model_with_union_property_inlined_fruit_type_1.py b/end_to_end_tests/golden-record/my_test_api_client/models/model_with_union_property_inlined_fruit_type_1.py index 7b1792f5e..d2020747c 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/models/model_with_union_property_inlined_fruit_type_1.py +++ b/end_to_end_tests/golden-record/my_test_api_client/models/model_with_union_property_inlined_fruit_type_1.py @@ -9,7 +9,7 @@ @attr.s(auto_attribs=True) class ModelWithUnionPropertyInlinedFruitType1: - """ """ + """ """ bananas: Union[Unset, str] = UNSET additional_properties: Dict[str, Any] = attr.ib(init=False, factory=dict) diff --git a/end_to_end_tests/golden-record/my_test_api_client/models/test_inline_objects_json_body.py b/end_to_end_tests/golden-record/my_test_api_client/models/test_inline_objects_json_body.py index 1ee542873..e74ed557b 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/models/test_inline_objects_json_body.py +++ b/end_to_end_tests/golden-record/my_test_api_client/models/test_inline_objects_json_body.py @@ -9,7 +9,7 @@ @attr.s(auto_attribs=True) class TestInlineObjectsJsonBody: - """ """ + """ """ a_property: Union[Unset, str] = UNSET diff --git a/end_to_end_tests/golden-record/my_test_api_client/models/test_inline_objects_response_200.py b/end_to_end_tests/golden-record/my_test_api_client/models/test_inline_objects_response_200.py index 9b1a6fa58..7c6aa6fb2 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/models/test_inline_objects_response_200.py +++ b/end_to_end_tests/golden-record/my_test_api_client/models/test_inline_objects_response_200.py @@ -9,7 +9,7 @@ @attr.s(auto_attribs=True) class TestInlineObjectsResponse200: - """ """ + """ """ a_property: Union[Unset, str] = UNSET diff --git a/end_to_end_tests/golden-record/my_test_api_client/models/validation_error.py b/end_to_end_tests/golden-record/my_test_api_client/models/validation_error.py index a0cd07b51..8bbb20c76 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/models/validation_error.py +++ b/end_to_end_tests/golden-record/my_test_api_client/models/validation_error.py @@ -7,7 +7,7 @@ @attr.s(auto_attribs=True) class ValidationError: - """ """ + """ """ loc: List[str] msg: str 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 0739e2197..2b1cfc5b8 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 @@ -16,14 +16,14 @@ def __bool__(self) -> bool: @attr.s(auto_attribs=True) class File: - """ Contains information for file uploads """ + """Contains information for file uploads""" payload: Union[BinaryIO, TextIO] file_name: Optional[str] = None mime_type: Optional[str] = None def to_tuple(self) -> FileJsonType: - """ Return a tuple representation that httpx will accept for multipart/form-data """ + """Return a tuple representation that httpx will accept for multipart/form-data""" return self.file_name, self.payload, self.mime_type @@ -32,7 +32,7 @@ def to_tuple(self) -> FileJsonType: @attr.s(auto_attribs=True) class Response(Generic[T]): - """ A response from an endpoint """ + """A response from an endpoint""" status_code: int content: bytes From e087ff05e6d58f5c0a16f5a72cd4e01118ec54fe Mon Sep 17 00:00:00 2001 From: Forest Tong Date: Fri, 7 May 2021 14:05:02 -0400 Subject: [PATCH 3/6] Remove NoneProperty --- .../api/default/get_common_parameters.py | 46 +++++++++++++++-- .../api/default/post_common_parameters.py | 46 +++++++++++++++-- .../get_same_name_multiple_locations_param.py | 50 +++++++++++++++++-- ..._with_cookie_auth_token_with_cookie_get.py | 14 +++--- .../parser/properties/__init__.py | 10 ---- openapi_python_client/parser/responses.py | 6 +-- .../property_templates/none_property.py.jinja | 9 ---- tests/test_parser/test_responses.py | 6 +-- 8 files changed, 140 insertions(+), 47 deletions(-) delete mode 100644 openapi_python_client/templates/property_templates/none_property.py.jinja 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 158e04b1d..78b8d6abd 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,4 +1,4 @@ -from typing import Any, Dict, Union +from typing import Any, Dict, Optional, Union import httpx @@ -30,12 +30,20 @@ def _get_kwargs( } -def _build_response(*, response: httpx.Response) -> Response[None]: +def _parse_response(*, response: httpx.Response) -> Optional[Any]: + if response.status_code == 200: + response_200 = None + + return response_200 + return None + + +def _build_response(*, response: httpx.Response) -> Response[Any]: return Response( status_code=response.status_code, content=response.content, headers=response.headers, - parsed=None, + parsed=_parse_response(response=response), ) @@ -43,7 +51,7 @@ def sync_detailed( *, client: Client, common: Union[Unset, str] = UNSET, -) -> Response[None]: +) -> Response[Any]: kwargs = _get_kwargs( client=client, common=common, @@ -56,11 +64,24 @@ def sync_detailed( return _build_response(response=response) +def sync( + *, + client: Client, + common: Union[Unset, str] = UNSET, +) -> Optional[Any]: + """ """ + + return sync_detailed( + client=client, + common=common, + ).parsed + + async def asyncio_detailed( *, client: Client, common: Union[Unset, str] = UNSET, -) -> Response[None]: +) -> Response[Any]: kwargs = _get_kwargs( client=client, common=common, @@ -70,3 +91,18 @@ async def asyncio_detailed( response = await _client.get(**kwargs) return _build_response(response=response) + + +async def asyncio( + *, + client: Client, + common: Union[Unset, str] = UNSET, +) -> Optional[Any]: + """ """ + + return ( + await asyncio_detailed( + client=client, + common=common, + ) + ).parsed 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 bb2d0f395..7fb0f1f7c 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,4 +1,4 @@ -from typing import Any, Dict, Union +from typing import Any, Dict, Optional, Union import httpx @@ -30,12 +30,20 @@ def _get_kwargs( } -def _build_response(*, response: httpx.Response) -> Response[None]: +def _parse_response(*, response: httpx.Response) -> Optional[Any]: + if response.status_code == 200: + response_200 = None + + return response_200 + return None + + +def _build_response(*, response: httpx.Response) -> Response[Any]: return Response( status_code=response.status_code, content=response.content, headers=response.headers, - parsed=None, + parsed=_parse_response(response=response), ) @@ -43,7 +51,7 @@ def sync_detailed( *, client: Client, common: Union[Unset, str] = UNSET, -) -> Response[None]: +) -> Response[Any]: kwargs = _get_kwargs( client=client, common=common, @@ -56,11 +64,24 @@ def sync_detailed( return _build_response(response=response) +def sync( + *, + client: Client, + common: Union[Unset, str] = UNSET, +) -> Optional[Any]: + """ """ + + return sync_detailed( + client=client, + common=common, + ).parsed + + async def asyncio_detailed( *, client: Client, common: Union[Unset, str] = UNSET, -) -> Response[None]: +) -> Response[Any]: kwargs = _get_kwargs( client=client, common=common, @@ -70,3 +91,18 @@ async def asyncio_detailed( response = await _client.post(**kwargs) return _build_response(response=response) + + +async def asyncio( + *, + client: Client, + common: Union[Unset, str] = UNSET, +) -> Optional[Any]: + """ """ + + return ( + await asyncio_detailed( + client=client, + common=common, + ) + ).parsed 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 eeb4daff7..b833a4267 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,4 +1,4 @@ -from typing import Any, Dict, Union +from typing import Any, Dict, Optional, Union import httpx @@ -31,12 +31,20 @@ def _get_kwargs( } -def _build_response(*, response: httpx.Response) -> Response[None]: +def _parse_response(*, response: httpx.Response) -> Optional[Any]: + if response.status_code == 200: + response_200 = None + + return response_200 + return None + + +def _build_response(*, response: httpx.Response) -> Response[Any]: return Response( status_code=response.status_code, content=response.content, headers=response.headers, - parsed=None, + parsed=_parse_response(response=response), ) @@ -45,7 +53,7 @@ def sync_detailed( client: Client, param_path: Union[Unset, str] = UNSET, param_query: Union[Unset, str] = UNSET, -) -> Response[None]: +) -> Response[Any]: kwargs = _get_kwargs( client=client, param_path=param_path, @@ -59,12 +67,27 @@ def sync_detailed( return _build_response(response=response) +def sync( + *, + client: Client, + param_path: Union[Unset, str] = UNSET, + param_query: Union[Unset, str] = UNSET, +) -> Optional[Any]: + """ """ + + return sync_detailed( + client=client, + param_path=param_path, + param_query=param_query, + ).parsed + + async def asyncio_detailed( *, client: Client, param_path: Union[Unset, str] = UNSET, param_query: Union[Unset, str] = UNSET, -) -> Response[None]: +) -> Response[Any]: kwargs = _get_kwargs( client=client, param_path=param_path, @@ -75,3 +98,20 @@ async def asyncio_detailed( response = await _client.get(**kwargs) return _build_response(response=response) + + +async def asyncio( + *, + client: Client, + param_path: Union[Unset, str] = UNSET, + param_query: Union[Unset, str] = UNSET, +) -> Optional[Any]: + """ """ + + return ( + await asyncio_detailed( + client=client, + param_path=param_path, + param_query=param_query, + ) + ).parsed 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 10eaea4c1..c6cb1ed27 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,4 +1,4 @@ -from typing import Any, Dict, Optional, Union +from typing import Any, Dict, Optional import httpx @@ -26,7 +26,7 @@ def _get_kwargs( } -def _parse_response(*, response: httpx.Response) -> Optional[Union[Any, None]]: +def _parse_response(*, response: httpx.Response) -> Optional[Any]: if response.status_code == 200: response_200 = None @@ -38,7 +38,7 @@ def _parse_response(*, response: httpx.Response) -> Optional[Union[Any, None]]: return None -def _build_response(*, response: httpx.Response) -> Response[Union[Any, None]]: +def _build_response(*, response: httpx.Response) -> Response[Any]: return Response( status_code=response.status_code, content=response.content, @@ -51,7 +51,7 @@ def sync_detailed( *, client: Client, my_token: str, -) -> Response[Union[Any, None]]: +) -> Response[Any]: kwargs = _get_kwargs( client=client, my_token=my_token, @@ -68,7 +68,7 @@ def sync( *, client: Client, my_token: str, -) -> Optional[Union[Any, None]]: +) -> Optional[Any]: """Test optional cookie parameters""" return sync_detailed( @@ -81,7 +81,7 @@ async def asyncio_detailed( *, client: Client, my_token: str, -) -> Response[Union[Any, None]]: +) -> Response[Any]: kwargs = _get_kwargs( client=client, my_token=my_token, @@ -97,7 +97,7 @@ async def asyncio( *, client: Client, my_token: str, -) -> Optional[Union[Any, None]]: +) -> Optional[Any]: """Test optional cookie parameters""" return ( diff --git a/openapi_python_client/parser/properties/__init__.py b/openapi_python_client/parser/properties/__init__.py index 920963168..9e6842f97 100644 --- a/openapi_python_client/parser/properties/__init__.py +++ b/openapi_python_client/parser/properties/__init__.py @@ -3,7 +3,6 @@ "Class", "EnumProperty", "ModelProperty", - "NoneProperty", "Property", "Schemas", "build_schemas", @@ -26,15 +25,6 @@ from .schemas import Class, Schemas, parse_reference_path, update_schemas_with_data -@attr.s(auto_attribs=True, frozen=True) -class NoneProperty(Property): - """A property that is always None""" - - _type_string: ClassVar[str] = "None" - _json_type_string: ClassVar[str] = "None" - template: ClassVar[Optional[str]] = "none_property.py.jinja" - - @attr.s(auto_attribs=True, frozen=True) class AnyProperty(Property): """A property that can be any type (used for empty schemas)""" diff --git a/openapi_python_client/parser/responses.py b/openapi_python_client/parser/responses.py index ffa703d6f..cbda7a140 100644 --- a/openapi_python_client/parser/responses.py +++ b/openapi_python_client/parser/responses.py @@ -7,7 +7,7 @@ from .. import Config from .. import schema as oai from .errors import ParseError, PropertyError -from .properties import NoneProperty, Property, Schemas, property_from_data +from .properties import AnyProperty, Property, Schemas, property_from_data @attr.s(auto_attribs=True, frozen=True) @@ -28,10 +28,10 @@ class Response: def empty_response(status_code: int, response_name: str) -> Response: - """Return an empty response, for when no response type is defined""" + """Return an untyped response, for when no response type is defined""" return Response( status_code=status_code, - prop=NoneProperty( + prop=AnyProperty( name=response_name, default=None, nullable=False, diff --git a/openapi_python_client/templates/property_templates/none_property.py.jinja b/openapi_python_client/templates/property_templates/none_property.py.jinja deleted file mode 100644 index adc6b1524..000000000 --- a/openapi_python_client/templates/property_templates/none_property.py.jinja +++ /dev/null @@ -1,9 +0,0 @@ -{% macro construct(property, source, initial_value="None") %} -{{ property.python_name }} = {{ initial_value }} -{% endmacro %} - -{% macro check_type_for_construct(property, source) %}{{ source }} is None{% endmacro %} - -{% macro transform(property, source, destination, declare_type=True) %} -{{ destination }} = None -{% endmacro %} diff --git a/tests/test_parser/test_responses.py b/tests/test_parser/test_responses.py index 025172388..d262c8a0d 100644 --- a/tests/test_parser/test_responses.py +++ b/tests/test_parser/test_responses.py @@ -2,7 +2,7 @@ import openapi_python_client.schema as oai from openapi_python_client.parser.errors import ParseError, PropertyError -from openapi_python_client.parser.properties import NoneProperty, Schemas, StringProperty +from openapi_python_client.parser.properties import AnyProperty, Schemas, StringProperty MODULE_NAME = "openapi_python_client.parser.responses" @@ -20,7 +20,7 @@ def test_response_from_data_no_content(): assert response == Response( status_code=200, - prop=NoneProperty(name="response_200", default=None, nullable=False, required=True), + prop=AnyProperty(name="response_200", default=None, nullable=False, required=True), source="None", ) @@ -46,7 +46,7 @@ def test_response_from_data_no_content_schema(): assert response == Response( status_code=200, - prop=NoneProperty(name="response_200", default=None, nullable=False, required=True), + prop=AnyProperty(name="response_200", default=None, nullable=False, required=True), source="None", ) From 140bcb42f50699ecccf22c946529c61b3767109c Mon Sep 17 00:00:00 2001 From: Forest Tong Date: Fri, 7 May 2021 14:15:22 -0400 Subject: [PATCH 4/6] Add test case, change to check for Any instead of None --- .../api/default/get_common_parameters.py | 40 +---------------- .../api/default/post_common_parameters.py | 40 +---------------- .../get_same_name_multiple_locations_param.py | 44 +------------------ .../api/tests/defaults_tests_defaults_post.py | 2 +- .../api/tests/int_enum_tests_int_enum_post.py | 2 +- .../tests/json_body_tests_json_body_post.py | 2 +- .../no_response_tests_no_response_get.py | 36 +-------------- ...tional_value_tests_optional_query_param.py | 2 +- ..._with_cookie_auth_token_with_cookie_get.py | 44 +------------------ ...d_content_tests_unsupported_content_get.py | 36 +-------------- .../tests/upload_file_tests_upload_post.py | 2 +- .../my_test_api_client/models/a_model.py | 34 +++++++++++--- end_to_end_tests/openapi.json | 4 +- openapi_python_client/parser/openapi.py | 2 +- .../templates/endpoint_module.py.jinja | 2 +- .../property_templates/any_property.py.jinja | 4 +- 16 files changed, 51 insertions(+), 245 deletions(-) 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 78b8d6abd..96487587d 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,4 +1,4 @@ -from typing import Any, Dict, Optional, Union +from typing import Any, Dict, Union import httpx @@ -30,20 +30,12 @@ def _get_kwargs( } -def _parse_response(*, response: httpx.Response) -> Optional[Any]: - if response.status_code == 200: - response_200 = None - - return response_200 - return None - - def _build_response(*, response: httpx.Response) -> Response[Any]: return Response( status_code=response.status_code, content=response.content, headers=response.headers, - parsed=_parse_response(response=response), + parsed=None, ) @@ -64,19 +56,6 @@ def sync_detailed( return _build_response(response=response) -def sync( - *, - client: Client, - common: Union[Unset, str] = UNSET, -) -> Optional[Any]: - """ """ - - return sync_detailed( - client=client, - common=common, - ).parsed - - async def asyncio_detailed( *, client: Client, @@ -91,18 +70,3 @@ async def asyncio_detailed( response = await _client.get(**kwargs) return _build_response(response=response) - - -async def asyncio( - *, - client: Client, - common: Union[Unset, str] = UNSET, -) -> Optional[Any]: - """ """ - - return ( - await asyncio_detailed( - client=client, - common=common, - ) - ).parsed 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 7fb0f1f7c..3283f4830 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,4 +1,4 @@ -from typing import Any, Dict, Optional, Union +from typing import Any, Dict, Union import httpx @@ -30,20 +30,12 @@ def _get_kwargs( } -def _parse_response(*, response: httpx.Response) -> Optional[Any]: - if response.status_code == 200: - response_200 = None - - return response_200 - return None - - def _build_response(*, response: httpx.Response) -> Response[Any]: return Response( status_code=response.status_code, content=response.content, headers=response.headers, - parsed=_parse_response(response=response), + parsed=None, ) @@ -64,19 +56,6 @@ def sync_detailed( return _build_response(response=response) -def sync( - *, - client: Client, - common: Union[Unset, str] = UNSET, -) -> Optional[Any]: - """ """ - - return sync_detailed( - client=client, - common=common, - ).parsed - - async def asyncio_detailed( *, client: Client, @@ -91,18 +70,3 @@ async def asyncio_detailed( response = await _client.post(**kwargs) return _build_response(response=response) - - -async def asyncio( - *, - client: Client, - common: Union[Unset, str] = UNSET, -) -> Optional[Any]: - """ """ - - return ( - await asyncio_detailed( - client=client, - common=common, - ) - ).parsed 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 b833a4267..2013768aa 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,4 +1,4 @@ -from typing import Any, Dict, Optional, Union +from typing import Any, Dict, Union import httpx @@ -31,20 +31,12 @@ def _get_kwargs( } -def _parse_response(*, response: httpx.Response) -> Optional[Any]: - if response.status_code == 200: - response_200 = None - - return response_200 - return None - - def _build_response(*, response: httpx.Response) -> Response[Any]: return Response( status_code=response.status_code, content=response.content, headers=response.headers, - parsed=_parse_response(response=response), + parsed=None, ) @@ -67,21 +59,6 @@ def sync_detailed( return _build_response(response=response) -def sync( - *, - client: Client, - param_path: Union[Unset, str] = UNSET, - param_query: Union[Unset, str] = UNSET, -) -> Optional[Any]: - """ """ - - return sync_detailed( - client=client, - param_path=param_path, - param_query=param_query, - ).parsed - - async def asyncio_detailed( *, client: Client, @@ -98,20 +75,3 @@ async def asyncio_detailed( response = await _client.get(**kwargs) return _build_response(response=response) - - -async def asyncio( - *, - client: Client, - param_path: Union[Unset, str] = UNSET, - param_query: Union[Unset, str] = UNSET, -) -> Optional[Any]: - """ """ - - return ( - await asyncio_detailed( - client=client, - param_path=param_path, - param_query=param_query, - ) - ).parsed 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 ab4057df2..f22ec0153 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 @@ -133,7 +133,7 @@ def _get_kwargs( def _parse_response(*, response: httpx.Response) -> Optional[Union[Any, HTTPValidationError]]: if response.status_code == 200: - response_200 = None + response_200 = response.json() return response_200 if response.status_code == 422: 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 a1ab36a18..d295ddaab 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 @@ -36,7 +36,7 @@ def _get_kwargs( def _parse_response(*, response: httpx.Response) -> Optional[Union[Any, HTTPValidationError]]: if response.status_code == 200: - response_200 = None + response_200 = response.json() return response_200 if response.status_code == 422: 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 748a89593..eba1f9615 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 @@ -31,7 +31,7 @@ def _get_kwargs( def _parse_response(*, response: httpx.Response) -> Optional[Union[Any, HTTPValidationError]]: if response.status_code == 200: - response_200 = None + response_200 = response.json() return response_200 if response.status_code == 422: 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 ba5a580e9..9ba34b83b 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,4 +1,4 @@ -from typing import Any, Dict, Optional +from typing import Any, Dict import httpx @@ -23,20 +23,12 @@ def _get_kwargs( } -def _parse_response(*, response: httpx.Response) -> Optional[Any]: - if response.status_code == 200: - response_200 = None - - return response_200 - return None - - def _build_response(*, response: httpx.Response) -> Response[Any]: return Response( status_code=response.status_code, content=response.content, headers=response.headers, - parsed=_parse_response(response=response), + parsed=None, ) @@ -55,17 +47,6 @@ def sync_detailed( return _build_response(response=response) -def sync( - *, - client: Client, -) -> Optional[Any]: - """ """ - - return sync_detailed( - client=client, - ).parsed - - async def asyncio_detailed( *, client: Client, @@ -78,16 +59,3 @@ async def asyncio_detailed( response = await _client.get(**kwargs) return _build_response(response=response) - - -async def asyncio( - *, - client: Client, -) -> Optional[Any]: - """ """ - - return ( - await asyncio_detailed( - client=client, - ) - ).parsed diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/tests/optional_value_tests_optional_query_param.py b/end_to_end_tests/golden-record/my_test_api_client/api/tests/optional_value_tests_optional_query_param.py index 57b6a7ccd..370ba1d45 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/tests/optional_value_tests_optional_query_param.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/tests/optional_value_tests_optional_query_param.py @@ -37,7 +37,7 @@ def _get_kwargs( def _parse_response(*, response: httpx.Response) -> Optional[Union[Any, HTTPValidationError]]: if response.status_code == 200: - response_200 = None + response_200 = response.json() return response_200 if response.status_code == 422: 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 c6cb1ed27..90cf20b07 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,4 +1,4 @@ -from typing import Any, Dict, Optional +from typing import Any, Dict import httpx @@ -26,24 +26,12 @@ def _get_kwargs( } -def _parse_response(*, response: httpx.Response) -> Optional[Any]: - if response.status_code == 200: - response_200 = None - - return response_200 - if response.status_code == 401: - response_401 = None - - return response_401 - return None - - def _build_response(*, response: httpx.Response) -> Response[Any]: return Response( status_code=response.status_code, content=response.content, headers=response.headers, - parsed=_parse_response(response=response), + parsed=None, ) @@ -64,19 +52,6 @@ def sync_detailed( return _build_response(response=response) -def sync( - *, - client: Client, - my_token: str, -) -> Optional[Any]: - """Test optional cookie parameters""" - - return sync_detailed( - client=client, - my_token=my_token, - ).parsed - - async def asyncio_detailed( *, client: Client, @@ -91,18 +66,3 @@ async def asyncio_detailed( response = await _client.get(**kwargs) return _build_response(response=response) - - -async def asyncio( - *, - client: Client, - my_token: str, -) -> Optional[Any]: - """Test optional cookie parameters""" - - return ( - await asyncio_detailed( - client=client, - my_token=my_token, - ) - ).parsed 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 6d2a233fb..9c7776899 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,4 +1,4 @@ -from typing import Any, Dict, Optional +from typing import Any, Dict import httpx @@ -23,20 +23,12 @@ def _get_kwargs( } -def _parse_response(*, response: httpx.Response) -> Optional[Any]: - if response.status_code == 200: - response_200 = None - - return response_200 - return None - - def _build_response(*, response: httpx.Response) -> Response[Any]: return Response( status_code=response.status_code, content=response.content, headers=response.headers, - parsed=_parse_response(response=response), + parsed=None, ) @@ -55,17 +47,6 @@ def sync_detailed( return _build_response(response=response) -def sync( - *, - client: Client, -) -> Optional[Any]: - """ """ - - return sync_detailed( - client=client, - ).parsed - - async def asyncio_detailed( *, client: Client, @@ -78,16 +59,3 @@ async def asyncio_detailed( response = await _client.get(**kwargs) return _build_response(response=response) - - -async def asyncio( - *, - client: Client, -) -> Optional[Any]: - """ """ - - return ( - await asyncio_detailed( - client=client, - ) - ).parsed 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 7e789b6d6..b416e9209 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 @@ -42,7 +42,7 @@ def _get_kwargs( def _parse_response(*, response: httpx.Response) -> Optional[Union[Any, HTTPValidationError]]: if response.status_code == 200: - response_200 = None + response_200 = response.json() return response_200 if response.status_code == 422: diff --git a/end_to_end_tests/golden-record/my_test_api_client/models/a_model.py b/end_to_end_tests/golden-record/my_test_api_client/models/a_model.py index 38ce8d114..5b28aed46 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/models/a_model.py +++ b/end_to_end_tests/golden-record/my_test_api_client/models/a_model.py @@ -22,13 +22,14 @@ class AModel: a_camel_date_time: Union[datetime.date, datetime.datetime] a_date: datetime.date required_not_nullable: str - one_of_models: Union[FreeFormModel, ModelWithUnionProperty] + one_of_models: Union[Any, FreeFormModel, ModelWithUnionProperty] model: ModelWithUnionProperty a_nullable_date: Optional[datetime.date] required_nullable: Optional[str] nullable_one_of_models: Union[FreeFormModel, ModelWithUnionProperty, None] nullable_model: Optional[ModelWithUnionProperty] an_allof_enum_with_overridden_default: AnAllOfEnum = AnAllOfEnum.OVERRIDDEN_DEFAULT + any_value: Union[Unset, Any] = UNSET an_optional_allof_enum: Union[Unset, AnAllOfEnum] = UNSET nested_list_of_enums: Union[Unset, List[List[DifferentEnum]]] = UNSET a_not_required_date: Union[Unset, datetime.date] = UNSET @@ -56,11 +57,16 @@ def to_dict(self) -> Dict[str, Any]: if isinstance(self.one_of_models, FreeFormModel): one_of_models = self.one_of_models.to_dict() - else: + elif isinstance(self.one_of_models, ModelWithUnionProperty): one_of_models = self.one_of_models.to_dict() + else: + one_of_models = self.one_of_models + model = self.model.to_dict() + any_value = self.any_value + an_optional_allof_enum: Union[Unset, str] = UNSET if not isinstance(self.an_optional_allof_enum, Unset): an_optional_allof_enum = self.an_optional_allof_enum.value @@ -154,6 +160,8 @@ def to_dict(self) -> Dict[str, Any]: "nullable_model": nullable_model, } ) + if any_value is not UNSET: + field_dict["any_value"] = any_value if an_optional_allof_enum is not UNSET: field_dict["an_optional_allof_enum"] = an_optional_allof_enum if nested_list_of_enums is not UNSET: @@ -207,7 +215,7 @@ def _parse_a_camel_date_time(data: object) -> Union[datetime.date, datetime.date required_not_nullable = d.pop("required_not_nullable") - def _parse_one_of_models(data: object) -> Union[FreeFormModel, ModelWithUnionProperty]: + def _parse_one_of_models(data: object) -> Union[Any, FreeFormModel, ModelWithUnionProperty]: try: one_of_models_type_0: FreeFormModel if not isinstance(data, dict): @@ -217,17 +225,28 @@ def _parse_one_of_models(data: object) -> Union[FreeFormModel, ModelWithUnionPro return one_of_models_type_0 except: # noqa: E722 pass - if not isinstance(data, dict): + try: + one_of_models_type_1: ModelWithUnionProperty + if not isinstance(data, dict): + raise TypeError() + one_of_models_type_1 = ModelWithUnionProperty.from_dict(data) + + return one_of_models_type_1 + except: # noqa: E722 + pass + if not True: raise TypeError() - one_of_models_type_1: ModelWithUnionProperty - one_of_models_type_1 = ModelWithUnionProperty.from_dict(data) + one_of_models_type_2: Any + one_of_models_type_2 = data - return one_of_models_type_1 + return one_of_models_type_2 one_of_models = _parse_one_of_models(d.pop("one_of_models")) model = ModelWithUnionProperty.from_dict(d.pop("model")) + any_value = d.pop("any_value", UNSET) + an_optional_allof_enum: Union[Unset, AnAllOfEnum] = UNSET _an_optional_allof_enum = d.pop("an_optional_allof_enum", UNSET) if not isinstance(_an_optional_allof_enum, Unset): @@ -375,6 +394,7 @@ def _parse_not_required_nullable_one_of_models( required_not_nullable=required_not_nullable, one_of_models=one_of_models, model=model, + any_value=any_value, an_optional_allof_enum=an_optional_allof_enum, nested_list_of_enums=nested_list_of_enums, a_nullable_date=a_nullable_date, diff --git a/end_to_end_tests/openapi.json b/end_to_end_tests/openapi.json index 585b97cde..1a460a778 100644 --- a/end_to_end_tests/openapi.json +++ b/end_to_end_tests/openapi.json @@ -808,6 +808,7 @@ ], "type": "object", "properties": { + "any_value": {}, "an_enum_value": { "$ref": "#/components/schemas/AnEnum" }, @@ -897,7 +898,8 @@ }, { "ref": "#/components/schemas/ModelWithUnionProperty" - } + }, + {} ], "nullable": false }, diff --git a/openapi_python_client/parser/openapi.py b/openapi_python_client/parser/openapi.py index ca8793d09..b5540a783 100644 --- a/openapi_python_client/parser/openapi.py +++ b/openapi_python_client/parser/openapi.py @@ -292,7 +292,7 @@ def response_type(self) -> str: """Get the Python type of any response from this endpoint""" types = sorted({response.prop.get_type_string() for response in self.responses}) if len(types) == 0: - return "None" + return "Any" if len(types) == 1: return self.responses[0].prop.get_type_string() return f"Union[{', '.join(types)}]" diff --git a/openapi_python_client/templates/endpoint_module.py.jinja b/openapi_python_client/templates/endpoint_module.py.jinja index 06876141a..57b9cda70 100644 --- a/openapi_python_client/templates/endpoint_module.py.jinja +++ b/openapi_python_client/templates/endpoint_module.py.jinja @@ -13,7 +13,7 @@ from ...types import Response, UNSET{% if endpoint.multipart_body_class %}, File {% from "endpoint_macros.py.jinja" import header_params, cookie_params, query_params, json_body, arguments, client, kwargs, parse_response %} {% set return_string = endpoint.response_type() %} -{% set parsed_responses = (endpoint.responses | length > 0) and return_string != "None" %} +{% set parsed_responses = (endpoint.responses | length > 0) and return_string != "Any" %} def _get_kwargs( {{ arguments(endpoint) | indent(4) }} diff --git a/openapi_python_client/templates/property_templates/any_property.py.jinja b/openapi_python_client/templates/property_templates/any_property.py.jinja index bdcdc72c4..9ead50a16 100644 --- a/openapi_python_client/templates/property_templates/any_property.py.jinja +++ b/openapi_python_client/templates/property_templates/any_property.py.jinja @@ -1,9 +1,9 @@ {% macro construct(property, source, initial_value="None") %} -{{ property.python_name }} = {{ initial_value }} +{{ property.python_name }} = {{ source }} {% endmacro %} {% macro check_type_for_construct(property, source) %}True{% endmacro %} {% macro transform(property, source, destination, declare_type=True) %} -{{ destination }} = source +{{ destination }} = {{ source }} {% endmacro %} From 68a61b82d6f2f91267587243dfdbc46047b08280 Mon Sep 17 00:00:00 2001 From: Forest Tong Date: Fri, 7 May 2021 14:21:12 -0400 Subject: [PATCH 5/6] Fix test --- tests/test_parser/test_openapi.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_parser/test_openapi.py b/tests/test_parser/test_openapi.py index c496b7dc2..fe458d6bc 100644 --- a/tests/test_parser/test_openapi.py +++ b/tests/test_parser/test_openapi.py @@ -789,7 +789,7 @@ def test_from_data_no_security(self, mocker): @pytest.mark.parametrize( "response_types, expected", - (([], "None"), (["Something"], "Something"), (["First", "Second", "Second"], "Union[First, Second]")), + (([], "Any"), (["Something"], "Something"), (["First", "Second", "Second"], "Union[First, Second]")), ) def test_response_type(self, response_types, expected): endpoint = self.make_endpoint() From 6c38462fa9c4b88ee2ef1f2627b51913cdeff12d Mon Sep 17 00:00:00 2001 From: Dylan Anthony Date: Fri, 2 Jul 2021 10:40:01 -0600 Subject: [PATCH 6/6] fix: Remove need for unnecessary `if True` when constructing unions of Any properties. --- .../my_test_api_client/models/a_model.py | 2 -- .../property_templates/any_property.py.jinja | 2 -- .../union_property.py.jinja | 20 +++++++++---------- 3 files changed, 9 insertions(+), 15 deletions(-) diff --git a/end_to_end_tests/golden-record/my_test_api_client/models/a_model.py b/end_to_end_tests/golden-record/my_test_api_client/models/a_model.py index 2d65005c4..a7a68874a 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/models/a_model.py +++ b/end_to_end_tests/golden-record/my_test_api_client/models/a_model.py @@ -230,8 +230,6 @@ def _parse_one_of_models(data: object) -> Union[Any, FreeFormModel, ModelWithUni return one_of_models_type_1 except: # noqa: E722 pass - if not True: - raise TypeError() one_of_models_type_2 = data return one_of_models_type_2 diff --git a/openapi_python_client/templates/property_templates/any_property.py.jinja b/openapi_python_client/templates/property_templates/any_property.py.jinja index c6d08584b..18ccda75a 100644 --- a/openapi_python_client/templates/property_templates/any_property.py.jinja +++ b/openapi_python_client/templates/property_templates/any_property.py.jinja @@ -2,8 +2,6 @@ {{ property.python_name }} = {{ source }} {% endmacro %} -{% macro check_type_for_construct(property, source) %}True{% endmacro %} - {% macro transform(property, source, destination, declare_type=True, stringify=False) %} {{ destination }} = {{ source }} {% endmacro %} diff --git a/openapi_python_client/templates/property_templates/union_property.py.jinja b/openapi_python_client/templates/property_templates/union_property.py.jinja index ce988a913..859207dda 100644 --- a/openapi_python_client/templates/property_templates/union_property.py.jinja +++ b/openapi_python_client/templates/property_templates/union_property.py.jinja @@ -9,20 +9,21 @@ def _parse_{{ property.python_name }}(data: object) -> {{ property.get_type_stri return data {% endif %} {% for inner_property in property.inner_properties_with_template() %} - {% if not loop.last or property.has_properties_without_templates %} + {% import "property_templates/" + inner_property.template as inner_template %} + {% if inner_template.check_type_for_construct and (not loop.last or property.has_properties_without_templates) %} try: - {% from "property_templates/" + inner_property.template import construct, check_type_for_construct %} - if not {{ check_type_for_construct(inner_property, "data") }}: + if not {{ inner_template.check_type_for_construct(inner_property, "data") }}: raise TypeError() - {{ construct(inner_property, "data", initial_value="UNSET") | indent(8) }} + {{ inner_template.construct(inner_property, "data", initial_value="UNSET") | indent(8) }} return {{ inner_property.python_name }} except: # noqa: E722 pass - {% else %}{# Don't do try/except for the last one #} - {% from "property_templates/" + inner_property.template import construct, check_type_for_construct %} - if not {{ check_type_for_construct(inner_property, "data") }}: + {% else %}{# Don't do try/except for the last one nor any properties with no type checking #} + {% if inner_template.check_type_for_construct %} + if not {{ inner_template.check_type_for_construct(inner_property, "data") }}: raise TypeError() - {{ construct(inner_property, "data", initial_value="UNSET") | indent(4) }} + {% endif %} + {{ inner_template.construct(inner_property, "data", initial_value="UNSET") | indent(4) }} return {{ inner_property.python_name }} {% endif %} {% endfor %} @@ -34,9 +35,6 @@ def _parse_{{ property.python_name }}(data: object) -> {{ property.get_type_stri {{ property.python_name }} = _parse_{{ property.python_name }}({{ source }}) {% endmacro %} -{# For now we assume there will be no unions of unions #} -{% macro check_type_for_construct(property, source) %}True{% endmacro %} - {% macro transform(property, source, destination, declare_type=True, stringify=False) %} {% if not property.required or property.nullable %} {{ destination }}{% if declare_type %}: {{ property.get_type_string(json=True) }}{% endif %}