Skip to content

Commit 218e77b

Browse files
committed
feat: Include both UNSET and None static types for nullable or optional query params [#421, #380]. Thanks @forest-benchling!
1 parent 0ca21aa commit 218e77b

File tree

13 files changed

+302
-445
lines changed

13 files changed

+302
-445
lines changed

Diff for: end_to_end_tests/custom-templates-golden-record/my_test_api_client/api/__init__.py

+5
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from typing import Type
44

55
from my_test_api_client.api.default import DefaultEndpoints
6+
from my_test_api_client.api.location import LocationEndpoints
67
from my_test_api_client.api.parameters import ParametersEndpoints
78
from my_test_api_client.api.tag1 import Tag1Endpoints
89
from my_test_api_client.api.tests import TestsEndpoints
@@ -24,3 +25,7 @@ def parameters(cls) -> Type[ParametersEndpoints]:
2425
@classmethod
2526
def tag1(cls) -> Type[Tag1Endpoints]:
2627
return Tag1Endpoints
28+
29+
@classmethod
30+
def location(cls) -> Type[LocationEndpoints]:
31+
return LocationEndpoints
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
""" Contains methods for accessing the API Endpoints """
2+
3+
import types
4+
5+
from my_test_api_client.api.location import get_location_query_optionality
6+
7+
8+
class LocationEndpoints:
9+
@classmethod
10+
def get_location_query_optionality(cls) -> types.ModuleType:
11+
return get_location_query_optionality

Diff for: end_to_end_tests/custom-templates-golden-record/my_test_api_client/api/tests/__init__.py

-8
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
json_body_tests_json_body_post,
1414
no_response_tests_no_response_get,
1515
octet_stream_tests_octet_stream_get,
16-
optional_value_tests_optional_query_param,
1716
post_form_data,
1817
test_inline_objects,
1918
token_with_cookie_auth_token_with_cookie_get,
@@ -129,13 +128,6 @@ def test_inline_objects(cls) -> types.ModuleType:
129128
"""
130129
return test_inline_objects
131130

132-
@classmethod
133-
def optional_value_tests_optional_query_param(cls) -> types.ModuleType:
134-
"""
135-
Test optional query parameters
136-
"""
137-
return optional_value_tests_optional_query_param
138-
139131
@classmethod
140132
def token_with_cookie_auth_token_with_cookie_get(cls) -> types.ModuleType:
141133
"""

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
@@ -9,7 +9,7 @@
99
def _get_kwargs(
1010
*,
1111
client: Client,
12-
common: Union[Unset, str] = UNSET,
12+
common: Union[Unset, None, str] = UNSET,
1313
) -> Dict[str, Any]:
1414
url = "{}/common_parameters".format(client.base_url)
1515

@@ -42,7 +42,7 @@ def _build_response(*, response: httpx.Response) -> Response[Any]:
4242
def sync_detailed(
4343
*,
4444
client: Client,
45-
common: Union[Unset, str] = UNSET,
45+
common: Union[Unset, None, str] = UNSET,
4646
) -> Response[Any]:
4747
kwargs = _get_kwargs(
4848
client=client,
@@ -59,7 +59,7 @@ def sync_detailed(
5959
async def asyncio_detailed(
6060
*,
6161
client: Client,
62-
common: Union[Unset, str] = UNSET,
62+
common: Union[Unset, None, str] = UNSET,
6363
) -> Response[Any]:
6464
kwargs = _get_kwargs(
6565
client=client,

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
@@ -9,7 +9,7 @@
99
def _get_kwargs(
1010
*,
1111
client: Client,
12-
common: Union[Unset, str] = UNSET,
12+
common: Union[Unset, None, str] = UNSET,
1313
) -> Dict[str, Any]:
1414
url = "{}/common_parameters".format(client.base_url)
1515

@@ -42,7 +42,7 @@ def _build_response(*, response: httpx.Response) -> Response[Any]:
4242
def sync_detailed(
4343
*,
4444
client: Client,
45-
common: Union[Unset, str] = UNSET,
45+
common: Union[Unset, None, str] = UNSET,
4646
) -> Response[Any]:
4747
kwargs = _get_kwargs(
4848
client=client,
@@ -59,7 +59,7 @@ def sync_detailed(
5959
async def asyncio_detailed(
6060
*,
6161
client: Client,
62-
common: Union[Unset, str] = UNSET,
62+
common: Union[Unset, None, str] = UNSET,
6363
) -> Response[Any]:
6464
kwargs = _get_kwargs(
6565
client=client,

Diff for: end_to_end_tests/golden-record/my_test_api_client/api/location/__init__.py

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
from typing import Any, Dict, Union
2+
3+
import httpx
4+
5+
from ...client import Client
6+
from ...types import UNSET, Response, Unset
7+
8+
9+
def _get_kwargs(
10+
*,
11+
client: Client,
12+
not_null_required: str,
13+
null_required: Union[Unset, None, str] = UNSET,
14+
null_not_required: Union[Unset, None, str] = UNSET,
15+
not_null_not_required: Union[Unset, None, str] = UNSET,
16+
) -> Dict[str, Any]:
17+
url = "{}/location/query/optionality".format(client.base_url)
18+
19+
headers: Dict[str, Any] = client.get_headers()
20+
cookies: Dict[str, Any] = client.get_cookies()
21+
22+
params: Dict[str, Any] = {
23+
"not_null_required": not_null_required,
24+
"null_required": null_required,
25+
"null_not_required": null_not_required,
26+
"not_null_not_required": not_null_not_required,
27+
}
28+
params = {k: v for k, v in params.items() if v is not UNSET and v is not None}
29+
30+
return {
31+
"url": url,
32+
"headers": headers,
33+
"cookies": cookies,
34+
"timeout": client.get_timeout(),
35+
"params": params,
36+
}
37+
38+
39+
def _build_response(*, response: httpx.Response) -> Response[Any]:
40+
return Response(
41+
status_code=response.status_code,
42+
content=response.content,
43+
headers=response.headers,
44+
parsed=None,
45+
)
46+
47+
48+
def sync_detailed(
49+
*,
50+
client: Client,
51+
not_null_required: str,
52+
null_required: Union[Unset, None, str] = UNSET,
53+
null_not_required: Union[Unset, None, str] = UNSET,
54+
not_null_not_required: Union[Unset, None, str] = UNSET,
55+
) -> Response[Any]:
56+
kwargs = _get_kwargs(
57+
client=client,
58+
not_null_required=not_null_required,
59+
null_required=null_required,
60+
null_not_required=null_not_required,
61+
not_null_not_required=not_null_not_required,
62+
)
63+
64+
response = httpx.get(
65+
**kwargs,
66+
)
67+
68+
return _build_response(response=response)
69+
70+
71+
async def asyncio_detailed(
72+
*,
73+
client: Client,
74+
not_null_required: str,
75+
null_required: Union[Unset, None, str] = UNSET,
76+
null_not_required: Union[Unset, None, str] = UNSET,
77+
not_null_not_required: Union[Unset, None, str] = UNSET,
78+
) -> Response[Any]:
79+
kwargs = _get_kwargs(
80+
client=client,
81+
not_null_required=not_null_required,
82+
null_required=null_required,
83+
null_not_required=null_not_required,
84+
not_null_not_required=not_null_not_required,
85+
)
86+
87+
async with httpx.AsyncClient() as _client:
88+
response = await _client.get(**kwargs)
89+
90+
return _build_response(response=response)

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
@@ -10,7 +10,7 @@ def _get_kwargs(
1010
*,
1111
client: Client,
1212
param_path: Union[Unset, str] = UNSET,
13-
param_query: Union[Unset, str] = UNSET,
13+
param_query: Union[Unset, None, str] = UNSET,
1414
) -> Dict[str, Any]:
1515
url = "{}/same-name-multiple-locations/{param}".format(client.base_url, param=param_path)
1616

@@ -44,7 +44,7 @@ def sync_detailed(
4444
*,
4545
client: Client,
4646
param_path: Union[Unset, str] = UNSET,
47-
param_query: Union[Unset, str] = UNSET,
47+
param_query: Union[Unset, None, str] = UNSET,
4848
) -> Response[Any]:
4949
kwargs = _get_kwargs(
5050
client=client,
@@ -63,7 +63,7 @@ async def asyncio_detailed(
6363
*,
6464
client: Client,
6565
param_path: Union[Unset, str] = UNSET,
66-
param_query: Union[Unset, str] = UNSET,
66+
param_query: Union[Unset, None, str] = UNSET,
6767
) -> Response[Any]:
6868
kwargs = _get_kwargs(
6969
client=client,

0 commit comments

Comments
 (0)