Skip to content

fix: Prevent duplicate return types in generated api functions #365

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Apr 5, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ def _get_kwargs(
}


def _parse_response(*, response: httpx.Response) -> Optional[Union[None, HTTPValidationError]]:
def _parse_response(*, response: httpx.Response) -> Optional[Union[HTTPValidationError, None]]:
if response.status_code == 200:
response_200 = None

Expand All @@ -151,7 +151,7 @@ def _parse_response(*, response: httpx.Response) -> Optional[Union[None, HTTPVal
return None


def _build_response(*, response: httpx.Response) -> Response[Union[None, HTTPValidationError]]:
def _build_response(*, response: httpx.Response) -> Response[Union[HTTPValidationError, None]]:
return Response(
status_code=response.status_code,
content=response.content,
Expand Down Expand Up @@ -180,7 +180,7 @@ def sync_detailed(
required_model_prop: ModelWithUnionProperty,
nullable_model_prop: Union[ModelWithUnionProperty, None, Unset] = UNSET,
nullable_required_model_prop: Union[ModelWithUnionProperty, None],
) -> Response[Union[None, HTTPValidationError]]:
) -> Response[Union[HTTPValidationError, None]]:
kwargs = _get_kwargs(
client=client,
string_prop=string_prop,
Expand Down Expand Up @@ -229,7 +229,7 @@ def sync(
required_model_prop: ModelWithUnionProperty,
nullable_model_prop: Union[ModelWithUnionProperty, None, Unset] = UNSET,
nullable_required_model_prop: Union[ModelWithUnionProperty, None],
) -> Optional[Union[None, HTTPValidationError]]:
) -> Optional[Union[HTTPValidationError, None]]:
""" """

return sync_detailed(
Expand Down Expand Up @@ -274,7 +274,7 @@ async def asyncio_detailed(
required_model_prop: ModelWithUnionProperty,
nullable_model_prop: Union[ModelWithUnionProperty, None, Unset] = UNSET,
nullable_required_model_prop: Union[ModelWithUnionProperty, None],
) -> Response[Union[None, HTTPValidationError]]:
) -> Response[Union[HTTPValidationError, None]]:
kwargs = _get_kwargs(
client=client,
string_prop=string_prop,
Expand Down Expand Up @@ -322,7 +322,7 @@ async def asyncio(
required_model_prop: ModelWithUnionProperty,
nullable_model_prop: Union[ModelWithUnionProperty, None, Unset] = UNSET,
nullable_required_model_prop: Union[ModelWithUnionProperty, None],
) -> Optional[Union[None, HTTPValidationError]]:
) -> Optional[Union[HTTPValidationError, None]]:
""" """

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def _get_kwargs(
}


def _parse_response(*, response: httpx.Response) -> Optional[Union[List[AModel], HTTPValidationError]]:
def _parse_response(*, response: httpx.Response) -> Optional[Union[HTTPValidationError, List[AModel]]]:
if response.status_code == 200:
response_200 = []
_response_200 = response.json()
Expand All @@ -61,10 +61,14 @@ def _parse_response(*, response: httpx.Response) -> Optional[Union[List[AModel],
response_422 = HTTPValidationError.from_dict(response.json())

return response_422
if response.status_code == 423:
response_423 = HTTPValidationError.from_dict(response.json())

return response_423
return None


def _build_response(*, response: httpx.Response) -> Response[Union[List[AModel], HTTPValidationError]]:
def _build_response(*, response: httpx.Response) -> Response[Union[HTTPValidationError, List[AModel]]]:
return Response(
status_code=response.status_code,
content=response.content,
Expand All @@ -78,7 +82,7 @@ def sync_detailed(
client: Client,
an_enum_value: List[AnEnum],
some_date: Union[datetime.date, datetime.datetime],
) -> Response[Union[List[AModel], HTTPValidationError]]:
) -> Response[Union[HTTPValidationError, List[AModel]]]:
kwargs = _get_kwargs(
client=client,
an_enum_value=an_enum_value,
Expand All @@ -97,7 +101,7 @@ def sync(
client: Client,
an_enum_value: List[AnEnum],
some_date: Union[datetime.date, datetime.datetime],
) -> Optional[Union[List[AModel], HTTPValidationError]]:
) -> Optional[Union[HTTPValidationError, List[AModel]]]:
""" Get a list of things """

return sync_detailed(
Expand All @@ -112,7 +116,7 @@ async def asyncio_detailed(
client: Client,
an_enum_value: List[AnEnum],
some_date: Union[datetime.date, datetime.datetime],
) -> Response[Union[List[AModel], HTTPValidationError]]:
) -> Response[Union[HTTPValidationError, List[AModel]]]:
kwargs = _get_kwargs(
client=client,
an_enum_value=an_enum_value,
Expand All @@ -130,7 +134,7 @@ async def asyncio(
client: Client,
an_enum_value: List[AnEnum],
some_date: Union[datetime.date, datetime.datetime],
) -> Optional[Union[List[AModel], HTTPValidationError]]:
) -> Optional[Union[HTTPValidationError, List[AModel]]]:
""" Get a list of things """

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def _get_kwargs(
}


def _parse_response(*, response: httpx.Response) -> Optional[Union[None, HTTPValidationError]]:
def _parse_response(*, response: httpx.Response) -> Optional[Union[HTTPValidationError, None]]:
if response.status_code == 200:
response_200 = None

Expand All @@ -46,7 +46,7 @@ def _parse_response(*, response: httpx.Response) -> Optional[Union[None, HTTPVal
return None


def _build_response(*, response: httpx.Response) -> Response[Union[None, HTTPValidationError]]:
def _build_response(*, response: httpx.Response) -> Response[Union[HTTPValidationError, None]]:
return Response(
status_code=response.status_code,
content=response.content,
Expand All @@ -59,7 +59,7 @@ def sync_detailed(
*,
client: Client,
int_enum: AnIntEnum,
) -> Response[Union[None, HTTPValidationError]]:
) -> Response[Union[HTTPValidationError, None]]:
kwargs = _get_kwargs(
client=client,
int_enum=int_enum,
Expand All @@ -76,7 +76,7 @@ def sync(
*,
client: Client,
int_enum: AnIntEnum,
) -> Optional[Union[None, HTTPValidationError]]:
) -> Optional[Union[HTTPValidationError, None]]:
""" """

return sync_detailed(
Expand All @@ -89,7 +89,7 @@ async def asyncio_detailed(
*,
client: Client,
int_enum: AnIntEnum,
) -> Response[Union[None, HTTPValidationError]]:
) -> Response[Union[HTTPValidationError, None]]:
kwargs = _get_kwargs(
client=client,
int_enum=int_enum,
Expand All @@ -105,7 +105,7 @@ async def asyncio(
*,
client: Client,
int_enum: AnIntEnum,
) -> Optional[Union[None, HTTPValidationError]]:
) -> Optional[Union[HTTPValidationError, None]]:
""" """

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def _get_kwargs(
}


def _parse_response(*, response: httpx.Response) -> Optional[Union[None, HTTPValidationError]]:
def _parse_response(*, response: httpx.Response) -> Optional[Union[HTTPValidationError, None]]:
if response.status_code == 200:
response_200 = None

Expand All @@ -41,7 +41,7 @@ def _parse_response(*, response: httpx.Response) -> Optional[Union[None, HTTPVal
return None


def _build_response(*, response: httpx.Response) -> Response[Union[None, HTTPValidationError]]:
def _build_response(*, response: httpx.Response) -> Response[Union[HTTPValidationError, None]]:
return Response(
status_code=response.status_code,
content=response.content,
Expand All @@ -54,7 +54,7 @@ def sync_detailed(
*,
client: Client,
json_body: AModel,
) -> Response[Union[None, HTTPValidationError]]:
) -> Response[Union[HTTPValidationError, None]]:
kwargs = _get_kwargs(
client=client,
json_body=json_body,
Expand All @@ -71,7 +71,7 @@ def sync(
*,
client: Client,
json_body: AModel,
) -> Optional[Union[None, HTTPValidationError]]:
) -> Optional[Union[HTTPValidationError, None]]:
""" Try sending a JSON body """

return sync_detailed(
Expand All @@ -84,7 +84,7 @@ async def asyncio_detailed(
*,
client: Client,
json_body: AModel,
) -> Response[Union[None, HTTPValidationError]]:
) -> Response[Union[HTTPValidationError, None]]:
kwargs = _get_kwargs(
client=client,
json_body=json_body,
Expand All @@ -100,7 +100,7 @@ async def asyncio(
*,
client: Client,
json_body: AModel,
) -> Optional[Union[None, HTTPValidationError]]:
) -> Optional[Union[HTTPValidationError, None]]:
""" Try sending a JSON body """

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def _get_kwargs(
}


def _parse_response(*, response: httpx.Response) -> Optional[Union[None, HTTPValidationError]]:
def _parse_response(*, response: httpx.Response) -> Optional[Union[HTTPValidationError, None]]:
if response.status_code == 200:
response_200 = None

Expand All @@ -47,7 +47,7 @@ def _parse_response(*, response: httpx.Response) -> Optional[Union[None, HTTPVal
return None


def _build_response(*, response: httpx.Response) -> Response[Union[None, HTTPValidationError]]:
def _build_response(*, response: httpx.Response) -> Response[Union[HTTPValidationError, None]]:
return Response(
status_code=response.status_code,
content=response.content,
Expand All @@ -60,7 +60,7 @@ def sync_detailed(
*,
client: Client,
query_param: Union[Unset, List[str]] = UNSET,
) -> Response[Union[None, HTTPValidationError]]:
) -> Response[Union[HTTPValidationError, None]]:
kwargs = _get_kwargs(
client=client,
query_param=query_param,
Expand All @@ -77,7 +77,7 @@ def sync(
*,
client: Client,
query_param: Union[Unset, List[str]] = UNSET,
) -> Optional[Union[None, HTTPValidationError]]:
) -> Optional[Union[HTTPValidationError, None]]:
""" Test optional query parameters """

return sync_detailed(
Expand All @@ -90,7 +90,7 @@ async def asyncio_detailed(
*,
client: Client,
query_param: Union[Unset, List[str]] = UNSET,
) -> Response[Union[None, HTTPValidationError]]:
) -> Response[Union[HTTPValidationError, None]]:
kwargs = _get_kwargs(
client=client,
query_param=query_param,
Expand All @@ -106,7 +106,7 @@ async def asyncio(
*,
client: Client,
query_param: Union[Unset, List[str]] = UNSET,
) -> Optional[Union[None, HTTPValidationError]]:
) -> Optional[Union[HTTPValidationError, None]]:
""" Test optional query parameters """

return (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any, Dict, Optional, Union
from typing import Any, Dict

import httpx

Expand Down Expand Up @@ -26,32 +26,20 @@ def _get_kwargs(
}


def _parse_response(*, response: httpx.Response) -> Optional[Union[None, None]]:
if response.status_code == 200:
response_200 = None

return response_200
if response.status_code == 401:
response_401 = None

return response_401
return None


def _build_response(*, response: httpx.Response) -> Response[Union[None, None]]:
def _build_response(*, response: httpx.Response) -> Response[None]:
return Response(
status_code=response.status_code,
content=response.content,
headers=response.headers,
parsed=_parse_response(response=response),
parsed=None,
)


def sync_detailed(
*,
client: Client,
my_token: str,
) -> Response[Union[None, None]]:
) -> Response[None]:
kwargs = _get_kwargs(
client=client,
my_token=my_token,
Expand All @@ -64,24 +52,11 @@ def sync_detailed(
return _build_response(response=response)


def sync(
*,
client: Client,
my_token: str,
) -> Optional[Union[None, None]]:
""" Test optional cookie parameters """

return sync_detailed(
client=client,
my_token=my_token,
).parsed


async def asyncio_detailed(
*,
client: Client,
my_token: str,
) -> Response[Union[None, None]]:
) -> Response[None]:
kwargs = _get_kwargs(
client=client,
my_token=my_token,
Expand All @@ -91,18 +66,3 @@ async def asyncio_detailed(
response = await _client.get(**kwargs)

return _build_response(response=response)


async def asyncio(
*,
client: Client,
my_token: str,
) -> Optional[Union[None, None]]:
""" Test optional cookie parameters """

return (
await asyncio_detailed(
client=client,
my_token=my_token,
)
).parsed
Loading