Skip to content

Commit

Permalink
fix(generator): Treat empty schemas like Any instead of None. Tha…
Browse files Browse the repository at this point in the history
…nks @forest-benchling! [#417 & #445]

* Support AnyProperty

* Install Poetry requirements and re

* Remove NoneProperty

* Add test case, change to check for Any instead of None

* Fix test

* fix: Remove need for unnecessary `if True` when constructing unions of Any properties.

Co-authored-by: Forest Tong <forest@benchling.com>
  • Loading branch information
dbanty and forest-benchling committed Jul 2, 2021
1 parent 84247e5 commit 0056677
Show file tree
Hide file tree
Showing 23 changed files with 112 additions and 97 deletions.
Expand Up @@ -30,7 +30,7 @@ def _get_kwargs(
}


def _build_response(*, response: httpx.Response) -> Response[None]:
def _build_response(*, response: httpx.Response) -> Response[Any]:
return Response(
status_code=response.status_code,
content=response.content,
Expand All @@ -43,7 +43,7 @@ def sync_detailed(
*,
client: Client,
common: Union[Unset, str] = UNSET,
) -> Response[None]:
) -> Response[Any]:
kwargs = _get_kwargs(
client=client,
common=common,
Expand All @@ -60,7 +60,7 @@ async def asyncio_detailed(
*,
client: Client,
common: Union[Unset, str] = UNSET,
) -> Response[None]:
) -> Response[Any]:
kwargs = _get_kwargs(
client=client,
common=common,
Expand Down
Expand Up @@ -30,7 +30,7 @@ def _get_kwargs(
}


def _build_response(*, response: httpx.Response) -> Response[None]:
def _build_response(*, response: httpx.Response) -> Response[Any]:
return Response(
status_code=response.status_code,
content=response.content,
Expand All @@ -43,7 +43,7 @@ def sync_detailed(
*,
client: Client,
common: Union[Unset, str] = UNSET,
) -> Response[None]:
) -> Response[Any]:
kwargs = _get_kwargs(
client=client,
common=common,
Expand All @@ -60,7 +60,7 @@ async def asyncio_detailed(
*,
client: Client,
common: Union[Unset, str] = UNSET,
) -> Response[None]:
) -> Response[Any]:
kwargs = _get_kwargs(
client=client,
common=common,
Expand Down
Expand Up @@ -31,7 +31,7 @@ def _get_kwargs(
}


def _build_response(*, response: httpx.Response) -> Response[None]:
def _build_response(*, response: httpx.Response) -> Response[Any]:
return Response(
status_code=response.status_code,
content=response.content,
Expand All @@ -45,7 +45,7 @@ def sync_detailed(
client: Client,
param_path: Union[Unset, str] = UNSET,
param_query: Union[Unset, str] = UNSET,
) -> Response[None]:
) -> Response[Any]:
kwargs = _get_kwargs(
client=client,
param_path=param_path,
Expand All @@ -64,7 +64,7 @@ async def asyncio_detailed(
client: Client,
param_path: Union[Unset, str] = UNSET,
param_query: Union[Unset, str] = UNSET,
) -> Response[None]:
) -> Response[Any]:
kwargs = _get_kwargs(
client=client,
param_path=param_path,
Expand Down
Expand Up @@ -131,9 +131,9 @@ def _get_kwargs(
}


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

return response_200
if response.status_code == 422:
Expand All @@ -143,7 +143,7 @@ def _parse_response(*, response: httpx.Response) -> Optional[Union[HTTPValidatio
return None


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

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

return (
Expand Down
Expand Up @@ -34,9 +34,9 @@ def _get_kwargs(
}


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

return response_200
if response.status_code == 422:
Expand All @@ -46,7 +46,7 @@ def _parse_response(*, response: httpx.Response) -> Optional[Union[HTTPValidatio
return None


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

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

return (
Expand Down
Expand Up @@ -29,9 +29,9 @@ def _get_kwargs(
}


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

return response_200
if response.status_code == 422:
Expand All @@ -41,7 +41,7 @@ def _parse_response(*, response: httpx.Response) -> Optional[Union[HTTPValidatio
return None


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

return (
Expand Down
Expand Up @@ -23,7 +23,7 @@ def _get_kwargs(
}


def _build_response(*, response: httpx.Response) -> Response[None]:
def _build_response(*, response: httpx.Response) -> Response[Any]:
return Response(
status_code=response.status_code,
content=response.content,
Expand All @@ -35,7 +35,7 @@ def _build_response(*, response: httpx.Response) -> Response[None]:
def sync_detailed(
*,
client: Client,
) -> Response[None]:
) -> Response[Any]:
kwargs = _get_kwargs(
client=client,
)
Expand All @@ -50,7 +50,7 @@ def sync_detailed(
async def asyncio_detailed(
*,
client: Client,
) -> Response[None]:
) -> Response[Any]:
kwargs = _get_kwargs(
client=client,
)
Expand Down
Expand Up @@ -35,9 +35,9 @@ def _get_kwargs(
}


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

return response_200
if response.status_code == 422:
Expand All @@ -47,7 +47,7 @@ def _parse_response(*, response: httpx.Response) -> Optional[Union[HTTPValidatio
return None


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

return (
Expand Down
Expand Up @@ -26,7 +26,7 @@ def _get_kwargs(
}


def _build_response(*, response: httpx.Response) -> Response[None]:
def _build_response(*, response: httpx.Response) -> Response[Any]:
return Response(
status_code=response.status_code,
content=response.content,
Expand All @@ -39,7 +39,7 @@ def sync_detailed(
*,
client: Client,
form_data: AFormData,
) -> Response[None]:
) -> Response[Any]:
kwargs = _get_kwargs(
client=client,
form_data=form_data,
Expand All @@ -56,7 +56,7 @@ async def asyncio_detailed(
*,
client: Client,
form_data: AFormData,
) -> Response[None]:
) -> Response[Any]:
kwargs = _get_kwargs(
client=client,
form_data=form_data,
Expand Down
Expand Up @@ -26,7 +26,7 @@ def _get_kwargs(
}


def _build_response(*, response: httpx.Response) -> Response[None]:
def _build_response(*, response: httpx.Response) -> Response[Any]:
return Response(
status_code=response.status_code,
content=response.content,
Expand All @@ -39,7 +39,7 @@ def sync_detailed(
*,
client: Client,
my_token: str,
) -> Response[None]:
) -> Response[Any]:
kwargs = _get_kwargs(
client=client,
my_token=my_token,
Expand All @@ -56,7 +56,7 @@ async def asyncio_detailed(
*,
client: Client,
my_token: str,
) -> Response[None]:
) -> Response[Any]:
kwargs = _get_kwargs(
client=client,
my_token=my_token,
Expand Down

0 comments on commit 0056677

Please sign in to comment.