Skip to content

Commit 0056677

Browse files
fix(generator): Treat empty schemas like Any instead of None. Thanks @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 <[email protected]>
1 parent 84247e5 commit 0056677

23 files changed

+112
-97
lines changed

Diff for: end_to_end_tests/golden-record/my_test_api_client/api/default/get_common_parameters.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def _get_kwargs(
3030
}
3131

3232

33-
def _build_response(*, response: httpx.Response) -> Response[None]:
33+
def _build_response(*, response: httpx.Response) -> Response[Any]:
3434
return Response(
3535
status_code=response.status_code,
3636
content=response.content,
@@ -43,7 +43,7 @@ def sync_detailed(
4343
*,
4444
client: Client,
4545
common: Union[Unset, str] = UNSET,
46-
) -> Response[None]:
46+
) -> Response[Any]:
4747
kwargs = _get_kwargs(
4848
client=client,
4949
common=common,
@@ -60,7 +60,7 @@ async def asyncio_detailed(
6060
*,
6161
client: Client,
6262
common: Union[Unset, str] = UNSET,
63-
) -> Response[None]:
63+
) -> Response[Any]:
6464
kwargs = _get_kwargs(
6565
client=client,
6666
common=common,

Diff for: end_to_end_tests/golden-record/my_test_api_client/api/default/post_common_parameters.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def _get_kwargs(
3030
}
3131

3232

33-
def _build_response(*, response: httpx.Response) -> Response[None]:
33+
def _build_response(*, response: httpx.Response) -> Response[Any]:
3434
return Response(
3535
status_code=response.status_code,
3636
content=response.content,
@@ -43,7 +43,7 @@ def sync_detailed(
4343
*,
4444
client: Client,
4545
common: Union[Unset, str] = UNSET,
46-
) -> Response[None]:
46+
) -> Response[Any]:
4747
kwargs = _get_kwargs(
4848
client=client,
4949
common=common,
@@ -60,7 +60,7 @@ async def asyncio_detailed(
6060
*,
6161
client: Client,
6262
common: Union[Unset, str] = UNSET,
63-
) -> Response[None]:
63+
) -> Response[Any]:
6464
kwargs = _get_kwargs(
6565
client=client,
6666
common=common,

Diff for: end_to_end_tests/golden-record/my_test_api_client/api/parameters/get_same_name_multiple_locations_param.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def _get_kwargs(
3131
}
3232

3333

34-
def _build_response(*, response: httpx.Response) -> Response[None]:
34+
def _build_response(*, response: httpx.Response) -> Response[Any]:
3535
return Response(
3636
status_code=response.status_code,
3737
content=response.content,
@@ -45,7 +45,7 @@ def sync_detailed(
4545
client: Client,
4646
param_path: Union[Unset, str] = UNSET,
4747
param_query: Union[Unset, str] = UNSET,
48-
) -> Response[None]:
48+
) -> Response[Any]:
4949
kwargs = _get_kwargs(
5050
client=client,
5151
param_path=param_path,
@@ -64,7 +64,7 @@ async def asyncio_detailed(
6464
client: Client,
6565
param_path: Union[Unset, str] = UNSET,
6666
param_query: Union[Unset, str] = UNSET,
67-
) -> Response[None]:
67+
) -> Response[Any]:
6868
kwargs = _get_kwargs(
6969
client=client,
7070
param_path=param_path,

Diff for: end_to_end_tests/golden-record/my_test_api_client/api/tests/defaults_tests_defaults_post.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,9 @@ def _get_kwargs(
131131
}
132132

133133

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

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

145145

146-
def _build_response(*, response: httpx.Response) -> Response[Union[HTTPValidationError, None]]:
146+
def _build_response(*, response: httpx.Response) -> Response[Union[Any, HTTPValidationError]]:
147147
return Response(
148148
status_code=response.status_code,
149149
content=response.content,
@@ -172,7 +172,7 @@ def sync_detailed(
172172
required_model_prop: ModelWithUnionProperty,
173173
nullable_model_prop: Union[Unset, None, ModelWithUnionProperty] = UNSET,
174174
nullable_required_model_prop: Optional[ModelWithUnionProperty],
175-
) -> Response[Union[HTTPValidationError, None]]:
175+
) -> Response[Union[Any, HTTPValidationError]]:
176176
kwargs = _get_kwargs(
177177
client=client,
178178
string_prop=string_prop,
@@ -221,7 +221,7 @@ def sync(
221221
required_model_prop: ModelWithUnionProperty,
222222
nullable_model_prop: Union[Unset, None, ModelWithUnionProperty] = UNSET,
223223
nullable_required_model_prop: Optional[ModelWithUnionProperty],
224-
) -> Optional[Union[HTTPValidationError, None]]:
224+
) -> Optional[Union[Any, HTTPValidationError]]:
225225
""" """
226226

227227
return sync_detailed(
@@ -266,7 +266,7 @@ async def asyncio_detailed(
266266
required_model_prop: ModelWithUnionProperty,
267267
nullable_model_prop: Union[Unset, None, ModelWithUnionProperty] = UNSET,
268268
nullable_required_model_prop: Optional[ModelWithUnionProperty],
269-
) -> Response[Union[HTTPValidationError, None]]:
269+
) -> Response[Union[Any, HTTPValidationError]]:
270270
kwargs = _get_kwargs(
271271
client=client,
272272
string_prop=string_prop,
@@ -314,7 +314,7 @@ async def asyncio(
314314
required_model_prop: ModelWithUnionProperty,
315315
nullable_model_prop: Union[Unset, None, ModelWithUnionProperty] = UNSET,
316316
nullable_required_model_prop: Optional[ModelWithUnionProperty],
317-
) -> Optional[Union[HTTPValidationError, None]]:
317+
) -> Optional[Union[Any, HTTPValidationError]]:
318318
""" """
319319

320320
return (

Diff for: end_to_end_tests/golden-record/my_test_api_client/api/tests/int_enum_tests_int_enum_post.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ def _get_kwargs(
3434
}
3535

3636

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

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

4848

49-
def _build_response(*, response: httpx.Response) -> Response[Union[HTTPValidationError, None]]:
49+
def _build_response(*, response: httpx.Response) -> Response[Union[Any, HTTPValidationError]]:
5050
return Response(
5151
status_code=response.status_code,
5252
content=response.content,
@@ -59,7 +59,7 @@ def sync_detailed(
5959
*,
6060
client: Client,
6161
int_enum: AnIntEnum,
62-
) -> Response[Union[HTTPValidationError, None]]:
62+
) -> Response[Union[Any, HTTPValidationError]]:
6363
kwargs = _get_kwargs(
6464
client=client,
6565
int_enum=int_enum,
@@ -76,7 +76,7 @@ def sync(
7676
*,
7777
client: Client,
7878
int_enum: AnIntEnum,
79-
) -> Optional[Union[HTTPValidationError, None]]:
79+
) -> Optional[Union[Any, HTTPValidationError]]:
8080
""" """
8181

8282
return sync_detailed(
@@ -89,7 +89,7 @@ async def asyncio_detailed(
8989
*,
9090
client: Client,
9191
int_enum: AnIntEnum,
92-
) -> Response[Union[HTTPValidationError, None]]:
92+
) -> Response[Union[Any, HTTPValidationError]]:
9393
kwargs = _get_kwargs(
9494
client=client,
9595
int_enum=int_enum,
@@ -105,7 +105,7 @@ async def asyncio(
105105
*,
106106
client: Client,
107107
int_enum: AnIntEnum,
108-
) -> Optional[Union[HTTPValidationError, None]]:
108+
) -> Optional[Union[Any, HTTPValidationError]]:
109109
""" """
110110

111111
return (

Diff for: end_to_end_tests/golden-record/my_test_api_client/api/tests/json_body_tests_json_body_post.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ def _get_kwargs(
2929
}
3030

3131

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

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

4343

44-
def _build_response(*, response: httpx.Response) -> Response[Union[HTTPValidationError, None]]:
44+
def _build_response(*, response: httpx.Response) -> Response[Union[Any, HTTPValidationError]]:
4545
return Response(
4646
status_code=response.status_code,
4747
content=response.content,
@@ -54,7 +54,7 @@ def sync_detailed(
5454
*,
5555
client: Client,
5656
json_body: AModel,
57-
) -> Response[Union[HTTPValidationError, None]]:
57+
) -> Response[Union[Any, HTTPValidationError]]:
5858
kwargs = _get_kwargs(
5959
client=client,
6060
json_body=json_body,
@@ -71,7 +71,7 @@ def sync(
7171
*,
7272
client: Client,
7373
json_body: AModel,
74-
) -> Optional[Union[HTTPValidationError, None]]:
74+
) -> Optional[Union[Any, HTTPValidationError]]:
7575
"""Try sending a JSON body"""
7676

7777
return sync_detailed(
@@ -84,7 +84,7 @@ async def asyncio_detailed(
8484
*,
8585
client: Client,
8686
json_body: AModel,
87-
) -> Response[Union[HTTPValidationError, None]]:
87+
) -> Response[Union[Any, HTTPValidationError]]:
8888
kwargs = _get_kwargs(
8989
client=client,
9090
json_body=json_body,
@@ -100,7 +100,7 @@ async def asyncio(
100100
*,
101101
client: Client,
102102
json_body: AModel,
103-
) -> Optional[Union[HTTPValidationError, None]]:
103+
) -> Optional[Union[Any, HTTPValidationError]]:
104104
"""Try sending a JSON body"""
105105

106106
return (

Diff for: end_to_end_tests/golden-record/my_test_api_client/api/tests/no_response_tests_no_response_get.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def _get_kwargs(
2323
}
2424

2525

26-
def _build_response(*, response: httpx.Response) -> Response[None]:
26+
def _build_response(*, response: httpx.Response) -> Response[Any]:
2727
return Response(
2828
status_code=response.status_code,
2929
content=response.content,
@@ -35,7 +35,7 @@ def _build_response(*, response: httpx.Response) -> Response[None]:
3535
def sync_detailed(
3636
*,
3737
client: Client,
38-
) -> Response[None]:
38+
) -> Response[Any]:
3939
kwargs = _get_kwargs(
4040
client=client,
4141
)
@@ -50,7 +50,7 @@ def sync_detailed(
5050
async def asyncio_detailed(
5151
*,
5252
client: Client,
53-
) -> Response[None]:
53+
) -> Response[Any]:
5454
kwargs = _get_kwargs(
5555
client=client,
5656
)

Diff for: end_to_end_tests/golden-record/my_test_api_client/api/tests/optional_value_tests_optional_query_param.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ def _get_kwargs(
3535
}
3636

3737

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

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

4949

50-
def _build_response(*, response: httpx.Response) -> Response[Union[HTTPValidationError, None]]:
50+
def _build_response(*, response: httpx.Response) -> Response[Union[Any, HTTPValidationError]]:
5151
return Response(
5252
status_code=response.status_code,
5353
content=response.content,
@@ -60,7 +60,7 @@ def sync_detailed(
6060
*,
6161
client: Client,
6262
query_param: Union[Unset, List[str]] = UNSET,
63-
) -> Response[Union[HTTPValidationError, None]]:
63+
) -> Response[Union[Any, HTTPValidationError]]:
6464
kwargs = _get_kwargs(
6565
client=client,
6666
query_param=query_param,
@@ -77,7 +77,7 @@ def sync(
7777
*,
7878
client: Client,
7979
query_param: Union[Unset, List[str]] = UNSET,
80-
) -> Optional[Union[HTTPValidationError, None]]:
80+
) -> Optional[Union[Any, HTTPValidationError]]:
8181
"""Test optional query parameters"""
8282

8383
return sync_detailed(
@@ -90,7 +90,7 @@ async def asyncio_detailed(
9090
*,
9191
client: Client,
9292
query_param: Union[Unset, List[str]] = UNSET,
93-
) -> Response[Union[HTTPValidationError, None]]:
93+
) -> Response[Union[Any, HTTPValidationError]]:
9494
kwargs = _get_kwargs(
9595
client=client,
9696
query_param=query_param,
@@ -106,7 +106,7 @@ async def asyncio(
106106
*,
107107
client: Client,
108108
query_param: Union[Unset, List[str]] = UNSET,
109-
) -> Optional[Union[HTTPValidationError, None]]:
109+
) -> Optional[Union[Any, HTTPValidationError]]:
110110
"""Test optional query parameters"""
111111

112112
return (

Diff for: end_to_end_tests/golden-record/my_test_api_client/api/tests/post_form_data.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def _get_kwargs(
2626
}
2727

2828

29-
def _build_response(*, response: httpx.Response) -> Response[None]:
29+
def _build_response(*, response: httpx.Response) -> Response[Any]:
3030
return Response(
3131
status_code=response.status_code,
3232
content=response.content,
@@ -39,7 +39,7 @@ def sync_detailed(
3939
*,
4040
client: Client,
4141
form_data: AFormData,
42-
) -> Response[None]:
42+
) -> Response[Any]:
4343
kwargs = _get_kwargs(
4444
client=client,
4545
form_data=form_data,
@@ -56,7 +56,7 @@ async def asyncio_detailed(
5656
*,
5757
client: Client,
5858
form_data: AFormData,
59-
) -> Response[None]:
59+
) -> Response[Any]:
6060
kwargs = _get_kwargs(
6161
client=client,
6262
form_data=form_data,

Diff for: end_to_end_tests/golden-record/my_test_api_client/api/tests/token_with_cookie_auth_token_with_cookie_get.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def _get_kwargs(
2626
}
2727

2828

29-
def _build_response(*, response: httpx.Response) -> Response[None]:
29+
def _build_response(*, response: httpx.Response) -> Response[Any]:
3030
return Response(
3131
status_code=response.status_code,
3232
content=response.content,
@@ -39,7 +39,7 @@ def sync_detailed(
3939
*,
4040
client: Client,
4141
my_token: str,
42-
) -> Response[None]:
42+
) -> Response[Any]:
4343
kwargs = _get_kwargs(
4444
client=client,
4545
my_token=my_token,
@@ -56,7 +56,7 @@ async def asyncio_detailed(
5656
*,
5757
client: Client,
5858
my_token: str,
59-
) -> Response[None]:
59+
) -> Response[Any]:
6060
kwargs = _get_kwargs(
6161
client=client,
6262
my_token=my_token,

0 commit comments

Comments
 (0)