Skip to content

Commit 22c9f2c

Browse files
committed
refactor: Simplify response type generation by moving logic to Python
1 parent 6cd6d05 commit 22c9f2c

11 files changed

+92
-191
lines changed

end_to_end_tests/golden-record/my_test_api_client/api/tests/defaults_tests_defaults_post.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ def _get_kwargs(
139139
}
140140

141141

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

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

153153

154-
def _build_response(*, response: httpx.Response) -> Response[Union[None, HTTPValidationError]]:
154+
def _build_response(*, response: httpx.Response) -> Response[Union[HTTPValidationError, None]]:
155155
return Response(
156156
status_code=response.status_code,
157157
content=response.content,
@@ -180,7 +180,7 @@ def sync_detailed(
180180
required_model_prop: ModelWithUnionProperty,
181181
nullable_model_prop: Union[ModelWithUnionProperty, None, Unset] = UNSET,
182182
nullable_required_model_prop: Union[ModelWithUnionProperty, None],
183-
) -> Response[Union[None, HTTPValidationError]]:
183+
) -> Response[Union[HTTPValidationError, None]]:
184184
kwargs = _get_kwargs(
185185
client=client,
186186
string_prop=string_prop,
@@ -229,7 +229,7 @@ def sync(
229229
required_model_prop: ModelWithUnionProperty,
230230
nullable_model_prop: Union[ModelWithUnionProperty, None, Unset] = UNSET,
231231
nullable_required_model_prop: Union[ModelWithUnionProperty, None],
232-
) -> Optional[Union[None, HTTPValidationError]]:
232+
) -> Optional[Union[HTTPValidationError, None]]:
233233
""" """
234234

235235
return sync_detailed(
@@ -274,7 +274,7 @@ async def asyncio_detailed(
274274
required_model_prop: ModelWithUnionProperty,
275275
nullable_model_prop: Union[ModelWithUnionProperty, None, Unset] = UNSET,
276276
nullable_required_model_prop: Union[ModelWithUnionProperty, None],
277-
) -> Response[Union[None, HTTPValidationError]]:
277+
) -> Response[Union[HTTPValidationError, None]]:
278278
kwargs = _get_kwargs(
279279
client=client,
280280
string_prop=string_prop,
@@ -322,7 +322,7 @@ async def asyncio(
322322
required_model_prop: ModelWithUnionProperty,
323323
nullable_model_prop: Union[ModelWithUnionProperty, None, Unset] = UNSET,
324324
nullable_required_model_prop: Union[ModelWithUnionProperty, None],
325-
) -> Optional[Union[None, HTTPValidationError]]:
325+
) -> Optional[Union[HTTPValidationError, None]]:
326326
""" """
327327

328328
return (

end_to_end_tests/golden-record/my_test_api_client/api/tests/get_user_list.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def _get_kwargs(
4747
}
4848

4949

50-
def _parse_response(*, response: httpx.Response) -> Optional[Union[List[AModel], HTTPValidationError]]:
50+
def _parse_response(*, response: httpx.Response) -> Optional[Union[HTTPValidationError, List[AModel]]]:
5151
if response.status_code == 200:
5252
response_200 = []
5353
_response_200 = response.json()
@@ -68,7 +68,7 @@ def _parse_response(*, response: httpx.Response) -> Optional[Union[List[AModel],
6868
return None
6969

7070

71-
def _build_response(*, response: httpx.Response) -> Response[Union[List[AModel], HTTPValidationError]]:
71+
def _build_response(*, response: httpx.Response) -> Response[Union[HTTPValidationError, List[AModel]]]:
7272
return Response(
7373
status_code=response.status_code,
7474
content=response.content,
@@ -82,7 +82,7 @@ def sync_detailed(
8282
client: Client,
8383
an_enum_value: List[AnEnum],
8484
some_date: Union[datetime.date, datetime.datetime],
85-
) -> Response[Union[List[AModel], HTTPValidationError]]:
85+
) -> Response[Union[HTTPValidationError, List[AModel]]]:
8686
kwargs = _get_kwargs(
8787
client=client,
8888
an_enum_value=an_enum_value,
@@ -101,7 +101,7 @@ def sync(
101101
client: Client,
102102
an_enum_value: List[AnEnum],
103103
some_date: Union[datetime.date, datetime.datetime],
104-
) -> Optional[Union[List[AModel], HTTPValidationError]]:
104+
) -> Optional[Union[HTTPValidationError, List[AModel]]]:
105105
""" Get a list of things """
106106

107107
return sync_detailed(
@@ -116,7 +116,7 @@ async def asyncio_detailed(
116116
client: Client,
117117
an_enum_value: List[AnEnum],
118118
some_date: Union[datetime.date, datetime.datetime],
119-
) -> Response[Union[List[AModel], HTTPValidationError]]:
119+
) -> Response[Union[HTTPValidationError, List[AModel]]]:
120120
kwargs = _get_kwargs(
121121
client=client,
122122
an_enum_value=an_enum_value,
@@ -134,7 +134,7 @@ async def asyncio(
134134
client: Client,
135135
an_enum_value: List[AnEnum],
136136
some_date: Union[datetime.date, datetime.datetime],
137-
) -> Optional[Union[List[AModel], HTTPValidationError]]:
137+
) -> Optional[Union[HTTPValidationError, List[AModel]]]:
138138
""" Get a list of things """
139139

140140
return (

end_to_end_tests/golden-record/my_test_api_client/api/tests/int_enum_tests_int_enum_post.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def _get_kwargs(
3434
}
3535

3636

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

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

4848

49-
def _build_response(*, response: httpx.Response) -> Response[Union[None, HTTPValidationError]]:
49+
def _build_response(*, response: httpx.Response) -> Response[Union[HTTPValidationError, None]]:
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[None, HTTPValidationError]]:
62+
) -> Response[Union[HTTPValidationError, None]]:
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[None, HTTPValidationError]]:
79+
) -> Optional[Union[HTTPValidationError, None]]:
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[None, HTTPValidationError]]:
92+
) -> Response[Union[HTTPValidationError, None]]:
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[None, HTTPValidationError]]:
108+
) -> Optional[Union[HTTPValidationError, None]]:
109109
""" """
110110

111111
return (

end_to_end_tests/golden-record/my_test_api_client/api/tests/json_body_tests_json_body_post.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def _get_kwargs(
2929
}
3030

3131

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

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

4343

44-
def _build_response(*, response: httpx.Response) -> Response[Union[None, HTTPValidationError]]:
44+
def _build_response(*, response: httpx.Response) -> Response[Union[HTTPValidationError, None]]:
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[None, HTTPValidationError]]:
57+
) -> Response[Union[HTTPValidationError, None]]:
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[None, HTTPValidationError]]:
74+
) -> Optional[Union[HTTPValidationError, None]]:
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[None, HTTPValidationError]]:
87+
) -> Response[Union[HTTPValidationError, None]]:
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[None, HTTPValidationError]]:
103+
) -> Optional[Union[HTTPValidationError, None]]:
104104
""" Try sending a JSON body """
105105

106106
return (

end_to_end_tests/golden-record/my_test_api_client/api/tests/optional_value_tests_optional_query_param.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def _get_kwargs(
3535
}
3636

3737

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

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

4949

50-
def _build_response(*, response: httpx.Response) -> Response[Union[None, HTTPValidationError]]:
50+
def _build_response(*, response: httpx.Response) -> Response[Union[HTTPValidationError, None]]:
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[None, HTTPValidationError]]:
63+
) -> Response[Union[HTTPValidationError, None]]:
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[None, HTTPValidationError]]:
80+
) -> Optional[Union[HTTPValidationError, None]]:
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[None, HTTPValidationError]]:
93+
) -> Response[Union[HTTPValidationError, None]]:
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[None, HTTPValidationError]]:
109+
) -> Optional[Union[HTTPValidationError, None]]:
110110
""" Test optional query parameters """
111111

112112
return (
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Any, Dict, Optional, Union
1+
from typing import Any, Dict
22

33
import httpx
44

@@ -26,32 +26,20 @@ def _get_kwargs(
2626
}
2727

2828

29-
def _parse_response(*, response: httpx.Response) -> Optional[Union[None, None]]:
30-
if response.status_code == 200:
31-
response_200 = None
32-
33-
return response_200
34-
if response.status_code == 401:
35-
response_401 = None
36-
37-
return response_401
38-
return None
39-
40-
41-
def _build_response(*, response: httpx.Response) -> Response[Union[None, None]]:
29+
def _build_response(*, response: httpx.Response) -> Response[None]:
4230
return Response(
4331
status_code=response.status_code,
4432
content=response.content,
4533
headers=response.headers,
46-
parsed=_parse_response(response=response),
34+
parsed=None,
4735
)
4836

4937

5038
def sync_detailed(
5139
*,
5240
client: Client,
5341
my_token: str,
54-
) -> Response[Union[None, None]]:
42+
) -> Response[None]:
5543
kwargs = _get_kwargs(
5644
client=client,
5745
my_token=my_token,
@@ -64,24 +52,11 @@ def sync_detailed(
6452
return _build_response(response=response)
6553

6654

67-
def sync(
68-
*,
69-
client: Client,
70-
my_token: str,
71-
) -> Optional[Union[None, None]]:
72-
""" Test optional cookie parameters """
73-
74-
return sync_detailed(
75-
client=client,
76-
my_token=my_token,
77-
).parsed
78-
79-
8055
async def asyncio_detailed(
8156
*,
8257
client: Client,
8358
my_token: str,
84-
) -> Response[Union[None, None]]:
59+
) -> Response[None]:
8560
kwargs = _get_kwargs(
8661
client=client,
8762
my_token=my_token,
@@ -91,18 +66,3 @@ async def asyncio_detailed(
9166
response = await _client.get(**kwargs)
9267

9368
return _build_response(response=response)
94-
95-
96-
async def asyncio(
97-
*,
98-
client: Client,
99-
my_token: str,
100-
) -> Optional[Union[None, None]]:
101-
""" Test optional cookie parameters """
102-
103-
return (
104-
await asyncio_detailed(
105-
client=client,
106-
my_token=my_token,
107-
)
108-
).parsed

0 commit comments

Comments
 (0)