From 9df04c9a183dec5c0643d391ea61bc2560632fc4 Mon Sep 17 00:00:00 2001 From: Robert Schweizer Date: Fri, 24 Mar 2023 17:35:19 +0100 Subject: [PATCH 1/6] fix: Make empty response a `NoneProperty` We know the type of this: It's `None`, so we don't need to annotate it as `Any`. --- .../api/default/get_common_parameters.py | 12 +-- .../api/default/post_common_parameters.py | 12 +-- .../api/location/get_location_header_types.py | 12 +-- .../get_location_query_optionality.py | 12 +-- .../get_parameter_references_path_param.py | 12 +-- ...lete_common_parameters_overriding_param.py | 12 +-- .../get_common_parameters_overriding_param.py | 12 +-- .../get_same_name_multiple_locations_param.py | 12 +-- .../parameters/multiple_path_parameters.py | 12 +-- .../api/tag1/get_tag_with_number.py | 12 +-- .../api/tests/description_with_backslash.py | 12 +-- ..._with_cookie_auth_token_with_cookie_get.py | 74 ++++++++++++++++--- .../my_test_api_client/api/true_/false_.py | 12 +-- openapi_python_client/parser/responses.py | 4 +- .../templates/endpoint_module.py.jinja | 2 +- tests/test_parser/test_responses.py | 12 +-- 16 files changed, 146 insertions(+), 90 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 a2478b80d..7312769bc 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 @@ -34,7 +34,7 @@ def _get_kwargs( } -def _parse_response(*, client: Client, response: httpx.Response) -> Optional[Any]: +def _parse_response(*, client: Client, response: httpx.Response) -> Optional[None]: if response.status_code == HTTPStatus.OK: return None if client.raise_on_unexpected_status: @@ -43,7 +43,7 @@ def _parse_response(*, client: Client, response: httpx.Response) -> Optional[Any return None -def _build_response(*, client: Client, response: httpx.Response) -> Response[Any]: +def _build_response(*, client: Client, response: httpx.Response) -> Response[None]: return Response( status_code=HTTPStatus(response.status_code), content=response.content, @@ -56,7 +56,7 @@ def sync_detailed( *, client: Client, common: Union[Unset, None, str] = UNSET, -) -> Response[Any]: +) -> Response[None]: """ Args: common (Union[Unset, None, str]): @@ -66,7 +66,7 @@ def sync_detailed( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[Any] + Response[None] """ kwargs = _get_kwargs( @@ -86,7 +86,7 @@ async def asyncio_detailed( *, client: Client, common: Union[Unset, None, str] = UNSET, -) -> Response[Any]: +) -> Response[None]: """ Args: common (Union[Unset, None, str]): @@ -96,7 +96,7 @@ async def asyncio_detailed( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[Any] + Response[None] """ kwargs = _get_kwargs( 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 99e7f21d7..0cd09545c 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 @@ -34,7 +34,7 @@ def _get_kwargs( } -def _parse_response(*, client: Client, response: httpx.Response) -> Optional[Any]: +def _parse_response(*, client: Client, response: httpx.Response) -> Optional[None]: if response.status_code == HTTPStatus.OK: return None if client.raise_on_unexpected_status: @@ -43,7 +43,7 @@ def _parse_response(*, client: Client, response: httpx.Response) -> Optional[Any return None -def _build_response(*, client: Client, response: httpx.Response) -> Response[Any]: +def _build_response(*, client: Client, response: httpx.Response) -> Response[None]: return Response( status_code=HTTPStatus(response.status_code), content=response.content, @@ -56,7 +56,7 @@ def sync_detailed( *, client: Client, common: Union[Unset, None, str] = UNSET, -) -> Response[Any]: +) -> Response[None]: """ Args: common (Union[Unset, None, str]): @@ -66,7 +66,7 @@ def sync_detailed( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[Any] + Response[None] """ kwargs = _get_kwargs( @@ -86,7 +86,7 @@ async def asyncio_detailed( *, client: Client, common: Union[Unset, None, str] = UNSET, -) -> Response[Any]: +) -> Response[None]: """ Args: common (Union[Unset, None, str]): @@ -96,7 +96,7 @@ async def asyncio_detailed( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[Any] + Response[None] """ kwargs = _get_kwargs( diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/location/get_location_header_types.py b/end_to_end_tests/golden-record/my_test_api_client/api/location/get_location_header_types.py index 9249eab31..bd27b3005 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/location/get_location_header_types.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/location/get_location_header_types.py @@ -53,7 +53,7 @@ def _get_kwargs( } -def _parse_response(*, client: Client, response: httpx.Response) -> Optional[Any]: +def _parse_response(*, client: Client, response: httpx.Response) -> Optional[None]: if response.status_code == HTTPStatus.OK: return None if client.raise_on_unexpected_status: @@ -62,7 +62,7 @@ def _parse_response(*, client: Client, response: httpx.Response) -> Optional[Any return None -def _build_response(*, client: Client, response: httpx.Response) -> Response[Any]: +def _build_response(*, client: Client, response: httpx.Response) -> Response[None]: return Response( status_code=HTTPStatus(response.status_code), content=response.content, @@ -80,7 +80,7 @@ def sync_detailed( integer_header: Union[Unset, int] = UNSET, int_enum_header: Union[Unset, GetLocationHeaderTypesIntEnumHeader] = UNSET, string_enum_header: Union[Unset, GetLocationHeaderTypesStringEnumHeader] = UNSET, -) -> Response[Any]: +) -> Response[None]: """ Args: boolean_header (Union[Unset, bool]): @@ -95,7 +95,7 @@ def sync_detailed( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[Any] + Response[None] """ kwargs = _get_kwargs( @@ -125,7 +125,7 @@ async def asyncio_detailed( integer_header: Union[Unset, int] = UNSET, int_enum_header: Union[Unset, GetLocationHeaderTypesIntEnumHeader] = UNSET, string_enum_header: Union[Unset, GetLocationHeaderTypesStringEnumHeader] = UNSET, -) -> Response[Any]: +) -> Response[None]: """ Args: boolean_header (Union[Unset, bool]): @@ -140,7 +140,7 @@ async def asyncio_detailed( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[Any] + Response[None] """ kwargs = _get_kwargs( diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/location/get_location_query_optionality.py b/end_to_end_tests/golden-record/my_test_api_client/api/location/get_location_query_optionality.py index 0209c7319..1681aa7be 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/location/get_location_query_optionality.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/location/get_location_query_optionality.py @@ -58,7 +58,7 @@ def _get_kwargs( } -def _parse_response(*, client: Client, response: httpx.Response) -> Optional[Any]: +def _parse_response(*, client: Client, response: httpx.Response) -> Optional[None]: if response.status_code == HTTPStatus.OK: return None if client.raise_on_unexpected_status: @@ -67,7 +67,7 @@ def _parse_response(*, client: Client, response: httpx.Response) -> Optional[Any return None -def _build_response(*, client: Client, response: httpx.Response) -> Response[Any]: +def _build_response(*, client: Client, response: httpx.Response) -> Response[None]: return Response( status_code=HTTPStatus(response.status_code), content=response.content, @@ -83,7 +83,7 @@ def sync_detailed( null_required: Union[Unset, None, datetime.datetime] = UNSET, null_not_required: Union[Unset, None, datetime.datetime] = UNSET, not_null_not_required: Union[Unset, None, datetime.datetime] = UNSET, -) -> Response[Any]: +) -> Response[None]: """ Args: not_null_required (datetime.datetime): @@ -96,7 +96,7 @@ def sync_detailed( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[Any] + Response[None] """ kwargs = _get_kwargs( @@ -122,7 +122,7 @@ async def asyncio_detailed( null_required: Union[Unset, None, datetime.datetime] = UNSET, null_not_required: Union[Unset, None, datetime.datetime] = UNSET, not_null_not_required: Union[Unset, None, datetime.datetime] = UNSET, -) -> Response[Any]: +) -> Response[None]: """ Args: not_null_required (datetime.datetime): @@ -135,7 +135,7 @@ async def asyncio_detailed( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[Any] + Response[None] """ kwargs = _get_kwargs( diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/parameter_references/get_parameter_references_path_param.py b/end_to_end_tests/golden-record/my_test_api_client/api/parameter_references/get_parameter_references_path_param.py index b8c33ec94..0d1df91ce 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/parameter_references/get_parameter_references_path_param.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/parameter_references/get_parameter_references_path_param.py @@ -46,7 +46,7 @@ def _get_kwargs( } -def _parse_response(*, client: Client, response: httpx.Response) -> Optional[Any]: +def _parse_response(*, client: Client, response: httpx.Response) -> Optional[None]: if response.status_code == HTTPStatus.OK: return None if client.raise_on_unexpected_status: @@ -55,7 +55,7 @@ def _parse_response(*, client: Client, response: httpx.Response) -> Optional[Any return None -def _build_response(*, client: Client, response: httpx.Response) -> Response[Any]: +def _build_response(*, client: Client, response: httpx.Response) -> Response[None]: return Response( status_code=HTTPStatus(response.status_code), content=response.content, @@ -72,7 +72,7 @@ def sync_detailed( integer_param: Union[Unset, None, int] = 0, header_param: Union[Unset, str] = UNSET, cookie_param: Union[Unset, str] = UNSET, -) -> Response[Any]: +) -> Response[None]: """Test different types of parameter references Args: @@ -87,7 +87,7 @@ def sync_detailed( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[Any] + Response[None] """ kwargs = _get_kwargs( @@ -115,7 +115,7 @@ async def asyncio_detailed( integer_param: Union[Unset, None, int] = 0, header_param: Union[Unset, str] = UNSET, cookie_param: Union[Unset, str] = UNSET, -) -> Response[Any]: +) -> Response[None]: """Test different types of parameter references Args: @@ -130,7 +130,7 @@ async def asyncio_detailed( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[Any] + Response[None] """ kwargs = _get_kwargs( diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/parameters/delete_common_parameters_overriding_param.py b/end_to_end_tests/golden-record/my_test_api_client/api/parameters/delete_common_parameters_overriding_param.py index 2816ec304..633c8050e 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/parameters/delete_common_parameters_overriding_param.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/parameters/delete_common_parameters_overriding_param.py @@ -35,7 +35,7 @@ def _get_kwargs( } -def _parse_response(*, client: Client, response: httpx.Response) -> Optional[Any]: +def _parse_response(*, client: Client, response: httpx.Response) -> Optional[None]: if response.status_code == HTTPStatus.OK: return None if client.raise_on_unexpected_status: @@ -44,7 +44,7 @@ def _parse_response(*, client: Client, response: httpx.Response) -> Optional[Any return None -def _build_response(*, client: Client, response: httpx.Response) -> Response[Any]: +def _build_response(*, client: Client, response: httpx.Response) -> Response[None]: return Response( status_code=HTTPStatus(response.status_code), content=response.content, @@ -58,7 +58,7 @@ def sync_detailed( *, client: Client, param_query: Union[Unset, None, str] = UNSET, -) -> Response[Any]: +) -> Response[None]: """ Args: param_path (str): @@ -69,7 +69,7 @@ def sync_detailed( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[Any] + Response[None] """ kwargs = _get_kwargs( @@ -91,7 +91,7 @@ async def asyncio_detailed( *, client: Client, param_query: Union[Unset, None, str] = UNSET, -) -> Response[Any]: +) -> Response[None]: """ Args: param_path (str): @@ -102,7 +102,7 @@ async def asyncio_detailed( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[Any] + Response[None] """ kwargs = _get_kwargs( diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/parameters/get_common_parameters_overriding_param.py b/end_to_end_tests/golden-record/my_test_api_client/api/parameters/get_common_parameters_overriding_param.py index f1d97abc5..3f9d25e7d 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/parameters/get_common_parameters_overriding_param.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/parameters/get_common_parameters_overriding_param.py @@ -35,7 +35,7 @@ def _get_kwargs( } -def _parse_response(*, client: Client, response: httpx.Response) -> Optional[Any]: +def _parse_response(*, client: Client, response: httpx.Response) -> Optional[None]: if response.status_code == HTTPStatus.OK: return None if client.raise_on_unexpected_status: @@ -44,7 +44,7 @@ def _parse_response(*, client: Client, response: httpx.Response) -> Optional[Any return None -def _build_response(*, client: Client, response: httpx.Response) -> Response[Any]: +def _build_response(*, client: Client, response: httpx.Response) -> Response[None]: return Response( status_code=HTTPStatus(response.status_code), content=response.content, @@ -58,7 +58,7 @@ def sync_detailed( *, client: Client, param_query: str = "overridden_in_GET", -) -> Response[Any]: +) -> Response[None]: """Test that if you have an overriding property from `PathItem` in `Operation`, it produces valid code Args: @@ -71,7 +71,7 @@ def sync_detailed( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[Any] + Response[None] """ kwargs = _get_kwargs( @@ -93,7 +93,7 @@ async def asyncio_detailed( *, client: Client, param_query: str = "overridden_in_GET", -) -> Response[Any]: +) -> Response[None]: """Test that if you have an overriding property from `PathItem` in `Operation`, it produces valid code Args: @@ -106,7 +106,7 @@ async def asyncio_detailed( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[Any] + Response[None] """ kwargs = _get_kwargs( 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 ee9c35016..48ab09277 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 @@ -43,7 +43,7 @@ def _get_kwargs( } -def _parse_response(*, client: Client, response: httpx.Response) -> Optional[Any]: +def _parse_response(*, client: Client, response: httpx.Response) -> Optional[None]: if response.status_code == HTTPStatus.OK: return None if client.raise_on_unexpected_status: @@ -52,7 +52,7 @@ def _parse_response(*, client: Client, response: httpx.Response) -> Optional[Any return None -def _build_response(*, client: Client, response: httpx.Response) -> Response[Any]: +def _build_response(*, client: Client, response: httpx.Response) -> Response[None]: return Response( status_code=HTTPStatus(response.status_code), content=response.content, @@ -68,7 +68,7 @@ def sync_detailed( param_query: Union[Unset, None, str] = UNSET, param_header: Union[Unset, str] = UNSET, param_cookie: Union[Unset, str] = UNSET, -) -> Response[Any]: +) -> Response[None]: """ Args: param_path (str): @@ -81,7 +81,7 @@ def sync_detailed( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[Any] + Response[None] """ kwargs = _get_kwargs( @@ -107,7 +107,7 @@ async def asyncio_detailed( param_query: Union[Unset, None, str] = UNSET, param_header: Union[Unset, str] = UNSET, param_cookie: Union[Unset, str] = UNSET, -) -> Response[Any]: +) -> Response[None]: """ Args: param_path (str): @@ -120,7 +120,7 @@ async def asyncio_detailed( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[Any] + Response[None] """ kwargs = _get_kwargs( diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/parameters/multiple_path_parameters.py b/end_to_end_tests/golden-record/my_test_api_client/api/parameters/multiple_path_parameters.py index 347aa36b4..583cfa89c 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/parameters/multiple_path_parameters.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/parameters/multiple_path_parameters.py @@ -33,7 +33,7 @@ def _get_kwargs( } -def _parse_response(*, client: Client, response: httpx.Response) -> Optional[Any]: +def _parse_response(*, client: Client, response: httpx.Response) -> Optional[None]: if response.status_code == HTTPStatus.OK: return None if client.raise_on_unexpected_status: @@ -42,7 +42,7 @@ def _parse_response(*, client: Client, response: httpx.Response) -> Optional[Any return None -def _build_response(*, client: Client, response: httpx.Response) -> Response[Any]: +def _build_response(*, client: Client, response: httpx.Response) -> Response[None]: return Response( status_code=HTTPStatus(response.status_code), content=response.content, @@ -58,7 +58,7 @@ def sync_detailed( param3: int, *, client: Client, -) -> Response[Any]: +) -> Response[None]: """ Args: param4 (str): @@ -71,7 +71,7 @@ def sync_detailed( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[Any] + Response[None] """ kwargs = _get_kwargs( @@ -97,7 +97,7 @@ async def asyncio_detailed( param3: int, *, client: Client, -) -> Response[Any]: +) -> Response[None]: """ Args: param4 (str): @@ -110,7 +110,7 @@ async def asyncio_detailed( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[Any] + Response[None] """ kwargs = _get_kwargs( diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/tag1/get_tag_with_number.py b/end_to_end_tests/golden-record/my_test_api_client/api/tag1/get_tag_with_number.py index 05f976082..47cce69ff 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/tag1/get_tag_with_number.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/tag1/get_tag_with_number.py @@ -27,7 +27,7 @@ def _get_kwargs( } -def _parse_response(*, client: Client, response: httpx.Response) -> Optional[Any]: +def _parse_response(*, client: Client, response: httpx.Response) -> Optional[None]: if response.status_code == HTTPStatus.OK: return None if client.raise_on_unexpected_status: @@ -36,7 +36,7 @@ def _parse_response(*, client: Client, response: httpx.Response) -> Optional[Any return None -def _build_response(*, client: Client, response: httpx.Response) -> Response[Any]: +def _build_response(*, client: Client, response: httpx.Response) -> Response[None]: return Response( status_code=HTTPStatus(response.status_code), content=response.content, @@ -48,14 +48,14 @@ def _build_response(*, client: Client, response: httpx.Response) -> Response[Any def sync_detailed( *, client: Client, -) -> Response[Any]: +) -> Response[None]: """ Raises: errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[Any] + Response[None] """ kwargs = _get_kwargs( @@ -73,14 +73,14 @@ def sync_detailed( async def asyncio_detailed( *, client: Client, -) -> Response[Any]: +) -> Response[None]: """ Raises: errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[Any] + Response[None] """ kwargs = _get_kwargs( diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/tests/description_with_backslash.py b/end_to_end_tests/golden-record/my_test_api_client/api/tests/description_with_backslash.py index 31923ad11..a650433d9 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/tests/description_with_backslash.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/tests/description_with_backslash.py @@ -27,7 +27,7 @@ def _get_kwargs( } -def _parse_response(*, client: Client, response: httpx.Response) -> Optional[Any]: +def _parse_response(*, client: Client, response: httpx.Response) -> Optional[None]: if response.status_code == HTTPStatus.OK: return None if client.raise_on_unexpected_status: @@ -36,7 +36,7 @@ def _parse_response(*, client: Client, response: httpx.Response) -> Optional[Any return None -def _build_response(*, client: Client, response: httpx.Response) -> Response[Any]: +def _build_response(*, client: Client, response: httpx.Response) -> Response[None]: return Response( status_code=HTTPStatus(response.status_code), content=response.content, @@ -48,7 +48,7 @@ def _build_response(*, client: Client, response: httpx.Response) -> Response[Any def sync_detailed( *, client: Client, -) -> Response[Any]: +) -> Response[None]: r""" Test description with \ Test description with \ @@ -58,7 +58,7 @@ def sync_detailed( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[Any] + Response[None] """ kwargs = _get_kwargs( @@ -76,7 +76,7 @@ def sync_detailed( async def asyncio_detailed( *, client: Client, -) -> Response[Any]: +) -> Response[None]: r""" Test description with \ Test description with \ @@ -86,7 +86,7 @@ async def asyncio_detailed( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[Any] + Response[None] """ kwargs = _get_kwargs( 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 994f1ee4e..a195cce0b 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,5 +1,5 @@ from http import HTTPStatus -from typing import Any, Dict, Optional +from typing import Any, Dict, Optional, Union, cast import httpx @@ -30,18 +30,20 @@ def _get_kwargs( } -def _parse_response(*, client: Client, response: httpx.Response) -> Optional[Any]: +def _parse_response(*, client: Client, response: httpx.Response) -> Optional[Union[Any, None]]: if response.status_code == HTTPStatus.OK: - return None + response_200 = cast(Any, response.json()) + return response_200 if response.status_code == HTTPStatus.UNAUTHORIZED: - return None + response_401 = cast(None, None) + return response_401 if client.raise_on_unexpected_status: raise errors.UnexpectedStatus(response.status_code, response.content) else: return None -def _build_response(*, client: Client, response: httpx.Response) -> Response[Any]: +def _build_response(*, client: Client, response: httpx.Response) -> Response[Union[Any, None]]: return Response( status_code=HTTPStatus(response.status_code), content=response.content, @@ -54,7 +56,7 @@ def sync_detailed( *, client: Client, my_token: str, -) -> Response[Any]: +) -> Response[Union[Any, None]]: """TOKEN_WITH_COOKIE Test optional cookie parameters @@ -67,7 +69,7 @@ def sync_detailed( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[Any] + Response[Union[Any, None]] """ kwargs = _get_kwargs( @@ -83,11 +85,37 @@ def sync_detailed( return _build_response(client=client, response=response) +def sync( + *, + client: Client, + my_token: str, +) -> Optional[Union[Any, None]]: + """TOKEN_WITH_COOKIE + + Test optional cookie parameters + + Args: + my_token (str): + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[Union[Any, None]] + """ + + return sync_detailed( + client=client, + my_token=my_token, + ).parsed + + async def asyncio_detailed( *, client: Client, my_token: str, -) -> Response[Any]: +) -> Response[Union[Any, None]]: """TOKEN_WITH_COOKIE Test optional cookie parameters @@ -100,7 +128,7 @@ async def asyncio_detailed( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[Any] + Response[Union[Any, None]] """ kwargs = _get_kwargs( @@ -112,3 +140,31 @@ async def asyncio_detailed( response = await _client.request(**kwargs) return _build_response(client=client, response=response) + + +async def asyncio( + *, + client: Client, + my_token: str, +) -> Optional[Union[Any, None]]: + """TOKEN_WITH_COOKIE + + Test optional cookie parameters + + Args: + my_token (str): + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[Union[Any, None]] + """ + + 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/true_/false_.py b/end_to_end_tests/golden-record/my_test_api_client/api/true_/false_.py index 05967d439..a9430bced 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/true_/false_.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/true_/false_.py @@ -34,7 +34,7 @@ def _get_kwargs( } -def _parse_response(*, client: Client, response: httpx.Response) -> Optional[Any]: +def _parse_response(*, client: Client, response: httpx.Response) -> Optional[None]: if response.status_code == HTTPStatus.OK: return None if client.raise_on_unexpected_status: @@ -43,7 +43,7 @@ def _parse_response(*, client: Client, response: httpx.Response) -> Optional[Any return None -def _build_response(*, client: Client, response: httpx.Response) -> Response[Any]: +def _build_response(*, client: Client, response: httpx.Response) -> Response[None]: return Response( status_code=HTTPStatus(response.status_code), content=response.content, @@ -56,7 +56,7 @@ def sync_detailed( *, client: Client, import_: str, -) -> Response[Any]: +) -> Response[None]: """ Args: import_ (str): @@ -66,7 +66,7 @@ def sync_detailed( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[Any] + Response[None] """ kwargs = _get_kwargs( @@ -86,7 +86,7 @@ async def asyncio_detailed( *, client: Client, import_: str, -) -> Response[Any]: +) -> Response[None]: """ Args: import_ (str): @@ -96,7 +96,7 @@ async def asyncio_detailed( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[Any] + Response[None] """ kwargs = _get_kwargs( diff --git a/openapi_python_client/parser/responses.py b/openapi_python_client/parser/responses.py index e1f2cb49a..78c32b70e 100644 --- a/openapi_python_client/parser/responses.py +++ b/openapi_python_client/parser/responses.py @@ -9,7 +9,7 @@ from .. import schema as oai from ..utils import PythonIdentifier from .errors import ParseError, PropertyError -from .properties import AnyProperty, Property, Schemas, property_from_data +from .properties import NoneProperty, Property, Schemas, property_from_data @attr.s(auto_attribs=True, frozen=True) @@ -40,7 +40,7 @@ def empty_response( """Return an untyped response, for when no response type is defined""" return Response( status_code=status_code, - prop=AnyProperty( + prop=NoneProperty( name=response_name, default=None, nullable=False, diff --git a/openapi_python_client/templates/endpoint_module.py.jinja b/openapi_python_client/templates/endpoint_module.py.jinja index a94c6f025..70418dac6 100644 --- a/openapi_python_client/templates/endpoint_module.py.jinja +++ b/openapi_python_client/templates/endpoint_module.py.jinja @@ -15,7 +15,7 @@ from ... import errors arguments, client, kwargs, parse_response, docstring %} {% set return_string = endpoint.response_type() %} -{% set parsed_responses = (endpoint.responses | length > 0) and return_string != "Any" %} +{% set parsed_responses = (endpoint.responses | length > 0) and return_string not in ("Any", "None") %} def _get_kwargs( {{ arguments(endpoint) | indent(4) }} diff --git a/tests/test_parser/test_responses.py b/tests/test_parser/test_responses.py index ab73cfb74..424be11ad 100644 --- a/tests/test_parser/test_responses.py +++ b/tests/test_parser/test_responses.py @@ -7,7 +7,7 @@ MODULE_NAME = "openapi_python_client.parser.responses" -def test_response_from_data_no_content(any_property_factory): +def test_response_from_data_no_content(none_property_factory): from openapi_python_client.parser.responses import Response, response_from_data response, schemas = response_from_data( @@ -20,7 +20,7 @@ def test_response_from_data_no_content(any_property_factory): assert response == Response( status_code=200, - prop=any_property_factory( + prop=none_property_factory( name="response_200", default=None, nullable=False, @@ -31,7 +31,7 @@ def test_response_from_data_no_content(any_property_factory): ) -def test_response_from_data_reference(any_property_factory): +def test_response_from_data_reference(none_property_factory): from openapi_python_client.parser.responses import Response, response_from_data response, schemas = response_from_data( @@ -44,7 +44,7 @@ def test_response_from_data_reference(any_property_factory): assert response == Response( status_code=200, - prop=any_property_factory( + prop=none_property_factory( name="response_200", default=None, nullable=False, @@ -65,7 +65,7 @@ def test_response_from_data_unsupported_content_type(): assert response == ParseError(data=data, detail="Unsupported content_type {'blah': None}") -def test_response_from_data_no_content_schema(any_property_factory): +def test_response_from_data_no_content_schema(none_property_factory): from openapi_python_client.parser.responses import Response, response_from_data data = oai.Response.construct(description="", content={"application/json": oai.MediaType.construct()}) @@ -75,7 +75,7 @@ def test_response_from_data_no_content_schema(any_property_factory): assert response == Response( status_code=200, - prop=any_property_factory( + prop=none_property_factory( name="response_200", default=None, nullable=False, From 43f3a4c500325dd0087faf723b9bda459fea6811 Mon Sep 17 00:00:00 2001 From: Robert Schweizer Date: Mon, 27 Mar 2023 10:44:09 +0200 Subject: [PATCH 2/6] fix: Do not cast() unnecessarily cast(None, None) made mypy fail after that last commit. --- .../my_test_api_client/api/tests/callback_test.py | 4 ++-- .../api/tests/defaults_tests_defaults_post.py | 4 ++-- .../api/tests/int_enum_tests_int_enum_post.py | 4 ++-- .../api/tests/json_body_tests_json_body_post.py | 4 ++-- ...oken_with_cookie_auth_token_with_cookie_get.py | 6 +++--- .../api/tests/upload_file_tests_upload_post.py | 4 ++-- .../upload_multiple_files_tests_upload_post.py | 4 ++-- openapi_python_client/parser/responses.py | 15 +++++++++++++++ .../templates/endpoint_module.py.jinja | 2 +- 9 files changed, 31 insertions(+), 16 deletions(-) diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/tests/callback_test.py b/end_to_end_tests/golden-record/my_test_api_client/api/tests/callback_test.py index 34a238b2d..872686b8b 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/tests/callback_test.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/tests/callback_test.py @@ -1,5 +1,5 @@ from http import HTTPStatus -from typing import Any, Dict, Optional, Union, cast +from typing import Any, Dict, Optional, Union import httpx @@ -35,7 +35,7 @@ def _get_kwargs( def _parse_response(*, client: Client, response: httpx.Response) -> Optional[Union[Any, HTTPValidationError]]: if response.status_code == HTTPStatus.OK: - response_200 = cast(Any, response.json()) + response_200 = response.json() return response_200 if response.status_code == HTTPStatus.UNPROCESSABLE_ENTITY: response_422 = HTTPValidationError.from_dict(response.json()) 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 414542116..dd7a11aef 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/tests/defaults_tests_defaults_post.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/tests/defaults_tests_defaults_post.py @@ -1,6 +1,6 @@ import datetime from http import HTTPStatus -from typing import Any, Dict, List, Optional, Union, cast +from typing import Any, Dict, List, Optional, Union import httpx from dateutil.parser import isoparse @@ -102,7 +102,7 @@ def _get_kwargs( def _parse_response(*, client: Client, response: httpx.Response) -> Optional[Union[Any, HTTPValidationError]]: if response.status_code == HTTPStatus.OK: - response_200 = cast(Any, response.json()) + response_200 = response.json() return response_200 if response.status_code == HTTPStatus.UNPROCESSABLE_ENTITY: response_422 = HTTPValidationError.from_dict(response.json()) 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 5a3ee4c7b..8b01e01ec 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/tests/int_enum_tests_int_enum_post.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/tests/int_enum_tests_int_enum_post.py @@ -1,5 +1,5 @@ from http import HTTPStatus -from typing import Any, Dict, Optional, Union, cast +from typing import Any, Dict, Optional, Union import httpx @@ -40,7 +40,7 @@ def _get_kwargs( def _parse_response(*, client: Client, response: httpx.Response) -> Optional[Union[Any, HTTPValidationError]]: if response.status_code == HTTPStatus.OK: - response_200 = cast(Any, response.json()) + response_200 = response.json() return response_200 if response.status_code == HTTPStatus.UNPROCESSABLE_ENTITY: response_422 = HTTPValidationError.from_dict(response.json()) 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 d482d0e3c..6ec1ab31f 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/tests/json_body_tests_json_body_post.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/tests/json_body_tests_json_body_post.py @@ -1,5 +1,5 @@ from http import HTTPStatus -from typing import Any, Dict, Optional, Union, cast +from typing import Any, Dict, Optional, Union import httpx @@ -35,7 +35,7 @@ def _get_kwargs( def _parse_response(*, client: Client, response: httpx.Response) -> Optional[Union[Any, HTTPValidationError]]: if response.status_code == HTTPStatus.OK: - response_200 = cast(Any, response.json()) + response_200 = response.json() return response_200 if response.status_code == HTTPStatus.UNPROCESSABLE_ENTITY: response_422 = HTTPValidationError.from_dict(response.json()) 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 a195cce0b..7d4dd9367 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,5 +1,5 @@ from http import HTTPStatus -from typing import Any, Dict, Optional, Union, cast +from typing import Any, Dict, Optional, Union import httpx @@ -32,10 +32,10 @@ def _get_kwargs( def _parse_response(*, client: Client, response: httpx.Response) -> Optional[Union[Any, None]]: if response.status_code == HTTPStatus.OK: - response_200 = cast(Any, response.json()) + response_200 = response.json() return response_200 if response.status_code == HTTPStatus.UNAUTHORIZED: - response_401 = cast(None, None) + response_401 = None return response_401 if client.raise_on_unexpected_status: raise errors.UnexpectedStatus(response.status_code, response.content) 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 61f28a42e..65bf0f6cd 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/tests/upload_file_tests_upload_post.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/tests/upload_file_tests_upload_post.py @@ -1,5 +1,5 @@ from http import HTTPStatus -from typing import Any, Dict, Optional, Union, cast +from typing import Any, Dict, Optional, Union import httpx @@ -35,7 +35,7 @@ def _get_kwargs( def _parse_response(*, client: Client, response: httpx.Response) -> Optional[Union[Any, HTTPValidationError]]: if response.status_code == HTTPStatus.OK: - response_200 = cast(Any, response.json()) + response_200 = response.json() return response_200 if response.status_code == HTTPStatus.UNPROCESSABLE_ENTITY: response_422 = HTTPValidationError.from_dict(response.json()) diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/tests/upload_multiple_files_tests_upload_post.py b/end_to_end_tests/golden-record/my_test_api_client/api/tests/upload_multiple_files_tests_upload_post.py index 58c459a1d..21797e239 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/tests/upload_multiple_files_tests_upload_post.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/tests/upload_multiple_files_tests_upload_post.py @@ -1,5 +1,5 @@ from http import HTTPStatus -from typing import Any, Dict, List, Optional, Union, cast +from typing import Any, Dict, List, Optional, Union import httpx @@ -38,7 +38,7 @@ def _get_kwargs( def _parse_response(*, client: Client, response: httpx.Response) -> Optional[Union[Any, HTTPValidationError]]: if response.status_code == HTTPStatus.OK: - response_200 = cast(Any, response.json()) + response_200 = response.json() return response_200 if response.status_code == HTTPStatus.UNPROCESSABLE_ENTITY: response_422 = HTTPValidationError.from_dict(response.json()) diff --git a/openapi_python_client/parser/responses.py b/openapi_python_client/parser/responses.py index 78c32b70e..795ed057e 100644 --- a/openapi_python_client/parser/responses.py +++ b/openapi_python_client/parser/responses.py @@ -20,6 +20,21 @@ class Response: prop: Property source: str + def get_typed_source(self) -> str: + """Get Python statement that parses the response and returns the correct type. + + This might include a type cast if necessary (e.g. if we parse JSON + that can only be a string according to the OpenAPI schema) + """ + if self.source == self.prop.get_type_string(): + # No cast needed e.g. for `None` and `None`. + return self.source + if self.source == "response.json()" and self.prop.get_type_string() == "Any": + # response.json() is often used for untyped responses and already has + # the `Any` return type annotation. + return self.source + return f"cast({self.prop.get_type_string()}, {self.source})" + def _source_by_content_type(content_type: str) -> Optional[str]: known_content_types = { diff --git a/openapi_python_client/templates/endpoint_module.py.jinja b/openapi_python_client/templates/endpoint_module.py.jinja index 70418dac6..c60396335 100644 --- a/openapi_python_client/templates/endpoint_module.py.jinja +++ b/openapi_python_client/templates/endpoint_module.py.jinja @@ -67,7 +67,7 @@ def _parse_response(*, client: Client, response: httpx.Response) -> Optional[{{ {% if prop_template.construct %} {{ prop_template.construct(response.prop, response.source) | indent(8) }} {% else %} - {{ response.prop.python_name }} = cast({{ response.prop.get_type_string() }}, {{ response.source }}) + {{ response.prop.python_name }} = {{ response.get_typed_source() }} {% endif %} return {{ response.prop.python_name }} {% else %} From 11869550896089cb2fcc180ee6f5000ce0e90360 Mon Sep 17 00:00:00 2001 From: Robert Schweizer Date: Fri, 24 Mar 2023 18:41:12 +0100 Subject: [PATCH 3/6] feat: Parse JSON responses without schema It makes sense to return the parsed JSON here instead of None. --- .../no_response_tests_no_response_get.py | 45 +++++++++++++++- .../api/tests/post_form_data.py | 53 ++++++++++++++++++- .../api/tests/post_form_data_inline.py | 53 ++++++++++++++++++- ...d_content_tests_unsupported_content_get.py | 45 +++++++++++++++- .../templates/endpoint_module.py.jinja | 2 +- 5 files changed, 189 insertions(+), 9 deletions(-) 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 075452512..b2d3804a5 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,5 +1,5 @@ from http import HTTPStatus -from typing import Any, Dict, Optional +from typing import Any, Dict, Optional, cast import httpx @@ -29,7 +29,8 @@ def _get_kwargs( def _parse_response(*, client: Client, response: httpx.Response) -> Optional[Any]: if response.status_code == HTTPStatus.OK: - return None + response_200 = cast(Any, response.json()) + return response_200 if client.raise_on_unexpected_status: raise errors.UnexpectedStatus(response.status_code, response.content) else: @@ -71,6 +72,25 @@ def sync_detailed( return _build_response(client=client, response=response) +def sync( + *, + client: Client, +) -> Optional[Any]: + """No Response + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[Any] + """ + + return sync_detailed( + client=client, + ).parsed + + async def asyncio_detailed( *, client: Client, @@ -93,3 +113,24 @@ async def asyncio_detailed( response = await _client.request(**kwargs) return _build_response(client=client, response=response) + + +async def asyncio( + *, + client: Client, +) -> Optional[Any]: + """No Response + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[Any] + """ + + return ( + await asyncio_detailed( + client=client, + ) + ).parsed diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/tests/post_form_data.py b/end_to_end_tests/golden-record/my_test_api_client/api/tests/post_form_data.py index 07c0b225e..e15de1adc 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/tests/post_form_data.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/tests/post_form_data.py @@ -1,5 +1,5 @@ from http import HTTPStatus -from typing import Any, Dict, Optional +from typing import Any, Dict, Optional, cast import httpx @@ -32,7 +32,8 @@ def _get_kwargs( def _parse_response(*, client: Client, response: httpx.Response) -> Optional[Any]: if response.status_code == HTTPStatus.OK: - return None + response_200 = cast(Any, response.json()) + return response_200 if client.raise_on_unexpected_status: raise errors.UnexpectedStatus(response.status_code, response.content) else: @@ -78,6 +79,29 @@ def sync_detailed( return _build_response(client=client, response=response) +def sync( + *, + client: Client, + form_data: AFormData, +) -> Optional[Any]: + """Post form data + + Post form data + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[Any] + """ + + return sync_detailed( + client=client, + form_data=form_data, + ).parsed + + async def asyncio_detailed( *, client: Client, @@ -104,3 +128,28 @@ async def asyncio_detailed( response = await _client.request(**kwargs) return _build_response(client=client, response=response) + + +async def asyncio( + *, + client: Client, + form_data: AFormData, +) -> Optional[Any]: + """Post form data + + Post form data + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[Any] + """ + + return ( + await asyncio_detailed( + client=client, + form_data=form_data, + ) + ).parsed diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/tests/post_form_data_inline.py b/end_to_end_tests/golden-record/my_test_api_client/api/tests/post_form_data_inline.py index e93a22986..c4c53419e 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/tests/post_form_data_inline.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/tests/post_form_data_inline.py @@ -1,5 +1,5 @@ from http import HTTPStatus -from typing import Any, Dict, Optional +from typing import Any, Dict, Optional, cast import httpx @@ -32,7 +32,8 @@ def _get_kwargs( def _parse_response(*, client: Client, response: httpx.Response) -> Optional[Any]: if response.status_code == HTTPStatus.OK: - return None + response_200 = cast(Any, response.json()) + return response_200 if client.raise_on_unexpected_status: raise errors.UnexpectedStatus(response.status_code, response.content) else: @@ -78,6 +79,29 @@ def sync_detailed( return _build_response(client=client, response=response) +def sync( + *, + client: Client, + form_data: PostFormDataInlineData, +) -> Optional[Any]: + """Post form data (inline schema) + + Post form data (inline schema) + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[Any] + """ + + return sync_detailed( + client=client, + form_data=form_data, + ).parsed + + async def asyncio_detailed( *, client: Client, @@ -104,3 +128,28 @@ async def asyncio_detailed( response = await _client.request(**kwargs) return _build_response(client=client, response=response) + + +async def asyncio( + *, + client: Client, + form_data: PostFormDataInlineData, +) -> Optional[Any]: + """Post form data (inline schema) + + Post form data (inline schema) + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[Any] + """ + + return ( + await asyncio_detailed( + client=client, + form_data=form_data, + ) + ).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 6b719cb38..a067f9713 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,5 +1,5 @@ from http import HTTPStatus -from typing import Any, Dict, Optional +from typing import Any, Dict, Optional, cast import httpx @@ -29,7 +29,8 @@ def _get_kwargs( def _parse_response(*, client: Client, response: httpx.Response) -> Optional[Any]: if response.status_code == HTTPStatus.OK: - return None + response_200 = cast(Any, response.json()) + return response_200 if client.raise_on_unexpected_status: raise errors.UnexpectedStatus(response.status_code, response.content) else: @@ -71,6 +72,25 @@ def sync_detailed( return _build_response(client=client, response=response) +def sync( + *, + client: Client, +) -> Optional[Any]: + """Unsupported Content + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[Any] + """ + + return sync_detailed( + client=client, + ).parsed + + async def asyncio_detailed( *, client: Client, @@ -93,3 +113,24 @@ async def asyncio_detailed( response = await _client.request(**kwargs) return _build_response(client=client, response=response) + + +async def asyncio( + *, + client: Client, +) -> Optional[Any]: + """Unsupported Content + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[Any] + """ + + return ( + await asyncio_detailed( + client=client, + ) + ).parsed diff --git a/openapi_python_client/templates/endpoint_module.py.jinja b/openapi_python_client/templates/endpoint_module.py.jinja index c60396335..a7b05a502 100644 --- a/openapi_python_client/templates/endpoint_module.py.jinja +++ b/openapi_python_client/templates/endpoint_module.py.jinja @@ -15,7 +15,7 @@ from ... import errors arguments, client, kwargs, parse_response, docstring %} {% set return_string = endpoint.response_type() %} -{% set parsed_responses = (endpoint.responses | length > 0) and return_string not in ("Any", "None") %} +{% set parsed_responses = (endpoint.responses | length > 0) and return_string != "None" %} def _get_kwargs( {{ arguments(endpoint) | indent(4) }} From 5a75e3d85456b18c4d0fb74f634415824bbad4cd Mon Sep 17 00:00:00 2001 From: Robert Schweizer Date: Mon, 27 Mar 2023 09:30:36 +0200 Subject: [PATCH 4/6] fix: Ignore mypy error when returning None This was introduced in "fix: Make empty response a `NoneProperty`", but is easier to fix now since parsed_responses in endpoint_module.py.jinja does not include `Any` response types anymore. --- .../my_test_api_client/api/default/get_common_parameters.py | 2 +- .../my_test_api_client/api/default/post_common_parameters.py | 2 +- .../api/location/get_location_header_types.py | 2 +- .../api/location/get_location_query_optionality.py | 2 +- .../get_parameter_references_path_param.py | 2 +- .../parameters/delete_common_parameters_overriding_param.py | 2 +- .../api/parameters/get_common_parameters_overriding_param.py | 2 +- .../api/parameters/get_same_name_multiple_locations_param.py | 2 +- .../api/parameters/multiple_path_parameters.py | 2 +- .../my_test_api_client/api/tag1/get_tag_with_number.py | 2 +- .../api/tests/description_with_backslash.py | 2 +- .../api/tests/no_response_tests_no_response_get.py | 4 ++-- .../my_test_api_client/api/tests/post_form_data.py | 4 ++-- .../my_test_api_client/api/tests/post_form_data_inline.py | 4 ++-- .../unsupported_content_tests_unsupported_content_get.py | 4 ++-- .../golden-record/my_test_api_client/api/true_/false_.py | 2 +- openapi_python_client/templates/endpoint_module.py.jinja | 5 +++++ 17 files changed, 25 insertions(+), 20 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 7312769bc..3bb87b06d 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 @@ -48,7 +48,7 @@ def _build_response(*, client: Client, response: httpx.Response) -> Response[Non status_code=HTTPStatus(response.status_code), content=response.content, headers=response.headers, - parsed=_parse_response(client=client, response=response), + parsed=_parse_response(client=client, response=response), # type: ignore[func-returns-value] ) 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 0cd09545c..7abd3aea4 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 @@ -48,7 +48,7 @@ def _build_response(*, client: Client, response: httpx.Response) -> Response[Non status_code=HTTPStatus(response.status_code), content=response.content, headers=response.headers, - parsed=_parse_response(client=client, response=response), + parsed=_parse_response(client=client, response=response), # type: ignore[func-returns-value] ) diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/location/get_location_header_types.py b/end_to_end_tests/golden-record/my_test_api_client/api/location/get_location_header_types.py index bd27b3005..40bdd99af 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/location/get_location_header_types.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/location/get_location_header_types.py @@ -67,7 +67,7 @@ def _build_response(*, client: Client, response: httpx.Response) -> Response[Non status_code=HTTPStatus(response.status_code), content=response.content, headers=response.headers, - parsed=_parse_response(client=client, response=response), + parsed=_parse_response(client=client, response=response), # type: ignore[func-returns-value] ) diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/location/get_location_query_optionality.py b/end_to_end_tests/golden-record/my_test_api_client/api/location/get_location_query_optionality.py index 1681aa7be..275d32a2d 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/location/get_location_query_optionality.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/location/get_location_query_optionality.py @@ -72,7 +72,7 @@ def _build_response(*, client: Client, response: httpx.Response) -> Response[Non status_code=HTTPStatus(response.status_code), content=response.content, headers=response.headers, - parsed=_parse_response(client=client, response=response), + parsed=_parse_response(client=client, response=response), # type: ignore[func-returns-value] ) diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/parameter_references/get_parameter_references_path_param.py b/end_to_end_tests/golden-record/my_test_api_client/api/parameter_references/get_parameter_references_path_param.py index 0d1df91ce..f3d910c81 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/parameter_references/get_parameter_references_path_param.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/parameter_references/get_parameter_references_path_param.py @@ -60,7 +60,7 @@ def _build_response(*, client: Client, response: httpx.Response) -> Response[Non status_code=HTTPStatus(response.status_code), content=response.content, headers=response.headers, - parsed=_parse_response(client=client, response=response), + parsed=_parse_response(client=client, response=response), # type: ignore[func-returns-value] ) diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/parameters/delete_common_parameters_overriding_param.py b/end_to_end_tests/golden-record/my_test_api_client/api/parameters/delete_common_parameters_overriding_param.py index 633c8050e..2b3ffd170 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/parameters/delete_common_parameters_overriding_param.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/parameters/delete_common_parameters_overriding_param.py @@ -49,7 +49,7 @@ def _build_response(*, client: Client, response: httpx.Response) -> Response[Non status_code=HTTPStatus(response.status_code), content=response.content, headers=response.headers, - parsed=_parse_response(client=client, response=response), + parsed=_parse_response(client=client, response=response), # type: ignore[func-returns-value] ) diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/parameters/get_common_parameters_overriding_param.py b/end_to_end_tests/golden-record/my_test_api_client/api/parameters/get_common_parameters_overriding_param.py index 3f9d25e7d..1e025a5fc 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/parameters/get_common_parameters_overriding_param.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/parameters/get_common_parameters_overriding_param.py @@ -49,7 +49,7 @@ def _build_response(*, client: Client, response: httpx.Response) -> Response[Non status_code=HTTPStatus(response.status_code), content=response.content, headers=response.headers, - parsed=_parse_response(client=client, response=response), + parsed=_parse_response(client=client, response=response), # type: ignore[func-returns-value] ) 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 48ab09277..9d00bbef8 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 @@ -57,7 +57,7 @@ def _build_response(*, client: Client, response: httpx.Response) -> Response[Non status_code=HTTPStatus(response.status_code), content=response.content, headers=response.headers, - parsed=_parse_response(client=client, response=response), + parsed=_parse_response(client=client, response=response), # type: ignore[func-returns-value] ) diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/parameters/multiple_path_parameters.py b/end_to_end_tests/golden-record/my_test_api_client/api/parameters/multiple_path_parameters.py index 583cfa89c..27c9a21f3 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/parameters/multiple_path_parameters.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/parameters/multiple_path_parameters.py @@ -47,7 +47,7 @@ def _build_response(*, client: Client, response: httpx.Response) -> Response[Non status_code=HTTPStatus(response.status_code), content=response.content, headers=response.headers, - parsed=_parse_response(client=client, response=response), + parsed=_parse_response(client=client, response=response), # type: ignore[func-returns-value] ) diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/tag1/get_tag_with_number.py b/end_to_end_tests/golden-record/my_test_api_client/api/tag1/get_tag_with_number.py index 47cce69ff..201fbe45d 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/tag1/get_tag_with_number.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/tag1/get_tag_with_number.py @@ -41,7 +41,7 @@ def _build_response(*, client: Client, response: httpx.Response) -> Response[Non status_code=HTTPStatus(response.status_code), content=response.content, headers=response.headers, - parsed=_parse_response(client=client, response=response), + parsed=_parse_response(client=client, response=response), # type: ignore[func-returns-value] ) diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/tests/description_with_backslash.py b/end_to_end_tests/golden-record/my_test_api_client/api/tests/description_with_backslash.py index a650433d9..a27d3b34e 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/tests/description_with_backslash.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/tests/description_with_backslash.py @@ -41,7 +41,7 @@ def _build_response(*, client: Client, response: httpx.Response) -> Response[Non status_code=HTTPStatus(response.status_code), content=response.content, headers=response.headers, - parsed=_parse_response(client=client, response=response), + parsed=_parse_response(client=client, response=response), # type: ignore[func-returns-value] ) 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 b2d3804a5..8f5a03aba 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,5 +1,5 @@ from http import HTTPStatus -from typing import Any, Dict, Optional, cast +from typing import Any, Dict, Optional import httpx @@ -29,7 +29,7 @@ def _get_kwargs( def _parse_response(*, client: Client, response: httpx.Response) -> Optional[Any]: if response.status_code == HTTPStatus.OK: - response_200 = cast(Any, response.json()) + response_200 = response.json() return response_200 if client.raise_on_unexpected_status: raise errors.UnexpectedStatus(response.status_code, response.content) diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/tests/post_form_data.py b/end_to_end_tests/golden-record/my_test_api_client/api/tests/post_form_data.py index e15de1adc..3d5115610 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/tests/post_form_data.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/tests/post_form_data.py @@ -1,5 +1,5 @@ from http import HTTPStatus -from typing import Any, Dict, Optional, cast +from typing import Any, Dict, Optional import httpx @@ -32,7 +32,7 @@ def _get_kwargs( def _parse_response(*, client: Client, response: httpx.Response) -> Optional[Any]: if response.status_code == HTTPStatus.OK: - response_200 = cast(Any, response.json()) + response_200 = response.json() return response_200 if client.raise_on_unexpected_status: raise errors.UnexpectedStatus(response.status_code, response.content) diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/tests/post_form_data_inline.py b/end_to_end_tests/golden-record/my_test_api_client/api/tests/post_form_data_inline.py index c4c53419e..0f8f3dc5a 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/tests/post_form_data_inline.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/tests/post_form_data_inline.py @@ -1,5 +1,5 @@ from http import HTTPStatus -from typing import Any, Dict, Optional, cast +from typing import Any, Dict, Optional import httpx @@ -32,7 +32,7 @@ def _get_kwargs( def _parse_response(*, client: Client, response: httpx.Response) -> Optional[Any]: if response.status_code == HTTPStatus.OK: - response_200 = cast(Any, response.json()) + response_200 = response.json() return response_200 if client.raise_on_unexpected_status: raise errors.UnexpectedStatus(response.status_code, response.content) 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 a067f9713..3fbaa44b4 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,5 +1,5 @@ from http import HTTPStatus -from typing import Any, Dict, Optional, cast +from typing import Any, Dict, Optional import httpx @@ -29,7 +29,7 @@ def _get_kwargs( def _parse_response(*, client: Client, response: httpx.Response) -> Optional[Any]: if response.status_code == HTTPStatus.OK: - response_200 = cast(Any, response.json()) + response_200 = response.json() return response_200 if client.raise_on_unexpected_status: raise errors.UnexpectedStatus(response.status_code, response.content) diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/true_/false_.py b/end_to_end_tests/golden-record/my_test_api_client/api/true_/false_.py index a9430bced..a140ffa0a 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/true_/false_.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/true_/false_.py @@ -48,7 +48,7 @@ def _build_response(*, client: Client, response: httpx.Response) -> Response[Non status_code=HTTPStatus(response.status_code), content=response.content, headers=response.headers, - parsed=_parse_response(client=client, response=response), + parsed=_parse_response(client=client, response=response), # type: ignore[func-returns-value] ) diff --git a/openapi_python_client/templates/endpoint_module.py.jinja b/openapi_python_client/templates/endpoint_module.py.jinja index a7b05a502..e8f512748 100644 --- a/openapi_python_client/templates/endpoint_module.py.jinja +++ b/openapi_python_client/templates/endpoint_module.py.jinja @@ -85,7 +85,12 @@ def _build_response(*, client: Client, response: httpx.Response) -> Response[{{ status_code=HTTPStatus(response.status_code), content=response.content, headers=response.headers, + {% if parsed_responses %} parsed=_parse_response(client=client, response=response), + {% else %} + {# If _parse_response() returns None, mypy complains: https://github.com/python/mypy/issues/6549 #} + parsed=_parse_response(client=client, response=response), # type: ignore[func-returns-value] + {% endif %} ) From 01908a576b5e3e2aef08777b0bce1c3f0782464b Mon Sep 17 00:00:00 2001 From: Robert Schweizer Date: Wed, 15 Mar 2023 20:09:34 +0100 Subject: [PATCH 5/6] fix: Add None to Response[] generic type Also prevents double return type annotations like `Optional[None]`. --- .../api/default/get_common_parameters.py | 4 ++-- .../api/default/post_common_parameters.py | 4 ++-- .../api/location/get_location_header_types.py | 4 ++-- .../get_location_query_optionality.py | 4 ++-- .../get_parameter_references_path_param.py | 4 ++-- ...lete_common_parameters_overriding_param.py | 4 ++-- .../get_common_parameters_overriding_param.py | 4 ++-- .../get_same_name_multiple_locations_param.py | 4 ++-- .../parameters/multiple_path_parameters.py | 4 ++-- ..._responses_unions_simple_before_complex.py | 22 +++++++++---------- .../api/tag1/get_tag_with_number.py | 4 ++-- .../api/tests/callback_test.py | 22 +++++++++---------- .../api/tests/defaults_tests_defaults_post.py | 22 +++++++++---------- .../api/tests/description_with_backslash.py | 4 ++-- .../api/tests/get_basic_list_of_booleans.py | 22 +++++++++---------- .../api/tests/get_basic_list_of_floats.py | 22 +++++++++---------- .../api/tests/get_basic_list_of_integers.py | 22 +++++++++---------- .../api/tests/get_basic_list_of_strings.py | 22 +++++++++---------- .../api/tests/get_user_list.py | 22 +++++++++---------- .../api/tests/int_enum_tests_int_enum_post.py | 22 +++++++++---------- .../tests/json_body_tests_json_body_post.py | 22 +++++++++---------- .../no_response_tests_no_response_get.py | 22 +++++++++---------- .../octet_stream_tests_octet_stream_get.py | 22 +++++++++---------- .../api/tests/post_form_data.py | 22 +++++++++---------- .../api/tests/post_form_data_inline.py | 22 +++++++++---------- .../api/tests/post_tests_json_body_string.py | 22 +++++++++---------- .../api/tests/test_inline_objects.py | 22 +++++++++---------- ..._with_cookie_auth_token_with_cookie_get.py | 12 +++++----- ...d_content_tests_unsupported_content_get.py | 22 +++++++++---------- .../tests/upload_file_tests_upload_post.py | 22 +++++++++---------- ...upload_multiple_files_tests_upload_post.py | 22 +++++++++---------- .../my_test_api_client/api/true_/false_.py | 4 ++-- .../golden-record/my_test_api_client/types.py | 2 +- .../api/body/post_body_multipart.py | 22 +++++++++---------- .../api/parameters/post_parameters_header.py | 22 +++++++++---------- integration-tests/integration_tests/types.py | 2 +- openapi_python_client/parser/openapi.py | 10 ++++----- .../templates/endpoint_module.py.jinja | 6 ++--- .../templates/types.py.jinja | 2 +- tests/test_parser/test_openapi.py | 6 ++++- 40 files changed, 276 insertions(+), 274 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 3bb87b06d..e4e209177 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,5 +1,5 @@ from http import HTTPStatus -from typing import Any, Dict, Optional, Union +from typing import Any, Dict, Union import httpx @@ -34,7 +34,7 @@ def _get_kwargs( } -def _parse_response(*, client: Client, response: httpx.Response) -> Optional[None]: +def _parse_response(*, client: Client, response: httpx.Response) -> None: if response.status_code == HTTPStatus.OK: return None if client.raise_on_unexpected_status: 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 7abd3aea4..acfc1bb3d 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,5 +1,5 @@ from http import HTTPStatus -from typing import Any, Dict, Optional, Union +from typing import Any, Dict, Union import httpx @@ -34,7 +34,7 @@ def _get_kwargs( } -def _parse_response(*, client: Client, response: httpx.Response) -> Optional[None]: +def _parse_response(*, client: Client, response: httpx.Response) -> None: if response.status_code == HTTPStatus.OK: return None if client.raise_on_unexpected_status: diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/location/get_location_header_types.py b/end_to_end_tests/golden-record/my_test_api_client/api/location/get_location_header_types.py index 40bdd99af..caaca2244 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/location/get_location_header_types.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/location/get_location_header_types.py @@ -1,5 +1,5 @@ from http import HTTPStatus -from typing import Any, Dict, Optional, Union +from typing import Any, Dict, Union import httpx @@ -53,7 +53,7 @@ def _get_kwargs( } -def _parse_response(*, client: Client, response: httpx.Response) -> Optional[None]: +def _parse_response(*, client: Client, response: httpx.Response) -> None: if response.status_code == HTTPStatus.OK: return None if client.raise_on_unexpected_status: diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/location/get_location_query_optionality.py b/end_to_end_tests/golden-record/my_test_api_client/api/location/get_location_query_optionality.py index 275d32a2d..1f211deb0 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/location/get_location_query_optionality.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/location/get_location_query_optionality.py @@ -1,6 +1,6 @@ import datetime from http import HTTPStatus -from typing import Any, Dict, Optional, Union +from typing import Any, Dict, Union import httpx @@ -58,7 +58,7 @@ def _get_kwargs( } -def _parse_response(*, client: Client, response: httpx.Response) -> Optional[None]: +def _parse_response(*, client: Client, response: httpx.Response) -> None: if response.status_code == HTTPStatus.OK: return None if client.raise_on_unexpected_status: diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/parameter_references/get_parameter_references_path_param.py b/end_to_end_tests/golden-record/my_test_api_client/api/parameter_references/get_parameter_references_path_param.py index f3d910c81..e624122f8 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/parameter_references/get_parameter_references_path_param.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/parameter_references/get_parameter_references_path_param.py @@ -1,5 +1,5 @@ from http import HTTPStatus -from typing import Any, Dict, Optional, Union +from typing import Any, Dict, Union import httpx @@ -46,7 +46,7 @@ def _get_kwargs( } -def _parse_response(*, client: Client, response: httpx.Response) -> Optional[None]: +def _parse_response(*, client: Client, response: httpx.Response) -> None: if response.status_code == HTTPStatus.OK: return None if client.raise_on_unexpected_status: diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/parameters/delete_common_parameters_overriding_param.py b/end_to_end_tests/golden-record/my_test_api_client/api/parameters/delete_common_parameters_overriding_param.py index 2b3ffd170..9ae19e6bd 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/parameters/delete_common_parameters_overriding_param.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/parameters/delete_common_parameters_overriding_param.py @@ -1,5 +1,5 @@ from http import HTTPStatus -from typing import Any, Dict, Optional, Union +from typing import Any, Dict, Union import httpx @@ -35,7 +35,7 @@ def _get_kwargs( } -def _parse_response(*, client: Client, response: httpx.Response) -> Optional[None]: +def _parse_response(*, client: Client, response: httpx.Response) -> None: if response.status_code == HTTPStatus.OK: return None if client.raise_on_unexpected_status: diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/parameters/get_common_parameters_overriding_param.py b/end_to_end_tests/golden-record/my_test_api_client/api/parameters/get_common_parameters_overriding_param.py index 1e025a5fc..1ff1a456c 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/parameters/get_common_parameters_overriding_param.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/parameters/get_common_parameters_overriding_param.py @@ -1,5 +1,5 @@ from http import HTTPStatus -from typing import Any, Dict, Optional +from typing import Any, Dict import httpx @@ -35,7 +35,7 @@ def _get_kwargs( } -def _parse_response(*, client: Client, response: httpx.Response) -> Optional[None]: +def _parse_response(*, client: Client, response: httpx.Response) -> None: if response.status_code == HTTPStatus.OK: return None if client.raise_on_unexpected_status: 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 9d00bbef8..30d2ef2b7 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,5 +1,5 @@ from http import HTTPStatus -from typing import Any, Dict, Optional, Union +from typing import Any, Dict, Union import httpx @@ -43,7 +43,7 @@ def _get_kwargs( } -def _parse_response(*, client: Client, response: httpx.Response) -> Optional[None]: +def _parse_response(*, client: Client, response: httpx.Response) -> None: if response.status_code == HTTPStatus.OK: return None if client.raise_on_unexpected_status: diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/parameters/multiple_path_parameters.py b/end_to_end_tests/golden-record/my_test_api_client/api/parameters/multiple_path_parameters.py index 27c9a21f3..df96d75b7 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/parameters/multiple_path_parameters.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/parameters/multiple_path_parameters.py @@ -1,5 +1,5 @@ from http import HTTPStatus -from typing import Any, Dict, Optional +from typing import Any, Dict import httpx @@ -33,7 +33,7 @@ def _get_kwargs( } -def _parse_response(*, client: Client, response: httpx.Response) -> Optional[None]: +def _parse_response(*, client: Client, response: httpx.Response) -> None: if response.status_code == HTTPStatus.OK: return None if client.raise_on_unexpected_status: diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/responses/post_responses_unions_simple_before_complex.py b/end_to_end_tests/golden-record/my_test_api_client/api/responses/post_responses_unions_simple_before_complex.py index b092e529d..476d066a9 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/responses/post_responses_unions_simple_before_complex.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/responses/post_responses_unions_simple_before_complex.py @@ -1,5 +1,5 @@ from http import HTTPStatus -from typing import Any, Dict, Optional +from typing import Any, Dict, Union import httpx @@ -32,7 +32,7 @@ def _get_kwargs( def _parse_response( *, client: Client, response: httpx.Response -) -> Optional[PostResponsesUnionsSimpleBeforeComplexResponse200]: +) -> Union[None, PostResponsesUnionsSimpleBeforeComplexResponse200]: if response.status_code == HTTPStatus.OK: response_200 = PostResponsesUnionsSimpleBeforeComplexResponse200.from_dict(response.json()) @@ -45,7 +45,7 @@ def _parse_response( def _build_response( *, client: Client, response: httpx.Response -) -> Response[PostResponsesUnionsSimpleBeforeComplexResponse200]: +) -> Response[Union[None, PostResponsesUnionsSimpleBeforeComplexResponse200]]: return Response( status_code=HTTPStatus(response.status_code), content=response.content, @@ -57,7 +57,7 @@ def _build_response( def sync_detailed( *, client: Client, -) -> Response[PostResponsesUnionsSimpleBeforeComplexResponse200]: +) -> Response[Union[None, PostResponsesUnionsSimpleBeforeComplexResponse200]]: """Regression test for #603 Raises: @@ -65,7 +65,7 @@ def sync_detailed( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[PostResponsesUnionsSimpleBeforeComplexResponse200] + Response[Union[None, PostResponsesUnionsSimpleBeforeComplexResponse200]] """ kwargs = _get_kwargs( @@ -83,7 +83,7 @@ def sync_detailed( def sync( *, client: Client, -) -> Optional[PostResponsesUnionsSimpleBeforeComplexResponse200]: +) -> Union[None, PostResponsesUnionsSimpleBeforeComplexResponse200]: """Regression test for #603 Raises: @@ -91,7 +91,7 @@ def sync( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - PostResponsesUnionsSimpleBeforeComplexResponse200 + Union[None, PostResponsesUnionsSimpleBeforeComplexResponse200] """ return sync_detailed( @@ -102,7 +102,7 @@ def sync( async def asyncio_detailed( *, client: Client, -) -> Response[PostResponsesUnionsSimpleBeforeComplexResponse200]: +) -> Response[Union[None, PostResponsesUnionsSimpleBeforeComplexResponse200]]: """Regression test for #603 Raises: @@ -110,7 +110,7 @@ async def asyncio_detailed( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[PostResponsesUnionsSimpleBeforeComplexResponse200] + Response[Union[None, PostResponsesUnionsSimpleBeforeComplexResponse200]] """ kwargs = _get_kwargs( @@ -126,7 +126,7 @@ async def asyncio_detailed( async def asyncio( *, client: Client, -) -> Optional[PostResponsesUnionsSimpleBeforeComplexResponse200]: +) -> Union[None, PostResponsesUnionsSimpleBeforeComplexResponse200]: """Regression test for #603 Raises: @@ -134,7 +134,7 @@ async def asyncio( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - PostResponsesUnionsSimpleBeforeComplexResponse200 + Union[None, PostResponsesUnionsSimpleBeforeComplexResponse200] """ return ( diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/tag1/get_tag_with_number.py b/end_to_end_tests/golden-record/my_test_api_client/api/tag1/get_tag_with_number.py index 201fbe45d..24afd48d7 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/tag1/get_tag_with_number.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/tag1/get_tag_with_number.py @@ -1,5 +1,5 @@ from http import HTTPStatus -from typing import Any, Dict, Optional +from typing import Any, Dict import httpx @@ -27,7 +27,7 @@ def _get_kwargs( } -def _parse_response(*, client: Client, response: httpx.Response) -> Optional[None]: +def _parse_response(*, client: Client, response: httpx.Response) -> None: if response.status_code == HTTPStatus.OK: return None if client.raise_on_unexpected_status: diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/tests/callback_test.py b/end_to_end_tests/golden-record/my_test_api_client/api/tests/callback_test.py index 872686b8b..343781097 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/tests/callback_test.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/tests/callback_test.py @@ -1,5 +1,5 @@ from http import HTTPStatus -from typing import Any, Dict, Optional, Union +from typing import Any, Dict, Union import httpx @@ -33,7 +33,7 @@ def _get_kwargs( } -def _parse_response(*, client: Client, response: httpx.Response) -> Optional[Union[Any, HTTPValidationError]]: +def _parse_response(*, client: Client, response: httpx.Response) -> Union[Any, HTTPValidationError, None]: if response.status_code == HTTPStatus.OK: response_200 = response.json() return response_200 @@ -47,7 +47,7 @@ def _parse_response(*, client: Client, response: httpx.Response) -> Optional[Uni return None -def _build_response(*, client: Client, response: httpx.Response) -> Response[Union[Any, HTTPValidationError]]: +def _build_response(*, client: Client, response: httpx.Response) -> Response[Union[Any, HTTPValidationError, None]]: return Response( status_code=HTTPStatus(response.status_code), content=response.content, @@ -60,7 +60,7 @@ def sync_detailed( *, client: Client, json_body: AModel, -) -> Response[Union[Any, HTTPValidationError]]: +) -> Response[Union[Any, HTTPValidationError, None]]: """Path with callback Try sending a request related to a callback @@ -73,7 +73,7 @@ def sync_detailed( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[Union[Any, HTTPValidationError]] + Response[Union[Any, HTTPValidationError, None]] """ kwargs = _get_kwargs( @@ -93,7 +93,7 @@ def sync( *, client: Client, json_body: AModel, -) -> Optional[Union[Any, HTTPValidationError]]: +) -> Union[Any, HTTPValidationError, None]: """Path with callback Try sending a request related to a callback @@ -106,7 +106,7 @@ def sync( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Union[Any, HTTPValidationError] + Union[Any, HTTPValidationError, None] """ return sync_detailed( @@ -119,7 +119,7 @@ async def asyncio_detailed( *, client: Client, json_body: AModel, -) -> Response[Union[Any, HTTPValidationError]]: +) -> Response[Union[Any, HTTPValidationError, None]]: """Path with callback Try sending a request related to a callback @@ -132,7 +132,7 @@ async def asyncio_detailed( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[Union[Any, HTTPValidationError]] + Response[Union[Any, HTTPValidationError, None]] """ kwargs = _get_kwargs( @@ -150,7 +150,7 @@ async def asyncio( *, client: Client, json_body: AModel, -) -> Optional[Union[Any, HTTPValidationError]]: +) -> Union[Any, HTTPValidationError, None]: """Path with callback Try sending a request related to a callback @@ -163,7 +163,7 @@ async def asyncio( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Union[Any, HTTPValidationError] + Union[Any, HTTPValidationError, None] """ return ( 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 dd7a11aef..20ffd595c 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/tests/defaults_tests_defaults_post.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/tests/defaults_tests_defaults_post.py @@ -1,6 +1,6 @@ import datetime from http import HTTPStatus -from typing import Any, Dict, List, Optional, Union +from typing import Any, Dict, List, Union import httpx from dateutil.parser import isoparse @@ -100,7 +100,7 @@ def _get_kwargs( } -def _parse_response(*, client: Client, response: httpx.Response) -> Optional[Union[Any, HTTPValidationError]]: +def _parse_response(*, client: Client, response: httpx.Response) -> Union[Any, HTTPValidationError, None]: if response.status_code == HTTPStatus.OK: response_200 = response.json() return response_200 @@ -114,7 +114,7 @@ def _parse_response(*, client: Client, response: httpx.Response) -> Optional[Uni return None -def _build_response(*, client: Client, response: httpx.Response) -> Response[Union[Any, HTTPValidationError]]: +def _build_response(*, client: Client, response: httpx.Response) -> Response[Union[Any, HTTPValidationError, None]]: return Response( status_code=HTTPStatus(response.status_code), content=response.content, @@ -137,7 +137,7 @@ def sync_detailed( enum_prop: AnEnum, model_prop: "ModelWithUnionProperty", required_model_prop: "ModelWithUnionProperty", -) -> Response[Union[Any, HTTPValidationError]]: +) -> Response[Union[Any, HTTPValidationError, None]]: """Defaults Args: @@ -158,7 +158,7 @@ def sync_detailed( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[Union[Any, HTTPValidationError]] + Response[Union[Any, HTTPValidationError, None]] """ kwargs = _get_kwargs( @@ -198,7 +198,7 @@ def sync( enum_prop: AnEnum, model_prop: "ModelWithUnionProperty", required_model_prop: "ModelWithUnionProperty", -) -> Optional[Union[Any, HTTPValidationError]]: +) -> Union[Any, HTTPValidationError, None]: """Defaults Args: @@ -219,7 +219,7 @@ def sync( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Union[Any, HTTPValidationError] + Union[Any, HTTPValidationError, None] """ return sync_detailed( @@ -252,7 +252,7 @@ async def asyncio_detailed( enum_prop: AnEnum, model_prop: "ModelWithUnionProperty", required_model_prop: "ModelWithUnionProperty", -) -> Response[Union[Any, HTTPValidationError]]: +) -> Response[Union[Any, HTTPValidationError, None]]: """Defaults Args: @@ -273,7 +273,7 @@ async def asyncio_detailed( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[Union[Any, HTTPValidationError]] + Response[Union[Any, HTTPValidationError, None]] """ kwargs = _get_kwargs( @@ -311,7 +311,7 @@ async def asyncio( enum_prop: AnEnum, model_prop: "ModelWithUnionProperty", required_model_prop: "ModelWithUnionProperty", -) -> Optional[Union[Any, HTTPValidationError]]: +) -> Union[Any, HTTPValidationError, None]: """Defaults Args: @@ -332,7 +332,7 @@ async def asyncio( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Union[Any, HTTPValidationError] + Union[Any, HTTPValidationError, None] """ return ( diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/tests/description_with_backslash.py b/end_to_end_tests/golden-record/my_test_api_client/api/tests/description_with_backslash.py index a27d3b34e..da69a20b6 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/tests/description_with_backslash.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/tests/description_with_backslash.py @@ -1,5 +1,5 @@ from http import HTTPStatus -from typing import Any, Dict, Optional +from typing import Any, Dict import httpx @@ -27,7 +27,7 @@ def _get_kwargs( } -def _parse_response(*, client: Client, response: httpx.Response) -> Optional[None]: +def _parse_response(*, client: Client, response: httpx.Response) -> None: if response.status_code == HTTPStatus.OK: return None if client.raise_on_unexpected_status: 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 266e5eb41..5949303e8 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/tests/get_basic_list_of_booleans.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/tests/get_basic_list_of_booleans.py @@ -1,5 +1,5 @@ from http import HTTPStatus -from typing import Any, Dict, List, Optional, cast +from typing import Any, Dict, List, Union, cast import httpx @@ -27,7 +27,7 @@ def _get_kwargs( } -def _parse_response(*, client: Client, response: httpx.Response) -> Optional[List[bool]]: +def _parse_response(*, client: Client, response: httpx.Response) -> Union[List[bool], None]: if response.status_code == HTTPStatus.OK: response_200 = cast(List[bool], response.json()) @@ -38,7 +38,7 @@ def _parse_response(*, client: Client, response: httpx.Response) -> Optional[Lis return None -def _build_response(*, client: Client, response: httpx.Response) -> Response[List[bool]]: +def _build_response(*, client: Client, response: httpx.Response) -> Response[Union[List[bool], None]]: return Response( status_code=HTTPStatus(response.status_code), content=response.content, @@ -50,7 +50,7 @@ def _build_response(*, client: Client, response: httpx.Response) -> Response[Lis def sync_detailed( *, client: Client, -) -> Response[List[bool]]: +) -> Response[Union[List[bool], None]]: """Get Basic List Of Booleans Get a list of booleans @@ -60,7 +60,7 @@ def sync_detailed( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[List[bool]] + Response[Union[List[bool], None]] """ kwargs = _get_kwargs( @@ -78,7 +78,7 @@ def sync_detailed( def sync( *, client: Client, -) -> Optional[List[bool]]: +) -> Union[List[bool], None]: """Get Basic List Of Booleans Get a list of booleans @@ -88,7 +88,7 @@ def sync( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - List[bool] + Union[List[bool], None] """ return sync_detailed( @@ -99,7 +99,7 @@ def sync( async def asyncio_detailed( *, client: Client, -) -> Response[List[bool]]: +) -> Response[Union[List[bool], None]]: """Get Basic List Of Booleans Get a list of booleans @@ -109,7 +109,7 @@ async def asyncio_detailed( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[List[bool]] + Response[Union[List[bool], None]] """ kwargs = _get_kwargs( @@ -125,7 +125,7 @@ async def asyncio_detailed( async def asyncio( *, client: Client, -) -> Optional[List[bool]]: +) -> Union[List[bool], None]: """Get Basic List Of Booleans Get a list of booleans @@ -135,7 +135,7 @@ async def asyncio( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - List[bool] + Union[List[bool], None] """ return ( 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 a1101a547..39c815052 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/tests/get_basic_list_of_floats.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/tests/get_basic_list_of_floats.py @@ -1,5 +1,5 @@ from http import HTTPStatus -from typing import Any, Dict, List, Optional, cast +from typing import Any, Dict, List, Union, cast import httpx @@ -27,7 +27,7 @@ def _get_kwargs( } -def _parse_response(*, client: Client, response: httpx.Response) -> Optional[List[float]]: +def _parse_response(*, client: Client, response: httpx.Response) -> Union[List[float], None]: if response.status_code == HTTPStatus.OK: response_200 = cast(List[float], response.json()) @@ -38,7 +38,7 @@ def _parse_response(*, client: Client, response: httpx.Response) -> Optional[Lis return None -def _build_response(*, client: Client, response: httpx.Response) -> Response[List[float]]: +def _build_response(*, client: Client, response: httpx.Response) -> Response[Union[List[float], None]]: return Response( status_code=HTTPStatus(response.status_code), content=response.content, @@ -50,7 +50,7 @@ def _build_response(*, client: Client, response: httpx.Response) -> Response[Lis def sync_detailed( *, client: Client, -) -> Response[List[float]]: +) -> Response[Union[List[float], None]]: """Get Basic List Of Floats Get a list of floats @@ -60,7 +60,7 @@ def sync_detailed( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[List[float]] + Response[Union[List[float], None]] """ kwargs = _get_kwargs( @@ -78,7 +78,7 @@ def sync_detailed( def sync( *, client: Client, -) -> Optional[List[float]]: +) -> Union[List[float], None]: """Get Basic List Of Floats Get a list of floats @@ -88,7 +88,7 @@ def sync( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - List[float] + Union[List[float], None] """ return sync_detailed( @@ -99,7 +99,7 @@ def sync( async def asyncio_detailed( *, client: Client, -) -> Response[List[float]]: +) -> Response[Union[List[float], None]]: """Get Basic List Of Floats Get a list of floats @@ -109,7 +109,7 @@ async def asyncio_detailed( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[List[float]] + Response[Union[List[float], None]] """ kwargs = _get_kwargs( @@ -125,7 +125,7 @@ async def asyncio_detailed( async def asyncio( *, client: Client, -) -> Optional[List[float]]: +) -> Union[List[float], None]: """Get Basic List Of Floats Get a list of floats @@ -135,7 +135,7 @@ async def asyncio( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - List[float] + Union[List[float], None] """ return ( 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 29627228c..c971d8863 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/tests/get_basic_list_of_integers.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/tests/get_basic_list_of_integers.py @@ -1,5 +1,5 @@ from http import HTTPStatus -from typing import Any, Dict, List, Optional, cast +from typing import Any, Dict, List, Union, cast import httpx @@ -27,7 +27,7 @@ def _get_kwargs( } -def _parse_response(*, client: Client, response: httpx.Response) -> Optional[List[int]]: +def _parse_response(*, client: Client, response: httpx.Response) -> Union[List[int], None]: if response.status_code == HTTPStatus.OK: response_200 = cast(List[int], response.json()) @@ -38,7 +38,7 @@ def _parse_response(*, client: Client, response: httpx.Response) -> Optional[Lis return None -def _build_response(*, client: Client, response: httpx.Response) -> Response[List[int]]: +def _build_response(*, client: Client, response: httpx.Response) -> Response[Union[List[int], None]]: return Response( status_code=HTTPStatus(response.status_code), content=response.content, @@ -50,7 +50,7 @@ def _build_response(*, client: Client, response: httpx.Response) -> Response[Lis def sync_detailed( *, client: Client, -) -> Response[List[int]]: +) -> Response[Union[List[int], None]]: """Get Basic List Of Integers Get a list of integers @@ -60,7 +60,7 @@ def sync_detailed( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[List[int]] + Response[Union[List[int], None]] """ kwargs = _get_kwargs( @@ -78,7 +78,7 @@ def sync_detailed( def sync( *, client: Client, -) -> Optional[List[int]]: +) -> Union[List[int], None]: """Get Basic List Of Integers Get a list of integers @@ -88,7 +88,7 @@ def sync( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - List[int] + Union[List[int], None] """ return sync_detailed( @@ -99,7 +99,7 @@ def sync( async def asyncio_detailed( *, client: Client, -) -> Response[List[int]]: +) -> Response[Union[List[int], None]]: """Get Basic List Of Integers Get a list of integers @@ -109,7 +109,7 @@ async def asyncio_detailed( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[List[int]] + Response[Union[List[int], None]] """ kwargs = _get_kwargs( @@ -125,7 +125,7 @@ async def asyncio_detailed( async def asyncio( *, client: Client, -) -> Optional[List[int]]: +) -> Union[List[int], None]: """Get Basic List Of Integers Get a list of integers @@ -135,7 +135,7 @@ async def asyncio( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - List[int] + Union[List[int], None] """ return ( 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 2c52de82b..b6e2ef9ef 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/tests/get_basic_list_of_strings.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/tests/get_basic_list_of_strings.py @@ -1,5 +1,5 @@ from http import HTTPStatus -from typing import Any, Dict, List, Optional, cast +from typing import Any, Dict, List, Union, cast import httpx @@ -27,7 +27,7 @@ def _get_kwargs( } -def _parse_response(*, client: Client, response: httpx.Response) -> Optional[List[str]]: +def _parse_response(*, client: Client, response: httpx.Response) -> Union[List[str], None]: if response.status_code == HTTPStatus.OK: response_200 = cast(List[str], response.json()) @@ -38,7 +38,7 @@ def _parse_response(*, client: Client, response: httpx.Response) -> Optional[Lis return None -def _build_response(*, client: Client, response: httpx.Response) -> Response[List[str]]: +def _build_response(*, client: Client, response: httpx.Response) -> Response[Union[List[str], None]]: return Response( status_code=HTTPStatus(response.status_code), content=response.content, @@ -50,7 +50,7 @@ def _build_response(*, client: Client, response: httpx.Response) -> Response[Lis def sync_detailed( *, client: Client, -) -> Response[List[str]]: +) -> Response[Union[List[str], None]]: """Get Basic List Of Strings Get a list of strings @@ -60,7 +60,7 @@ def sync_detailed( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[List[str]] + Response[Union[List[str], None]] """ kwargs = _get_kwargs( @@ -78,7 +78,7 @@ def sync_detailed( def sync( *, client: Client, -) -> Optional[List[str]]: +) -> Union[List[str], None]: """Get Basic List Of Strings Get a list of strings @@ -88,7 +88,7 @@ def sync( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - List[str] + Union[List[str], None] """ return sync_detailed( @@ -99,7 +99,7 @@ def sync( async def asyncio_detailed( *, client: Client, -) -> Response[List[str]]: +) -> Response[Union[List[str], None]]: """Get Basic List Of Strings Get a list of strings @@ -109,7 +109,7 @@ async def asyncio_detailed( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[List[str]] + Response[Union[List[str], None]] """ kwargs = _get_kwargs( @@ -125,7 +125,7 @@ async def asyncio_detailed( async def asyncio( *, client: Client, -) -> Optional[List[str]]: +) -> Union[List[str], None]: """Get Basic List Of Strings Get a list of strings @@ -135,7 +135,7 @@ async def asyncio( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - List[str] + Union[List[str], None] """ return ( 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 cef38f2ff..d3069f3c4 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 @@ -71,9 +71,7 @@ def _get_kwargs( } -def _parse_response( - *, client: Client, response: httpx.Response -) -> Optional[Union[HTTPValidationError, List["AModel"]]]: +def _parse_response(*, client: Client, response: httpx.Response) -> Union[HTTPValidationError, List["AModel"], None]: if response.status_code == HTTPStatus.OK: response_200 = [] _response_200 = response.json() @@ -99,7 +97,7 @@ def _parse_response( def _build_response( *, client: Client, response: httpx.Response -) -> Response[Union[HTTPValidationError, List["AModel"]]]: +) -> Response[Union[HTTPValidationError, List["AModel"], None]]: return Response( status_code=HTTPStatus(response.status_code), content=response.content, @@ -115,7 +113,7 @@ def sync_detailed( an_enum_value_with_null: List[Optional[AnEnumWithNull]], an_enum_value_with_only_null: List[None], some_date: Union[datetime.date, datetime.datetime], -) -> Response[Union[HTTPValidationError, List["AModel"]]]: +) -> Response[Union[HTTPValidationError, List["AModel"], None]]: """Get List Get a list of things @@ -131,7 +129,7 @@ def sync_detailed( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[Union[HTTPValidationError, List['AModel']]] + Response[Union[HTTPValidationError, List['AModel'], None]] """ kwargs = _get_kwargs( @@ -157,7 +155,7 @@ def sync( an_enum_value_with_null: List[Optional[AnEnumWithNull]], an_enum_value_with_only_null: List[None], some_date: Union[datetime.date, datetime.datetime], -) -> Optional[Union[HTTPValidationError, List["AModel"]]]: +) -> Union[HTTPValidationError, List["AModel"], None]: """Get List Get a list of things @@ -173,7 +171,7 @@ def sync( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Union[HTTPValidationError, List['AModel']] + Union[HTTPValidationError, List['AModel'], None] """ return sync_detailed( @@ -192,7 +190,7 @@ async def asyncio_detailed( an_enum_value_with_null: List[Optional[AnEnumWithNull]], an_enum_value_with_only_null: List[None], some_date: Union[datetime.date, datetime.datetime], -) -> Response[Union[HTTPValidationError, List["AModel"]]]: +) -> Response[Union[HTTPValidationError, List["AModel"], None]]: """Get List Get a list of things @@ -208,7 +206,7 @@ async def asyncio_detailed( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[Union[HTTPValidationError, List['AModel']]] + Response[Union[HTTPValidationError, List['AModel'], None]] """ kwargs = _get_kwargs( @@ -232,7 +230,7 @@ async def asyncio( an_enum_value_with_null: List[Optional[AnEnumWithNull]], an_enum_value_with_only_null: List[None], some_date: Union[datetime.date, datetime.datetime], -) -> Optional[Union[HTTPValidationError, List["AModel"]]]: +) -> Union[HTTPValidationError, List["AModel"], None]: """Get List Get a list of things @@ -248,7 +246,7 @@ async def asyncio( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Union[HTTPValidationError, List['AModel']] + Union[HTTPValidationError, List['AModel'], None] """ return ( 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 8b01e01ec..d2a051d07 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/tests/int_enum_tests_int_enum_post.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/tests/int_enum_tests_int_enum_post.py @@ -1,5 +1,5 @@ from http import HTTPStatus -from typing import Any, Dict, Optional, Union +from typing import Any, Dict, Union import httpx @@ -38,7 +38,7 @@ def _get_kwargs( } -def _parse_response(*, client: Client, response: httpx.Response) -> Optional[Union[Any, HTTPValidationError]]: +def _parse_response(*, client: Client, response: httpx.Response) -> Union[Any, HTTPValidationError, None]: if response.status_code == HTTPStatus.OK: response_200 = response.json() return response_200 @@ -52,7 +52,7 @@ def _parse_response(*, client: Client, response: httpx.Response) -> Optional[Uni return None -def _build_response(*, client: Client, response: httpx.Response) -> Response[Union[Any, HTTPValidationError]]: +def _build_response(*, client: Client, response: httpx.Response) -> Response[Union[Any, HTTPValidationError, None]]: return Response( status_code=HTTPStatus(response.status_code), content=response.content, @@ -65,7 +65,7 @@ def sync_detailed( *, client: Client, int_enum: AnIntEnum, -) -> Response[Union[Any, HTTPValidationError]]: +) -> Response[Union[Any, HTTPValidationError, None]]: """Int Enum Args: @@ -76,7 +76,7 @@ def sync_detailed( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[Union[Any, HTTPValidationError]] + Response[Union[Any, HTTPValidationError, None]] """ kwargs = _get_kwargs( @@ -96,7 +96,7 @@ def sync( *, client: Client, int_enum: AnIntEnum, -) -> Optional[Union[Any, HTTPValidationError]]: +) -> Union[Any, HTTPValidationError, None]: """Int Enum Args: @@ -107,7 +107,7 @@ def sync( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Union[Any, HTTPValidationError] + Union[Any, HTTPValidationError, None] """ return sync_detailed( @@ -120,7 +120,7 @@ async def asyncio_detailed( *, client: Client, int_enum: AnIntEnum, -) -> Response[Union[Any, HTTPValidationError]]: +) -> Response[Union[Any, HTTPValidationError, None]]: """Int Enum Args: @@ -131,7 +131,7 @@ async def asyncio_detailed( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[Union[Any, HTTPValidationError]] + Response[Union[Any, HTTPValidationError, None]] """ kwargs = _get_kwargs( @@ -149,7 +149,7 @@ async def asyncio( *, client: Client, int_enum: AnIntEnum, -) -> Optional[Union[Any, HTTPValidationError]]: +) -> Union[Any, HTTPValidationError, None]: """Int Enum Args: @@ -160,7 +160,7 @@ async def asyncio( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Union[Any, HTTPValidationError] + Union[Any, HTTPValidationError, None] """ return ( 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 6ec1ab31f..ae5f5630c 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/tests/json_body_tests_json_body_post.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/tests/json_body_tests_json_body_post.py @@ -1,5 +1,5 @@ from http import HTTPStatus -from typing import Any, Dict, Optional, Union +from typing import Any, Dict, Union import httpx @@ -33,7 +33,7 @@ def _get_kwargs( } -def _parse_response(*, client: Client, response: httpx.Response) -> Optional[Union[Any, HTTPValidationError]]: +def _parse_response(*, client: Client, response: httpx.Response) -> Union[Any, HTTPValidationError, None]: if response.status_code == HTTPStatus.OK: response_200 = response.json() return response_200 @@ -47,7 +47,7 @@ def _parse_response(*, client: Client, response: httpx.Response) -> Optional[Uni return None -def _build_response(*, client: Client, response: httpx.Response) -> Response[Union[Any, HTTPValidationError]]: +def _build_response(*, client: Client, response: httpx.Response) -> Response[Union[Any, HTTPValidationError, None]]: return Response( status_code=HTTPStatus(response.status_code), content=response.content, @@ -60,7 +60,7 @@ def sync_detailed( *, client: Client, json_body: AModel, -) -> Response[Union[Any, HTTPValidationError]]: +) -> Response[Union[Any, HTTPValidationError, None]]: """Json Body Try sending a JSON body @@ -73,7 +73,7 @@ def sync_detailed( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[Union[Any, HTTPValidationError]] + Response[Union[Any, HTTPValidationError, None]] """ kwargs = _get_kwargs( @@ -93,7 +93,7 @@ def sync( *, client: Client, json_body: AModel, -) -> Optional[Union[Any, HTTPValidationError]]: +) -> Union[Any, HTTPValidationError, None]: """Json Body Try sending a JSON body @@ -106,7 +106,7 @@ def sync( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Union[Any, HTTPValidationError] + Union[Any, HTTPValidationError, None] """ return sync_detailed( @@ -119,7 +119,7 @@ async def asyncio_detailed( *, client: Client, json_body: AModel, -) -> Response[Union[Any, HTTPValidationError]]: +) -> Response[Union[Any, HTTPValidationError, None]]: """Json Body Try sending a JSON body @@ -132,7 +132,7 @@ async def asyncio_detailed( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[Union[Any, HTTPValidationError]] + Response[Union[Any, HTTPValidationError, None]] """ kwargs = _get_kwargs( @@ -150,7 +150,7 @@ async def asyncio( *, client: Client, json_body: AModel, -) -> Optional[Union[Any, HTTPValidationError]]: +) -> Union[Any, HTTPValidationError, None]: """Json Body Try sending a JSON body @@ -163,7 +163,7 @@ async def asyncio( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Union[Any, HTTPValidationError] + Union[Any, HTTPValidationError, None] """ return ( 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 8f5a03aba..1c6c58f84 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,5 +1,5 @@ from http import HTTPStatus -from typing import Any, Dict, Optional +from typing import Any, Dict, Union import httpx @@ -27,7 +27,7 @@ def _get_kwargs( } -def _parse_response(*, client: Client, response: httpx.Response) -> Optional[Any]: +def _parse_response(*, client: Client, response: httpx.Response) -> Union[Any, None]: if response.status_code == HTTPStatus.OK: response_200 = response.json() return response_200 @@ -37,7 +37,7 @@ def _parse_response(*, client: Client, response: httpx.Response) -> Optional[Any return None -def _build_response(*, client: Client, response: httpx.Response) -> Response[Any]: +def _build_response(*, client: Client, response: httpx.Response) -> Response[Union[Any, None]]: return Response( status_code=HTTPStatus(response.status_code), content=response.content, @@ -49,7 +49,7 @@ def _build_response(*, client: Client, response: httpx.Response) -> Response[Any def sync_detailed( *, client: Client, -) -> Response[Any]: +) -> Response[Union[Any, None]]: """No Response Raises: @@ -57,7 +57,7 @@ def sync_detailed( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[Any] + Response[Union[Any, None]] """ kwargs = _get_kwargs( @@ -75,7 +75,7 @@ def sync_detailed( def sync( *, client: Client, -) -> Optional[Any]: +) -> Union[Any, None]: """No Response Raises: @@ -83,7 +83,7 @@ def sync( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[Any] + Union[Any, None] """ return sync_detailed( @@ -94,7 +94,7 @@ def sync( async def asyncio_detailed( *, client: Client, -) -> Response[Any]: +) -> Response[Union[Any, None]]: """No Response Raises: @@ -102,7 +102,7 @@ async def asyncio_detailed( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[Any] + Response[Union[Any, None]] """ kwargs = _get_kwargs( @@ -118,7 +118,7 @@ async def asyncio_detailed( async def asyncio( *, client: Client, -) -> Optional[Any]: +) -> Union[Any, None]: """No Response Raises: @@ -126,7 +126,7 @@ async def asyncio( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[Any] + Union[Any, None] """ return ( 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 68e0a7fd5..cc40ce48b 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/tests/octet_stream_tests_octet_stream_get.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/tests/octet_stream_tests_octet_stream_get.py @@ -1,6 +1,6 @@ from http import HTTPStatus from io import BytesIO -from typing import Any, Dict, Optional +from typing import Any, Dict, Union import httpx @@ -28,7 +28,7 @@ def _get_kwargs( } -def _parse_response(*, client: Client, response: httpx.Response) -> Optional[File]: +def _parse_response(*, client: Client, response: httpx.Response) -> Union[File, None]: if response.status_code == HTTPStatus.OK: response_200 = File(payload=BytesIO(response.content)) @@ -39,7 +39,7 @@ def _parse_response(*, client: Client, response: httpx.Response) -> Optional[Fil return None -def _build_response(*, client: Client, response: httpx.Response) -> Response[File]: +def _build_response(*, client: Client, response: httpx.Response) -> Response[Union[File, None]]: return Response( status_code=HTTPStatus(response.status_code), content=response.content, @@ -51,7 +51,7 @@ def _build_response(*, client: Client, response: httpx.Response) -> Response[Fil def sync_detailed( *, client: Client, -) -> Response[File]: +) -> Response[Union[File, None]]: """Octet Stream Raises: @@ -59,7 +59,7 @@ def sync_detailed( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[File] + Response[Union[File, None]] """ kwargs = _get_kwargs( @@ -77,7 +77,7 @@ def sync_detailed( def sync( *, client: Client, -) -> Optional[File]: +) -> Union[File, None]: """Octet Stream Raises: @@ -85,7 +85,7 @@ def sync( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - File + Union[File, None] """ return sync_detailed( @@ -96,7 +96,7 @@ def sync( async def asyncio_detailed( *, client: Client, -) -> Response[File]: +) -> Response[Union[File, None]]: """Octet Stream Raises: @@ -104,7 +104,7 @@ async def asyncio_detailed( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[File] + Response[Union[File, None]] """ kwargs = _get_kwargs( @@ -120,7 +120,7 @@ async def asyncio_detailed( async def asyncio( *, client: Client, -) -> Optional[File]: +) -> Union[File, None]: """Octet Stream Raises: @@ -128,7 +128,7 @@ async def asyncio( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - File + Union[File, None] """ return ( diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/tests/post_form_data.py b/end_to_end_tests/golden-record/my_test_api_client/api/tests/post_form_data.py index 3d5115610..cba1a5a29 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/tests/post_form_data.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/tests/post_form_data.py @@ -1,5 +1,5 @@ from http import HTTPStatus -from typing import Any, Dict, Optional +from typing import Any, Dict, Union import httpx @@ -30,7 +30,7 @@ def _get_kwargs( } -def _parse_response(*, client: Client, response: httpx.Response) -> Optional[Any]: +def _parse_response(*, client: Client, response: httpx.Response) -> Union[Any, None]: if response.status_code == HTTPStatus.OK: response_200 = response.json() return response_200 @@ -40,7 +40,7 @@ def _parse_response(*, client: Client, response: httpx.Response) -> Optional[Any return None -def _build_response(*, client: Client, response: httpx.Response) -> Response[Any]: +def _build_response(*, client: Client, response: httpx.Response) -> Response[Union[Any, None]]: return Response( status_code=HTTPStatus(response.status_code), content=response.content, @@ -53,7 +53,7 @@ def sync_detailed( *, client: Client, form_data: AFormData, -) -> Response[Any]: +) -> Response[Union[Any, None]]: """Post form data Post form data @@ -63,7 +63,7 @@ def sync_detailed( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[Any] + Response[Union[Any, None]] """ kwargs = _get_kwargs( @@ -83,7 +83,7 @@ def sync( *, client: Client, form_data: AFormData, -) -> Optional[Any]: +) -> Union[Any, None]: """Post form data Post form data @@ -93,7 +93,7 @@ def sync( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[Any] + Union[Any, None] """ return sync_detailed( @@ -106,7 +106,7 @@ async def asyncio_detailed( *, client: Client, form_data: AFormData, -) -> Response[Any]: +) -> Response[Union[Any, None]]: """Post form data Post form data @@ -116,7 +116,7 @@ async def asyncio_detailed( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[Any] + Response[Union[Any, None]] """ kwargs = _get_kwargs( @@ -134,7 +134,7 @@ async def asyncio( *, client: Client, form_data: AFormData, -) -> Optional[Any]: +) -> Union[Any, None]: """Post form data Post form data @@ -144,7 +144,7 @@ async def asyncio( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[Any] + Union[Any, None] """ return ( diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/tests/post_form_data_inline.py b/end_to_end_tests/golden-record/my_test_api_client/api/tests/post_form_data_inline.py index 0f8f3dc5a..7443afa9a 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/tests/post_form_data_inline.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/tests/post_form_data_inline.py @@ -1,5 +1,5 @@ from http import HTTPStatus -from typing import Any, Dict, Optional +from typing import Any, Dict, Union import httpx @@ -30,7 +30,7 @@ def _get_kwargs( } -def _parse_response(*, client: Client, response: httpx.Response) -> Optional[Any]: +def _parse_response(*, client: Client, response: httpx.Response) -> Union[Any, None]: if response.status_code == HTTPStatus.OK: response_200 = response.json() return response_200 @@ -40,7 +40,7 @@ def _parse_response(*, client: Client, response: httpx.Response) -> Optional[Any return None -def _build_response(*, client: Client, response: httpx.Response) -> Response[Any]: +def _build_response(*, client: Client, response: httpx.Response) -> Response[Union[Any, None]]: return Response( status_code=HTTPStatus(response.status_code), content=response.content, @@ -53,7 +53,7 @@ def sync_detailed( *, client: Client, form_data: PostFormDataInlineData, -) -> Response[Any]: +) -> Response[Union[Any, None]]: """Post form data (inline schema) Post form data (inline schema) @@ -63,7 +63,7 @@ def sync_detailed( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[Any] + Response[Union[Any, None]] """ kwargs = _get_kwargs( @@ -83,7 +83,7 @@ def sync( *, client: Client, form_data: PostFormDataInlineData, -) -> Optional[Any]: +) -> Union[Any, None]: """Post form data (inline schema) Post form data (inline schema) @@ -93,7 +93,7 @@ def sync( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[Any] + Union[Any, None] """ return sync_detailed( @@ -106,7 +106,7 @@ async def asyncio_detailed( *, client: Client, form_data: PostFormDataInlineData, -) -> Response[Any]: +) -> Response[Union[Any, None]]: """Post form data (inline schema) Post form data (inline schema) @@ -116,7 +116,7 @@ async def asyncio_detailed( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[Any] + Response[Union[Any, None]] """ kwargs = _get_kwargs( @@ -134,7 +134,7 @@ async def asyncio( *, client: Client, form_data: PostFormDataInlineData, -) -> Optional[Any]: +) -> Union[Any, None]: """Post form data (inline schema) Post form data (inline schema) @@ -144,7 +144,7 @@ async def asyncio( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[Any] + Union[Any, None] """ return ( diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/tests/post_tests_json_body_string.py b/end_to_end_tests/golden-record/my_test_api_client/api/tests/post_tests_json_body_string.py index 289eac03c..7edaac84f 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/tests/post_tests_json_body_string.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/tests/post_tests_json_body_string.py @@ -1,5 +1,5 @@ from http import HTTPStatus -from typing import Any, Dict, Optional, Union, cast +from typing import Any, Dict, Union, cast import httpx @@ -32,7 +32,7 @@ def _get_kwargs( } -def _parse_response(*, client: Client, response: httpx.Response) -> Optional[Union[HTTPValidationError, str]]: +def _parse_response(*, client: Client, response: httpx.Response) -> Union[HTTPValidationError, None, str]: if response.status_code == HTTPStatus.OK: response_200 = cast(str, response.json()) return response_200 @@ -46,7 +46,7 @@ def _parse_response(*, client: Client, response: httpx.Response) -> Optional[Uni return None -def _build_response(*, client: Client, response: httpx.Response) -> Response[Union[HTTPValidationError, str]]: +def _build_response(*, client: Client, response: httpx.Response) -> Response[Union[HTTPValidationError, None, str]]: return Response( status_code=HTTPStatus(response.status_code), content=response.content, @@ -59,7 +59,7 @@ def sync_detailed( *, client: Client, json_body: str, -) -> Response[Union[HTTPValidationError, str]]: +) -> Response[Union[HTTPValidationError, None, str]]: """Json Body Which is String Args: @@ -70,7 +70,7 @@ def sync_detailed( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[Union[HTTPValidationError, str]] + Response[Union[HTTPValidationError, None, str]] """ kwargs = _get_kwargs( @@ -90,7 +90,7 @@ def sync( *, client: Client, json_body: str, -) -> Optional[Union[HTTPValidationError, str]]: +) -> Union[HTTPValidationError, None, str]: """Json Body Which is String Args: @@ -101,7 +101,7 @@ def sync( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Union[HTTPValidationError, str] + Union[HTTPValidationError, None, str] """ return sync_detailed( @@ -114,7 +114,7 @@ async def asyncio_detailed( *, client: Client, json_body: str, -) -> Response[Union[HTTPValidationError, str]]: +) -> Response[Union[HTTPValidationError, None, str]]: """Json Body Which is String Args: @@ -125,7 +125,7 @@ async def asyncio_detailed( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[Union[HTTPValidationError, str]] + Response[Union[HTTPValidationError, None, str]] """ kwargs = _get_kwargs( @@ -143,7 +143,7 @@ async def asyncio( *, client: Client, json_body: str, -) -> Optional[Union[HTTPValidationError, str]]: +) -> Union[HTTPValidationError, None, str]: """Json Body Which is String Args: @@ -154,7 +154,7 @@ async def asyncio( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Union[HTTPValidationError, str] + Union[HTTPValidationError, None, str] """ return ( 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 f7ce0eda3..23a9a5f0b 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/tests/test_inline_objects.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/tests/test_inline_objects.py @@ -1,5 +1,5 @@ from http import HTTPStatus -from typing import Any, Dict, Optional +from typing import Any, Dict, Union import httpx @@ -33,7 +33,7 @@ def _get_kwargs( } -def _parse_response(*, client: Client, response: httpx.Response) -> Optional[TestInlineObjectsResponse200]: +def _parse_response(*, client: Client, response: httpx.Response) -> Union[None, TestInlineObjectsResponse200]: if response.status_code == HTTPStatus.OK: response_200 = TestInlineObjectsResponse200.from_dict(response.json()) @@ -44,7 +44,7 @@ def _parse_response(*, client: Client, response: httpx.Response) -> Optional[Tes return None -def _build_response(*, client: Client, response: httpx.Response) -> Response[TestInlineObjectsResponse200]: +def _build_response(*, client: Client, response: httpx.Response) -> Response[Union[None, TestInlineObjectsResponse200]]: return Response( status_code=HTTPStatus(response.status_code), content=response.content, @@ -57,7 +57,7 @@ def sync_detailed( *, client: Client, json_body: TestInlineObjectsJsonBody, -) -> Response[TestInlineObjectsResponse200]: +) -> Response[Union[None, TestInlineObjectsResponse200]]: """Test Inline Objects Args: @@ -68,7 +68,7 @@ def sync_detailed( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[TestInlineObjectsResponse200] + Response[Union[None, TestInlineObjectsResponse200]] """ kwargs = _get_kwargs( @@ -88,7 +88,7 @@ def sync( *, client: Client, json_body: TestInlineObjectsJsonBody, -) -> Optional[TestInlineObjectsResponse200]: +) -> Union[None, TestInlineObjectsResponse200]: """Test Inline Objects Args: @@ -99,7 +99,7 @@ def sync( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - TestInlineObjectsResponse200 + Union[None, TestInlineObjectsResponse200] """ return sync_detailed( @@ -112,7 +112,7 @@ async def asyncio_detailed( *, client: Client, json_body: TestInlineObjectsJsonBody, -) -> Response[TestInlineObjectsResponse200]: +) -> Response[Union[None, TestInlineObjectsResponse200]]: """Test Inline Objects Args: @@ -123,7 +123,7 @@ async def asyncio_detailed( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[TestInlineObjectsResponse200] + Response[Union[None, TestInlineObjectsResponse200]] """ kwargs = _get_kwargs( @@ -141,7 +141,7 @@ async def asyncio( *, client: Client, json_body: TestInlineObjectsJsonBody, -) -> Optional[TestInlineObjectsResponse200]: +) -> Union[None, TestInlineObjectsResponse200]: """Test Inline Objects Args: @@ -152,7 +152,7 @@ async def asyncio( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - TestInlineObjectsResponse200 + Union[None, TestInlineObjectsResponse200] """ return ( 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 7d4dd9367..2a4988965 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,5 +1,5 @@ from http import HTTPStatus -from typing import Any, Dict, Optional, Union +from typing import Any, Dict, Union import httpx @@ -30,7 +30,7 @@ def _get_kwargs( } -def _parse_response(*, client: Client, response: httpx.Response) -> Optional[Union[Any, None]]: +def _parse_response(*, client: Client, response: httpx.Response) -> Union[Any, None]: if response.status_code == HTTPStatus.OK: response_200 = response.json() return response_200 @@ -89,7 +89,7 @@ def sync( *, client: Client, my_token: str, -) -> Optional[Union[Any, None]]: +) -> Union[Any, None]: """TOKEN_WITH_COOKIE Test optional cookie parameters @@ -102,7 +102,7 @@ def sync( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[Union[Any, None]] + Union[Any, None] """ return sync_detailed( @@ -146,7 +146,7 @@ async def asyncio( *, client: Client, my_token: str, -) -> Optional[Union[Any, None]]: +) -> Union[Any, None]: """TOKEN_WITH_COOKIE Test optional cookie parameters @@ -159,7 +159,7 @@ async def asyncio( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[Union[Any, None]] + Union[Any, None] """ return ( 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 3fbaa44b4..87780172e 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,5 +1,5 @@ from http import HTTPStatus -from typing import Any, Dict, Optional +from typing import Any, Dict, Union import httpx @@ -27,7 +27,7 @@ def _get_kwargs( } -def _parse_response(*, client: Client, response: httpx.Response) -> Optional[Any]: +def _parse_response(*, client: Client, response: httpx.Response) -> Union[Any, None]: if response.status_code == HTTPStatus.OK: response_200 = response.json() return response_200 @@ -37,7 +37,7 @@ def _parse_response(*, client: Client, response: httpx.Response) -> Optional[Any return None -def _build_response(*, client: Client, response: httpx.Response) -> Response[Any]: +def _build_response(*, client: Client, response: httpx.Response) -> Response[Union[Any, None]]: return Response( status_code=HTTPStatus(response.status_code), content=response.content, @@ -49,7 +49,7 @@ def _build_response(*, client: Client, response: httpx.Response) -> Response[Any def sync_detailed( *, client: Client, -) -> Response[Any]: +) -> Response[Union[Any, None]]: """Unsupported Content Raises: @@ -57,7 +57,7 @@ def sync_detailed( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[Any] + Response[Union[Any, None]] """ kwargs = _get_kwargs( @@ -75,7 +75,7 @@ def sync_detailed( def sync( *, client: Client, -) -> Optional[Any]: +) -> Union[Any, None]: """Unsupported Content Raises: @@ -83,7 +83,7 @@ def sync( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[Any] + Union[Any, None] """ return sync_detailed( @@ -94,7 +94,7 @@ def sync( async def asyncio_detailed( *, client: Client, -) -> Response[Any]: +) -> Response[Union[Any, None]]: """Unsupported Content Raises: @@ -102,7 +102,7 @@ async def asyncio_detailed( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[Any] + Response[Union[Any, None]] """ kwargs = _get_kwargs( @@ -118,7 +118,7 @@ async def asyncio_detailed( async def asyncio( *, client: Client, -) -> Optional[Any]: +) -> Union[Any, None]: """Unsupported Content Raises: @@ -126,7 +126,7 @@ async def asyncio( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[Any] + Union[Any, None] """ return ( 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 65bf0f6cd..f6db55568 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/tests/upload_file_tests_upload_post.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/tests/upload_file_tests_upload_post.py @@ -1,5 +1,5 @@ from http import HTTPStatus -from typing import Any, Dict, Optional, Union +from typing import Any, Dict, Union import httpx @@ -33,7 +33,7 @@ def _get_kwargs( } -def _parse_response(*, client: Client, response: httpx.Response) -> Optional[Union[Any, HTTPValidationError]]: +def _parse_response(*, client: Client, response: httpx.Response) -> Union[Any, HTTPValidationError, None]: if response.status_code == HTTPStatus.OK: response_200 = response.json() return response_200 @@ -47,7 +47,7 @@ def _parse_response(*, client: Client, response: httpx.Response) -> Optional[Uni return None -def _build_response(*, client: Client, response: httpx.Response) -> Response[Union[Any, HTTPValidationError]]: +def _build_response(*, client: Client, response: httpx.Response) -> Response[Union[Any, HTTPValidationError, None]]: return Response( status_code=HTTPStatus(response.status_code), content=response.content, @@ -60,7 +60,7 @@ def sync_detailed( *, client: Client, multipart_data: BodyUploadFileTestsUploadPost, -) -> Response[Union[Any, HTTPValidationError]]: +) -> Response[Union[Any, HTTPValidationError, None]]: """Upload File Upload a file @@ -73,7 +73,7 @@ def sync_detailed( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[Union[Any, HTTPValidationError]] + Response[Union[Any, HTTPValidationError, None]] """ kwargs = _get_kwargs( @@ -93,7 +93,7 @@ def sync( *, client: Client, multipart_data: BodyUploadFileTestsUploadPost, -) -> Optional[Union[Any, HTTPValidationError]]: +) -> Union[Any, HTTPValidationError, None]: """Upload File Upload a file @@ -106,7 +106,7 @@ def sync( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Union[Any, HTTPValidationError] + Union[Any, HTTPValidationError, None] """ return sync_detailed( @@ -119,7 +119,7 @@ async def asyncio_detailed( *, client: Client, multipart_data: BodyUploadFileTestsUploadPost, -) -> Response[Union[Any, HTTPValidationError]]: +) -> Response[Union[Any, HTTPValidationError, None]]: """Upload File Upload a file @@ -132,7 +132,7 @@ async def asyncio_detailed( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[Union[Any, HTTPValidationError]] + Response[Union[Any, HTTPValidationError, None]] """ kwargs = _get_kwargs( @@ -150,7 +150,7 @@ async def asyncio( *, client: Client, multipart_data: BodyUploadFileTestsUploadPost, -) -> Optional[Union[Any, HTTPValidationError]]: +) -> Union[Any, HTTPValidationError, None]: """Upload File Upload a file @@ -163,7 +163,7 @@ async def asyncio( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Union[Any, HTTPValidationError] + Union[Any, HTTPValidationError, None] """ return ( diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/tests/upload_multiple_files_tests_upload_post.py b/end_to_end_tests/golden-record/my_test_api_client/api/tests/upload_multiple_files_tests_upload_post.py index 21797e239..3d9c74c84 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/tests/upload_multiple_files_tests_upload_post.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/tests/upload_multiple_files_tests_upload_post.py @@ -1,5 +1,5 @@ from http import HTTPStatus -from typing import Any, Dict, List, Optional, Union +from typing import Any, Dict, List, Union import httpx @@ -36,7 +36,7 @@ def _get_kwargs( } -def _parse_response(*, client: Client, response: httpx.Response) -> Optional[Union[Any, HTTPValidationError]]: +def _parse_response(*, client: Client, response: httpx.Response) -> Union[Any, HTTPValidationError, None]: if response.status_code == HTTPStatus.OK: response_200 = response.json() return response_200 @@ -50,7 +50,7 @@ def _parse_response(*, client: Client, response: httpx.Response) -> Optional[Uni return None -def _build_response(*, client: Client, response: httpx.Response) -> Response[Union[Any, HTTPValidationError]]: +def _build_response(*, client: Client, response: httpx.Response) -> Response[Union[Any, HTTPValidationError, None]]: return Response( status_code=HTTPStatus(response.status_code), content=response.content, @@ -63,7 +63,7 @@ def sync_detailed( *, client: Client, multipart_data: List[File], -) -> Response[Union[Any, HTTPValidationError]]: +) -> Response[Union[Any, HTTPValidationError, None]]: """Upload multiple files Upload several files in the same request @@ -76,7 +76,7 @@ def sync_detailed( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[Union[Any, HTTPValidationError]] + Response[Union[Any, HTTPValidationError, None]] """ kwargs = _get_kwargs( @@ -96,7 +96,7 @@ def sync( *, client: Client, multipart_data: List[File], -) -> Optional[Union[Any, HTTPValidationError]]: +) -> Union[Any, HTTPValidationError, None]: """Upload multiple files Upload several files in the same request @@ -109,7 +109,7 @@ def sync( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Union[Any, HTTPValidationError] + Union[Any, HTTPValidationError, None] """ return sync_detailed( @@ -122,7 +122,7 @@ async def asyncio_detailed( *, client: Client, multipart_data: List[File], -) -> Response[Union[Any, HTTPValidationError]]: +) -> Response[Union[Any, HTTPValidationError, None]]: """Upload multiple files Upload several files in the same request @@ -135,7 +135,7 @@ async def asyncio_detailed( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[Union[Any, HTTPValidationError]] + Response[Union[Any, HTTPValidationError, None]] """ kwargs = _get_kwargs( @@ -153,7 +153,7 @@ async def asyncio( *, client: Client, multipart_data: List[File], -) -> Optional[Union[Any, HTTPValidationError]]: +) -> Union[Any, HTTPValidationError, None]: """Upload multiple files Upload several files in the same request @@ -166,7 +166,7 @@ async def asyncio( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Union[Any, HTTPValidationError] + Union[Any, HTTPValidationError, None] """ return ( diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/true_/false_.py b/end_to_end_tests/golden-record/my_test_api_client/api/true_/false_.py index a140ffa0a..0086bd87f 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/true_/false_.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/true_/false_.py @@ -1,5 +1,5 @@ from http import HTTPStatus -from typing import Any, Dict, Optional +from typing import Any, Dict import httpx @@ -34,7 +34,7 @@ def _get_kwargs( } -def _parse_response(*, client: Client, response: httpx.Response) -> Optional[None]: +def _parse_response(*, client: Client, response: httpx.Response) -> None: if response.status_code == HTTPStatus.OK: return None if client.raise_on_unexpected_status: 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 230efea92..2e9f7b08c 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 @@ -38,7 +38,7 @@ class Response(Generic[T]): status_code: HTTPStatus content: bytes headers: MutableMapping[str, str] - parsed: Optional[T] + parsed: T __all__ = ["File", "Response", "FileJsonType"] diff --git a/integration-tests/integration_tests/api/body/post_body_multipart.py b/integration-tests/integration_tests/api/body/post_body_multipart.py index 9aaf6c388..265b3fa40 100644 --- a/integration-tests/integration_tests/api/body/post_body_multipart.py +++ b/integration-tests/integration_tests/api/body/post_body_multipart.py @@ -1,5 +1,5 @@ from http import HTTPStatus -from typing import Any, Dict, Optional, Union +from typing import Any, Dict, Union import httpx @@ -36,7 +36,7 @@ def _get_kwargs( def _parse_response( *, client: Client, response: httpx.Response -) -> Optional[Union[PostBodyMultipartResponse200, PublicError]]: +) -> Union[None, PostBodyMultipartResponse200, PublicError]: if response.status_code == HTTPStatus.OK: response_200 = PostBodyMultipartResponse200.from_dict(response.json()) @@ -53,7 +53,7 @@ def _parse_response( def _build_response( *, client: Client, response: httpx.Response -) -> Response[Union[PostBodyMultipartResponse200, PublicError]]: +) -> Response[Union[None, PostBodyMultipartResponse200, PublicError]]: return Response( status_code=HTTPStatus(response.status_code), content=response.content, @@ -66,7 +66,7 @@ def sync_detailed( *, client: Client, multipart_data: PostBodyMultipartMultipartData, -) -> Response[Union[PostBodyMultipartResponse200, PublicError]]: +) -> Response[Union[None, PostBodyMultipartResponse200, PublicError]]: """ Args: multipart_data (PostBodyMultipartMultipartData): @@ -76,7 +76,7 @@ def sync_detailed( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[Union[PostBodyMultipartResponse200, PublicError]] + Response[Union[None, PostBodyMultipartResponse200, PublicError]] """ kwargs = _get_kwargs( @@ -96,7 +96,7 @@ def sync( *, client: Client, multipart_data: PostBodyMultipartMultipartData, -) -> Optional[Union[PostBodyMultipartResponse200, PublicError]]: +) -> Union[None, PostBodyMultipartResponse200, PublicError]: """ Args: multipart_data (PostBodyMultipartMultipartData): @@ -106,7 +106,7 @@ def sync( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Union[PostBodyMultipartResponse200, PublicError] + Union[None, PostBodyMultipartResponse200, PublicError] """ return sync_detailed( @@ -119,7 +119,7 @@ async def asyncio_detailed( *, client: Client, multipart_data: PostBodyMultipartMultipartData, -) -> Response[Union[PostBodyMultipartResponse200, PublicError]]: +) -> Response[Union[None, PostBodyMultipartResponse200, PublicError]]: """ Args: multipart_data (PostBodyMultipartMultipartData): @@ -129,7 +129,7 @@ async def asyncio_detailed( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[Union[PostBodyMultipartResponse200, PublicError]] + Response[Union[None, PostBodyMultipartResponse200, PublicError]] """ kwargs = _get_kwargs( @@ -147,7 +147,7 @@ async def asyncio( *, client: Client, multipart_data: PostBodyMultipartMultipartData, -) -> Optional[Union[PostBodyMultipartResponse200, PublicError]]: +) -> Union[None, PostBodyMultipartResponse200, PublicError]: """ Args: multipart_data (PostBodyMultipartMultipartData): @@ -157,7 +157,7 @@ async def asyncio( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Union[PostBodyMultipartResponse200, PublicError] + Union[None, PostBodyMultipartResponse200, PublicError] """ return ( diff --git a/integration-tests/integration_tests/api/parameters/post_parameters_header.py b/integration-tests/integration_tests/api/parameters/post_parameters_header.py index 4d881bd0f..ef9bccff2 100644 --- a/integration-tests/integration_tests/api/parameters/post_parameters_header.py +++ b/integration-tests/integration_tests/api/parameters/post_parameters_header.py @@ -1,5 +1,5 @@ from http import HTTPStatus -from typing import Any, Dict, Optional, Union +from typing import Any, Dict, Union import httpx @@ -43,7 +43,7 @@ def _get_kwargs( def _parse_response( *, client: Client, response: httpx.Response -) -> Optional[Union[PostParametersHeaderResponse200, PublicError]]: +) -> Union[None, PostParametersHeaderResponse200, PublicError]: if response.status_code == HTTPStatus.OK: response_200 = PostParametersHeaderResponse200.from_dict(response.json()) @@ -60,7 +60,7 @@ def _parse_response( def _build_response( *, client: Client, response: httpx.Response -) -> Response[Union[PostParametersHeaderResponse200, PublicError]]: +) -> Response[Union[None, PostParametersHeaderResponse200, PublicError]]: return Response( status_code=HTTPStatus(response.status_code), content=response.content, @@ -76,7 +76,7 @@ def sync_detailed( string_header: str, number_header: float, integer_header: int, -) -> Response[Union[PostParametersHeaderResponse200, PublicError]]: +) -> Response[Union[None, PostParametersHeaderResponse200, PublicError]]: """ Args: boolean_header (bool): @@ -89,7 +89,7 @@ def sync_detailed( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[Union[PostParametersHeaderResponse200, PublicError]] + Response[Union[None, PostParametersHeaderResponse200, PublicError]] """ kwargs = _get_kwargs( @@ -115,7 +115,7 @@ def sync( string_header: str, number_header: float, integer_header: int, -) -> Optional[Union[PostParametersHeaderResponse200, PublicError]]: +) -> Union[None, PostParametersHeaderResponse200, PublicError]: """ Args: boolean_header (bool): @@ -128,7 +128,7 @@ def sync( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Union[PostParametersHeaderResponse200, PublicError] + Union[None, PostParametersHeaderResponse200, PublicError] """ return sync_detailed( @@ -147,7 +147,7 @@ async def asyncio_detailed( string_header: str, number_header: float, integer_header: int, -) -> Response[Union[PostParametersHeaderResponse200, PublicError]]: +) -> Response[Union[None, PostParametersHeaderResponse200, PublicError]]: """ Args: boolean_header (bool): @@ -160,7 +160,7 @@ async def asyncio_detailed( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[Union[PostParametersHeaderResponse200, PublicError]] + Response[Union[None, PostParametersHeaderResponse200, PublicError]] """ kwargs = _get_kwargs( @@ -184,7 +184,7 @@ async def asyncio( string_header: str, number_header: float, integer_header: int, -) -> Optional[Union[PostParametersHeaderResponse200, PublicError]]: +) -> Union[None, PostParametersHeaderResponse200, PublicError]: """ Args: boolean_header (bool): @@ -197,7 +197,7 @@ async def asyncio( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Union[PostParametersHeaderResponse200, PublicError] + Union[None, PostParametersHeaderResponse200, PublicError] """ return ( diff --git a/integration-tests/integration_tests/types.py b/integration-tests/integration_tests/types.py index 230efea92..2e9f7b08c 100644 --- a/integration-tests/integration_tests/types.py +++ b/integration-tests/integration_tests/types.py @@ -38,7 +38,7 @@ class Response(Generic[T]): status_code: HTTPStatus content: bytes headers: MutableMapping[str, str] - parsed: Optional[T] + parsed: T __all__ = ["File", "Response", "FileJsonType"] diff --git a/openapi_python_client/parser/openapi.py b/openapi_python_client/parser/openapi.py index e4af95a68..77f8f4fb6 100644 --- a/openapi_python_client/parser/openapi.py +++ b/openapi_python_client/parser/openapi.py @@ -516,12 +516,12 @@ def from_data( def response_type(self) -> str: """Get the Python type of any response from this endpoint""" - types = sorted({response.prop.get_type_string(quoted=False) for response in self.responses}) - if len(types) == 0: - return "Any" + types = {response.prop.get_type_string(quoted=False) for response in self.responses} + # We can always return None if client.raise_on_unexpected_status is unset + types.add("None") if len(types) == 1: - return self.responses[0].prop.get_type_string(quoted=False) - return f"Union[{', '.join(types)}]" + return next(iter(types)) + return f"Union[{', '.join(sorted(types))}]" def iter_all_parameters(self) -> Iterator[Property]: """Iterate through all the parameters of this endpoint""" diff --git a/openapi_python_client/templates/endpoint_module.py.jinja b/openapi_python_client/templates/endpoint_module.py.jinja index e8f512748..bf0da8dc5 100644 --- a/openapi_python_client/templates/endpoint_module.py.jinja +++ b/openapi_python_client/templates/endpoint_module.py.jinja @@ -60,7 +60,7 @@ def _get_kwargs( } -def _parse_response(*, client: Client, response: httpx.Response) -> Optional[{{ return_string }}]: +def _parse_response(*, client: Client, response: httpx.Response) -> {{ return_string }}: {% for response in endpoint.responses %} if response.status_code == HTTPStatus.{{ response.status_code.name }}: {% if parsed_responses %}{% import "property_templates/" + response.prop.template as prop_template %} @@ -113,7 +113,7 @@ def sync_detailed( {% if parsed_responses %} def sync( {{ arguments(endpoint) | indent(4) }} -) -> Optional[{{ return_string }}]: +) -> {{ return_string }}: {{ docstring(endpoint, return_string, is_detailed=false) | indent(4) }} return sync_detailed( @@ -140,7 +140,7 @@ async def asyncio_detailed( {% if parsed_responses %} async def asyncio( {{ arguments(endpoint) | indent(4) }} -) -> Optional[{{ return_string }}]: +) -> {{ return_string }}: {{ docstring(endpoint, return_string, is_detailed=false) | indent(4) }} return (await asyncio_detailed( diff --git a/openapi_python_client/templates/types.py.jinja b/openapi_python_client/templates/types.py.jinja index c746db6e1..82a522c6f 100644 --- a/openapi_python_client/templates/types.py.jinja +++ b/openapi_python_client/templates/types.py.jinja @@ -39,7 +39,7 @@ class Response(Generic[T]): status_code: HTTPStatus content: bytes headers: MutableMapping[str, str] - parsed: Optional[T] + parsed: T __all__ = ["File", "Response", "FileJsonType"] diff --git a/tests/test_parser/test_openapi.py b/tests/test_parser/test_openapi.py index 8ef6b0a6a..384ccdd12 100644 --- a/tests/test_parser/test_openapi.py +++ b/tests/test_parser/test_openapi.py @@ -1205,7 +1205,11 @@ def test_from_data_no_security(self, mocker): @pytest.mark.parametrize( "response_types, expected", - (([], "Any"), (["Something"], "Something"), (["First", "Second", "Second"], "Union[First, Second]")), + ( + ([], "None"), + (["Something"], "Union[None, Something]"), + (["First", "Second", "Second"], "Union[First, None, Second]"), + ), ) def test_response_type(self, response_types, expected): endpoint = self.make_endpoint() From afa1de31dd4b949e54aa1be070de2ca4c6b020e1 Mon Sep 17 00:00:00 2001 From: Robert Schweizer Date: Fri, 24 Mar 2023 18:43:28 +0100 Subject: [PATCH 6/6] feat: Make Any replace all other return types --- .../api/tests/callback_test.py | 22 +++++++++---------- .../api/tests/defaults_tests_defaults_post.py | 20 ++++++++--------- .../api/tests/int_enum_tests_int_enum_post.py | 22 +++++++++---------- .../tests/json_body_tests_json_body_post.py | 22 +++++++++---------- .../no_response_tests_no_response_get.py | 22 +++++++++---------- .../api/tests/post_form_data.py | 22 +++++++++---------- .../api/tests/post_form_data_inline.py | 22 +++++++++---------- ..._with_cookie_auth_token_with_cookie_get.py | 22 +++++++++---------- ...d_content_tests_unsupported_content_get.py | 22 +++++++++---------- .../tests/upload_file_tests_upload_post.py | 22 +++++++++---------- ...upload_multiple_files_tests_upload_post.py | 22 +++++++++---------- openapi_python_client/parser/openapi.py | 2 ++ 12 files changed, 122 insertions(+), 120 deletions(-) diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/tests/callback_test.py b/end_to_end_tests/golden-record/my_test_api_client/api/tests/callback_test.py index 343781097..b57afdffa 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/tests/callback_test.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/tests/callback_test.py @@ -1,5 +1,5 @@ from http import HTTPStatus -from typing import Any, Dict, Union +from typing import Any, Dict import httpx @@ -33,7 +33,7 @@ def _get_kwargs( } -def _parse_response(*, client: Client, response: httpx.Response) -> Union[Any, HTTPValidationError, None]: +def _parse_response(*, client: Client, response: httpx.Response) -> Any: if response.status_code == HTTPStatus.OK: response_200 = response.json() return response_200 @@ -47,7 +47,7 @@ def _parse_response(*, client: Client, response: httpx.Response) -> Union[Any, H return None -def _build_response(*, client: Client, response: httpx.Response) -> Response[Union[Any, HTTPValidationError, None]]: +def _build_response(*, client: Client, response: httpx.Response) -> Response[Any]: return Response( status_code=HTTPStatus(response.status_code), content=response.content, @@ -60,7 +60,7 @@ def sync_detailed( *, client: Client, json_body: AModel, -) -> Response[Union[Any, HTTPValidationError, None]]: +) -> Response[Any]: """Path with callback Try sending a request related to a callback @@ -73,7 +73,7 @@ def sync_detailed( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[Union[Any, HTTPValidationError, None]] + Response[Any] """ kwargs = _get_kwargs( @@ -93,7 +93,7 @@ def sync( *, client: Client, json_body: AModel, -) -> Union[Any, HTTPValidationError, None]: +) -> Any: """Path with callback Try sending a request related to a callback @@ -106,7 +106,7 @@ def sync( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Union[Any, HTTPValidationError, None] + Any """ return sync_detailed( @@ -119,7 +119,7 @@ async def asyncio_detailed( *, client: Client, json_body: AModel, -) -> Response[Union[Any, HTTPValidationError, None]]: +) -> Response[Any]: """Path with callback Try sending a request related to a callback @@ -132,7 +132,7 @@ async def asyncio_detailed( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[Union[Any, HTTPValidationError, None]] + Response[Any] """ kwargs = _get_kwargs( @@ -150,7 +150,7 @@ async def asyncio( *, client: Client, json_body: AModel, -) -> Union[Any, HTTPValidationError, None]: +) -> Any: """Path with callback Try sending a request related to a callback @@ -163,7 +163,7 @@ async def asyncio( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Union[Any, HTTPValidationError, None] + Any """ return ( 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 20ffd595c..fdb530714 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 @@ -100,7 +100,7 @@ def _get_kwargs( } -def _parse_response(*, client: Client, response: httpx.Response) -> Union[Any, HTTPValidationError, None]: +def _parse_response(*, client: Client, response: httpx.Response) -> Any: if response.status_code == HTTPStatus.OK: response_200 = response.json() return response_200 @@ -114,7 +114,7 @@ def _parse_response(*, client: Client, response: httpx.Response) -> Union[Any, H return None -def _build_response(*, client: Client, response: httpx.Response) -> Response[Union[Any, HTTPValidationError, None]]: +def _build_response(*, client: Client, response: httpx.Response) -> Response[Any]: return Response( status_code=HTTPStatus(response.status_code), content=response.content, @@ -137,7 +137,7 @@ def sync_detailed( enum_prop: AnEnum, model_prop: "ModelWithUnionProperty", required_model_prop: "ModelWithUnionProperty", -) -> Response[Union[Any, HTTPValidationError, None]]: +) -> Response[Any]: """Defaults Args: @@ -158,7 +158,7 @@ def sync_detailed( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[Union[Any, HTTPValidationError, None]] + Response[Any] """ kwargs = _get_kwargs( @@ -198,7 +198,7 @@ def sync( enum_prop: AnEnum, model_prop: "ModelWithUnionProperty", required_model_prop: "ModelWithUnionProperty", -) -> Union[Any, HTTPValidationError, None]: +) -> Any: """Defaults Args: @@ -219,7 +219,7 @@ def sync( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Union[Any, HTTPValidationError, None] + Any """ return sync_detailed( @@ -252,7 +252,7 @@ async def asyncio_detailed( enum_prop: AnEnum, model_prop: "ModelWithUnionProperty", required_model_prop: "ModelWithUnionProperty", -) -> Response[Union[Any, HTTPValidationError, None]]: +) -> Response[Any]: """Defaults Args: @@ -273,7 +273,7 @@ async def asyncio_detailed( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[Union[Any, HTTPValidationError, None]] + Response[Any] """ kwargs = _get_kwargs( @@ -311,7 +311,7 @@ async def asyncio( enum_prop: AnEnum, model_prop: "ModelWithUnionProperty", required_model_prop: "ModelWithUnionProperty", -) -> Union[Any, HTTPValidationError, None]: +) -> Any: """Defaults Args: @@ -332,7 +332,7 @@ async def asyncio( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Union[Any, HTTPValidationError, None] + Any """ return ( 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 d2a051d07..84e92d0a8 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/tests/int_enum_tests_int_enum_post.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/tests/int_enum_tests_int_enum_post.py @@ -1,5 +1,5 @@ from http import HTTPStatus -from typing import Any, Dict, Union +from typing import Any, Dict import httpx @@ -38,7 +38,7 @@ def _get_kwargs( } -def _parse_response(*, client: Client, response: httpx.Response) -> Union[Any, HTTPValidationError, None]: +def _parse_response(*, client: Client, response: httpx.Response) -> Any: if response.status_code == HTTPStatus.OK: response_200 = response.json() return response_200 @@ -52,7 +52,7 @@ def _parse_response(*, client: Client, response: httpx.Response) -> Union[Any, H return None -def _build_response(*, client: Client, response: httpx.Response) -> Response[Union[Any, HTTPValidationError, None]]: +def _build_response(*, client: Client, response: httpx.Response) -> Response[Any]: return Response( status_code=HTTPStatus(response.status_code), content=response.content, @@ -65,7 +65,7 @@ def sync_detailed( *, client: Client, int_enum: AnIntEnum, -) -> Response[Union[Any, HTTPValidationError, None]]: +) -> Response[Any]: """Int Enum Args: @@ -76,7 +76,7 @@ def sync_detailed( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[Union[Any, HTTPValidationError, None]] + Response[Any] """ kwargs = _get_kwargs( @@ -96,7 +96,7 @@ def sync( *, client: Client, int_enum: AnIntEnum, -) -> Union[Any, HTTPValidationError, None]: +) -> Any: """Int Enum Args: @@ -107,7 +107,7 @@ def sync( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Union[Any, HTTPValidationError, None] + Any """ return sync_detailed( @@ -120,7 +120,7 @@ async def asyncio_detailed( *, client: Client, int_enum: AnIntEnum, -) -> Response[Union[Any, HTTPValidationError, None]]: +) -> Response[Any]: """Int Enum Args: @@ -131,7 +131,7 @@ async def asyncio_detailed( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[Union[Any, HTTPValidationError, None]] + Response[Any] """ kwargs = _get_kwargs( @@ -149,7 +149,7 @@ async def asyncio( *, client: Client, int_enum: AnIntEnum, -) -> Union[Any, HTTPValidationError, None]: +) -> Any: """Int Enum Args: @@ -160,7 +160,7 @@ async def asyncio( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Union[Any, HTTPValidationError, None] + Any """ return ( 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 ae5f5630c..b8bd8a096 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/tests/json_body_tests_json_body_post.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/tests/json_body_tests_json_body_post.py @@ -1,5 +1,5 @@ from http import HTTPStatus -from typing import Any, Dict, Union +from typing import Any, Dict import httpx @@ -33,7 +33,7 @@ def _get_kwargs( } -def _parse_response(*, client: Client, response: httpx.Response) -> Union[Any, HTTPValidationError, None]: +def _parse_response(*, client: Client, response: httpx.Response) -> Any: if response.status_code == HTTPStatus.OK: response_200 = response.json() return response_200 @@ -47,7 +47,7 @@ def _parse_response(*, client: Client, response: httpx.Response) -> Union[Any, H return None -def _build_response(*, client: Client, response: httpx.Response) -> Response[Union[Any, HTTPValidationError, None]]: +def _build_response(*, client: Client, response: httpx.Response) -> Response[Any]: return Response( status_code=HTTPStatus(response.status_code), content=response.content, @@ -60,7 +60,7 @@ def sync_detailed( *, client: Client, json_body: AModel, -) -> Response[Union[Any, HTTPValidationError, None]]: +) -> Response[Any]: """Json Body Try sending a JSON body @@ -73,7 +73,7 @@ def sync_detailed( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[Union[Any, HTTPValidationError, None]] + Response[Any] """ kwargs = _get_kwargs( @@ -93,7 +93,7 @@ def sync( *, client: Client, json_body: AModel, -) -> Union[Any, HTTPValidationError, None]: +) -> Any: """Json Body Try sending a JSON body @@ -106,7 +106,7 @@ def sync( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Union[Any, HTTPValidationError, None] + Any """ return sync_detailed( @@ -119,7 +119,7 @@ async def asyncio_detailed( *, client: Client, json_body: AModel, -) -> Response[Union[Any, HTTPValidationError, None]]: +) -> Response[Any]: """Json Body Try sending a JSON body @@ -132,7 +132,7 @@ async def asyncio_detailed( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[Union[Any, HTTPValidationError, None]] + Response[Any] """ kwargs = _get_kwargs( @@ -150,7 +150,7 @@ async def asyncio( *, client: Client, json_body: AModel, -) -> Union[Any, HTTPValidationError, None]: +) -> Any: """Json Body Try sending a JSON body @@ -163,7 +163,7 @@ async def asyncio( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Union[Any, HTTPValidationError, None] + Any """ return ( 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 1c6c58f84..c1be8071f 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,5 +1,5 @@ from http import HTTPStatus -from typing import Any, Dict, Union +from typing import Any, Dict import httpx @@ -27,7 +27,7 @@ def _get_kwargs( } -def _parse_response(*, client: Client, response: httpx.Response) -> Union[Any, None]: +def _parse_response(*, client: Client, response: httpx.Response) -> Any: if response.status_code == HTTPStatus.OK: response_200 = response.json() return response_200 @@ -37,7 +37,7 @@ def _parse_response(*, client: Client, response: httpx.Response) -> Union[Any, N return None -def _build_response(*, client: Client, response: httpx.Response) -> Response[Union[Any, None]]: +def _build_response(*, client: Client, response: httpx.Response) -> Response[Any]: return Response( status_code=HTTPStatus(response.status_code), content=response.content, @@ -49,7 +49,7 @@ def _build_response(*, client: Client, response: httpx.Response) -> Response[Uni def sync_detailed( *, client: Client, -) -> Response[Union[Any, None]]: +) -> Response[Any]: """No Response Raises: @@ -57,7 +57,7 @@ def sync_detailed( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[Union[Any, None]] + Response[Any] """ kwargs = _get_kwargs( @@ -75,7 +75,7 @@ def sync_detailed( def sync( *, client: Client, -) -> Union[Any, None]: +) -> Any: """No Response Raises: @@ -83,7 +83,7 @@ def sync( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Union[Any, None] + Any """ return sync_detailed( @@ -94,7 +94,7 @@ def sync( async def asyncio_detailed( *, client: Client, -) -> Response[Union[Any, None]]: +) -> Response[Any]: """No Response Raises: @@ -102,7 +102,7 @@ async def asyncio_detailed( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[Union[Any, None]] + Response[Any] """ kwargs = _get_kwargs( @@ -118,7 +118,7 @@ async def asyncio_detailed( async def asyncio( *, client: Client, -) -> Union[Any, None]: +) -> Any: """No Response Raises: @@ -126,7 +126,7 @@ async def asyncio( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Union[Any, None] + Any """ return ( diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/tests/post_form_data.py b/end_to_end_tests/golden-record/my_test_api_client/api/tests/post_form_data.py index cba1a5a29..b3a980e57 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/tests/post_form_data.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/tests/post_form_data.py @@ -1,5 +1,5 @@ from http import HTTPStatus -from typing import Any, Dict, Union +from typing import Any, Dict import httpx @@ -30,7 +30,7 @@ def _get_kwargs( } -def _parse_response(*, client: Client, response: httpx.Response) -> Union[Any, None]: +def _parse_response(*, client: Client, response: httpx.Response) -> Any: if response.status_code == HTTPStatus.OK: response_200 = response.json() return response_200 @@ -40,7 +40,7 @@ def _parse_response(*, client: Client, response: httpx.Response) -> Union[Any, N return None -def _build_response(*, client: Client, response: httpx.Response) -> Response[Union[Any, None]]: +def _build_response(*, client: Client, response: httpx.Response) -> Response[Any]: return Response( status_code=HTTPStatus(response.status_code), content=response.content, @@ -53,7 +53,7 @@ def sync_detailed( *, client: Client, form_data: AFormData, -) -> Response[Union[Any, None]]: +) -> Response[Any]: """Post form data Post form data @@ -63,7 +63,7 @@ def sync_detailed( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[Union[Any, None]] + Response[Any] """ kwargs = _get_kwargs( @@ -83,7 +83,7 @@ def sync( *, client: Client, form_data: AFormData, -) -> Union[Any, None]: +) -> Any: """Post form data Post form data @@ -93,7 +93,7 @@ def sync( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Union[Any, None] + Any """ return sync_detailed( @@ -106,7 +106,7 @@ async def asyncio_detailed( *, client: Client, form_data: AFormData, -) -> Response[Union[Any, None]]: +) -> Response[Any]: """Post form data Post form data @@ -116,7 +116,7 @@ async def asyncio_detailed( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[Union[Any, None]] + Response[Any] """ kwargs = _get_kwargs( @@ -134,7 +134,7 @@ async def asyncio( *, client: Client, form_data: AFormData, -) -> Union[Any, None]: +) -> Any: """Post form data Post form data @@ -144,7 +144,7 @@ async def asyncio( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Union[Any, None] + Any """ return ( diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/tests/post_form_data_inline.py b/end_to_end_tests/golden-record/my_test_api_client/api/tests/post_form_data_inline.py index 7443afa9a..d57b305cd 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/tests/post_form_data_inline.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/tests/post_form_data_inline.py @@ -1,5 +1,5 @@ from http import HTTPStatus -from typing import Any, Dict, Union +from typing import Any, Dict import httpx @@ -30,7 +30,7 @@ def _get_kwargs( } -def _parse_response(*, client: Client, response: httpx.Response) -> Union[Any, None]: +def _parse_response(*, client: Client, response: httpx.Response) -> Any: if response.status_code == HTTPStatus.OK: response_200 = response.json() return response_200 @@ -40,7 +40,7 @@ def _parse_response(*, client: Client, response: httpx.Response) -> Union[Any, N return None -def _build_response(*, client: Client, response: httpx.Response) -> Response[Union[Any, None]]: +def _build_response(*, client: Client, response: httpx.Response) -> Response[Any]: return Response( status_code=HTTPStatus(response.status_code), content=response.content, @@ -53,7 +53,7 @@ def sync_detailed( *, client: Client, form_data: PostFormDataInlineData, -) -> Response[Union[Any, None]]: +) -> Response[Any]: """Post form data (inline schema) Post form data (inline schema) @@ -63,7 +63,7 @@ def sync_detailed( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[Union[Any, None]] + Response[Any] """ kwargs = _get_kwargs( @@ -83,7 +83,7 @@ def sync( *, client: Client, form_data: PostFormDataInlineData, -) -> Union[Any, None]: +) -> Any: """Post form data (inline schema) Post form data (inline schema) @@ -93,7 +93,7 @@ def sync( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Union[Any, None] + Any """ return sync_detailed( @@ -106,7 +106,7 @@ async def asyncio_detailed( *, client: Client, form_data: PostFormDataInlineData, -) -> Response[Union[Any, None]]: +) -> Response[Any]: """Post form data (inline schema) Post form data (inline schema) @@ -116,7 +116,7 @@ async def asyncio_detailed( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[Union[Any, None]] + Response[Any] """ kwargs = _get_kwargs( @@ -134,7 +134,7 @@ async def asyncio( *, client: Client, form_data: PostFormDataInlineData, -) -> Union[Any, None]: +) -> Any: """Post form data (inline schema) Post form data (inline schema) @@ -144,7 +144,7 @@ async def asyncio( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Union[Any, None] + Any """ return ( 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 2a4988965..3c765d521 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,5 +1,5 @@ from http import HTTPStatus -from typing import Any, Dict, Union +from typing import Any, Dict import httpx @@ -30,7 +30,7 @@ def _get_kwargs( } -def _parse_response(*, client: Client, response: httpx.Response) -> Union[Any, None]: +def _parse_response(*, client: Client, response: httpx.Response) -> Any: if response.status_code == HTTPStatus.OK: response_200 = response.json() return response_200 @@ -43,7 +43,7 @@ def _parse_response(*, client: Client, response: httpx.Response) -> Union[Any, N return None -def _build_response(*, client: Client, response: httpx.Response) -> Response[Union[Any, None]]: +def _build_response(*, client: Client, response: httpx.Response) -> Response[Any]: return Response( status_code=HTTPStatus(response.status_code), content=response.content, @@ -56,7 +56,7 @@ def sync_detailed( *, client: Client, my_token: str, -) -> Response[Union[Any, None]]: +) -> Response[Any]: """TOKEN_WITH_COOKIE Test optional cookie parameters @@ -69,7 +69,7 @@ def sync_detailed( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[Union[Any, None]] + Response[Any] """ kwargs = _get_kwargs( @@ -89,7 +89,7 @@ def sync( *, client: Client, my_token: str, -) -> Union[Any, None]: +) -> Any: """TOKEN_WITH_COOKIE Test optional cookie parameters @@ -102,7 +102,7 @@ def sync( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Union[Any, None] + Any """ return sync_detailed( @@ -115,7 +115,7 @@ async def asyncio_detailed( *, client: Client, my_token: str, -) -> Response[Union[Any, None]]: +) -> Response[Any]: """TOKEN_WITH_COOKIE Test optional cookie parameters @@ -128,7 +128,7 @@ async def asyncio_detailed( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[Union[Any, None]] + Response[Any] """ kwargs = _get_kwargs( @@ -146,7 +146,7 @@ async def asyncio( *, client: Client, my_token: str, -) -> Union[Any, None]: +) -> Any: """TOKEN_WITH_COOKIE Test optional cookie parameters @@ -159,7 +159,7 @@ async def asyncio( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Union[Any, None] + Any """ return ( 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 87780172e..b26ee9904 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,5 +1,5 @@ from http import HTTPStatus -from typing import Any, Dict, Union +from typing import Any, Dict import httpx @@ -27,7 +27,7 @@ def _get_kwargs( } -def _parse_response(*, client: Client, response: httpx.Response) -> Union[Any, None]: +def _parse_response(*, client: Client, response: httpx.Response) -> Any: if response.status_code == HTTPStatus.OK: response_200 = response.json() return response_200 @@ -37,7 +37,7 @@ def _parse_response(*, client: Client, response: httpx.Response) -> Union[Any, N return None -def _build_response(*, client: Client, response: httpx.Response) -> Response[Union[Any, None]]: +def _build_response(*, client: Client, response: httpx.Response) -> Response[Any]: return Response( status_code=HTTPStatus(response.status_code), content=response.content, @@ -49,7 +49,7 @@ def _build_response(*, client: Client, response: httpx.Response) -> Response[Uni def sync_detailed( *, client: Client, -) -> Response[Union[Any, None]]: +) -> Response[Any]: """Unsupported Content Raises: @@ -57,7 +57,7 @@ def sync_detailed( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[Union[Any, None]] + Response[Any] """ kwargs = _get_kwargs( @@ -75,7 +75,7 @@ def sync_detailed( def sync( *, client: Client, -) -> Union[Any, None]: +) -> Any: """Unsupported Content Raises: @@ -83,7 +83,7 @@ def sync( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Union[Any, None] + Any """ return sync_detailed( @@ -94,7 +94,7 @@ def sync( async def asyncio_detailed( *, client: Client, -) -> Response[Union[Any, None]]: +) -> Response[Any]: """Unsupported Content Raises: @@ -102,7 +102,7 @@ async def asyncio_detailed( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[Union[Any, None]] + Response[Any] """ kwargs = _get_kwargs( @@ -118,7 +118,7 @@ async def asyncio_detailed( async def asyncio( *, client: Client, -) -> Union[Any, None]: +) -> Any: """Unsupported Content Raises: @@ -126,7 +126,7 @@ async def asyncio( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Union[Any, None] + Any """ return ( 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 f6db55568..df787293e 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/tests/upload_file_tests_upload_post.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/tests/upload_file_tests_upload_post.py @@ -1,5 +1,5 @@ from http import HTTPStatus -from typing import Any, Dict, Union +from typing import Any, Dict import httpx @@ -33,7 +33,7 @@ def _get_kwargs( } -def _parse_response(*, client: Client, response: httpx.Response) -> Union[Any, HTTPValidationError, None]: +def _parse_response(*, client: Client, response: httpx.Response) -> Any: if response.status_code == HTTPStatus.OK: response_200 = response.json() return response_200 @@ -47,7 +47,7 @@ def _parse_response(*, client: Client, response: httpx.Response) -> Union[Any, H return None -def _build_response(*, client: Client, response: httpx.Response) -> Response[Union[Any, HTTPValidationError, None]]: +def _build_response(*, client: Client, response: httpx.Response) -> Response[Any]: return Response( status_code=HTTPStatus(response.status_code), content=response.content, @@ -60,7 +60,7 @@ def sync_detailed( *, client: Client, multipart_data: BodyUploadFileTestsUploadPost, -) -> Response[Union[Any, HTTPValidationError, None]]: +) -> Response[Any]: """Upload File Upload a file @@ -73,7 +73,7 @@ def sync_detailed( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[Union[Any, HTTPValidationError, None]] + Response[Any] """ kwargs = _get_kwargs( @@ -93,7 +93,7 @@ def sync( *, client: Client, multipart_data: BodyUploadFileTestsUploadPost, -) -> Union[Any, HTTPValidationError, None]: +) -> Any: """Upload File Upload a file @@ -106,7 +106,7 @@ def sync( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Union[Any, HTTPValidationError, None] + Any """ return sync_detailed( @@ -119,7 +119,7 @@ async def asyncio_detailed( *, client: Client, multipart_data: BodyUploadFileTestsUploadPost, -) -> Response[Union[Any, HTTPValidationError, None]]: +) -> Response[Any]: """Upload File Upload a file @@ -132,7 +132,7 @@ async def asyncio_detailed( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[Union[Any, HTTPValidationError, None]] + Response[Any] """ kwargs = _get_kwargs( @@ -150,7 +150,7 @@ async def asyncio( *, client: Client, multipart_data: BodyUploadFileTestsUploadPost, -) -> Union[Any, HTTPValidationError, None]: +) -> Any: """Upload File Upload a file @@ -163,7 +163,7 @@ async def asyncio( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Union[Any, HTTPValidationError, None] + Any """ return ( diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/tests/upload_multiple_files_tests_upload_post.py b/end_to_end_tests/golden-record/my_test_api_client/api/tests/upload_multiple_files_tests_upload_post.py index 3d9c74c84..b44f0ffcd 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/tests/upload_multiple_files_tests_upload_post.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/tests/upload_multiple_files_tests_upload_post.py @@ -1,5 +1,5 @@ from http import HTTPStatus -from typing import Any, Dict, List, Union +from typing import Any, Dict, List import httpx @@ -36,7 +36,7 @@ def _get_kwargs( } -def _parse_response(*, client: Client, response: httpx.Response) -> Union[Any, HTTPValidationError, None]: +def _parse_response(*, client: Client, response: httpx.Response) -> Any: if response.status_code == HTTPStatus.OK: response_200 = response.json() return response_200 @@ -50,7 +50,7 @@ def _parse_response(*, client: Client, response: httpx.Response) -> Union[Any, H return None -def _build_response(*, client: Client, response: httpx.Response) -> Response[Union[Any, HTTPValidationError, None]]: +def _build_response(*, client: Client, response: httpx.Response) -> Response[Any]: return Response( status_code=HTTPStatus(response.status_code), content=response.content, @@ -63,7 +63,7 @@ def sync_detailed( *, client: Client, multipart_data: List[File], -) -> Response[Union[Any, HTTPValidationError, None]]: +) -> Response[Any]: """Upload multiple files Upload several files in the same request @@ -76,7 +76,7 @@ def sync_detailed( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[Union[Any, HTTPValidationError, None]] + Response[Any] """ kwargs = _get_kwargs( @@ -96,7 +96,7 @@ def sync( *, client: Client, multipart_data: List[File], -) -> Union[Any, HTTPValidationError, None]: +) -> Any: """Upload multiple files Upload several files in the same request @@ -109,7 +109,7 @@ def sync( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Union[Any, HTTPValidationError, None] + Any """ return sync_detailed( @@ -122,7 +122,7 @@ async def asyncio_detailed( *, client: Client, multipart_data: List[File], -) -> Response[Union[Any, HTTPValidationError, None]]: +) -> Response[Any]: """Upload multiple files Upload several files in the same request @@ -135,7 +135,7 @@ async def asyncio_detailed( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[Union[Any, HTTPValidationError, None]] + Response[Any] """ kwargs = _get_kwargs( @@ -153,7 +153,7 @@ async def asyncio( *, client: Client, multipart_data: List[File], -) -> Union[Any, HTTPValidationError, None]: +) -> Any: """Upload multiple files Upload several files in the same request @@ -166,7 +166,7 @@ async def asyncio( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Union[Any, HTTPValidationError, None] + Any """ return ( diff --git a/openapi_python_client/parser/openapi.py b/openapi_python_client/parser/openapi.py index 77f8f4fb6..ed9a90849 100644 --- a/openapi_python_client/parser/openapi.py +++ b/openapi_python_client/parser/openapi.py @@ -521,6 +521,8 @@ def response_type(self) -> str: types.add("None") if len(types) == 1: return next(iter(types)) + if "Any" in types: + return "Any" # Any includes all other types return f"Union[{', '.join(sorted(types))}]" def iter_all_parameters(self) -> Iterator[Property]: