Skip to content

Commit c91bd92

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

File tree

13 files changed

+288
-569
lines changed

13 files changed

+288
-569
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 .default import DefaultEndpoints
6+
from .location import LocationEndpoints
67
from .parameters import ParametersEndpoints
78
from .tag1 import Tag1Endpoints
89
from .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,105 @@
1+
import datetime
2+
from typing import Any, Dict, Union
3+
4+
import httpx
5+
6+
from ...client import Client
7+
from ...types import UNSET, Response, Unset
8+
9+
10+
def _get_kwargs(
11+
*,
12+
client: Client,
13+
not_null_required: datetime.datetime,
14+
null_required: Union[Unset, None, datetime.datetime] = UNSET,
15+
null_not_required: Union[Unset, None, datetime.datetime] = UNSET,
16+
not_null_not_required: Union[Unset, None, datetime.datetime] = UNSET,
17+
) -> Dict[str, Any]:
18+
url = "{}/location/query/optionality".format(client.base_url)
19+
20+
headers: Dict[str, Any] = client.get_headers()
21+
cookies: Dict[str, Any] = client.get_cookies()
22+
23+
json_not_null_required = not_null_required.isoformat()
24+
25+
json_null_required: Union[Unset, None, str] = UNSET
26+
if not isinstance(null_required, Unset):
27+
json_null_required = null_required.isoformat() if null_required else None
28+
29+
json_null_not_required: Union[Unset, None, str] = UNSET
30+
if not isinstance(null_not_required, Unset):
31+
json_null_not_required = null_not_required.isoformat() if null_not_required else None
32+
33+
json_not_null_not_required: Union[Unset, None, str] = UNSET
34+
if not isinstance(not_null_not_required, Unset):
35+
json_not_null_not_required = not_null_not_required.isoformat() if not_null_not_required else None
36+
37+
params: Dict[str, Any] = {
38+
"not_null_required": json_not_null_required,
39+
"null_required": json_null_required,
40+
"null_not_required": json_null_not_required,
41+
"not_null_not_required": json_not_null_not_required,
42+
}
43+
params = {k: v for k, v in params.items() if v is not UNSET and v is not None}
44+
45+
return {
46+
"url": url,
47+
"headers": headers,
48+
"cookies": cookies,
49+
"timeout": client.get_timeout(),
50+
"params": params,
51+
}
52+
53+
54+
def _build_response(*, response: httpx.Response) -> Response[Any]:
55+
return Response(
56+
status_code=response.status_code,
57+
content=response.content,
58+
headers=response.headers,
59+
parsed=None,
60+
)
61+
62+
63+
def sync_detailed(
64+
*,
65+
client: Client,
66+
not_null_required: datetime.datetime,
67+
null_required: Union[Unset, None, datetime.datetime] = UNSET,
68+
null_not_required: Union[Unset, None, datetime.datetime] = UNSET,
69+
not_null_not_required: Union[Unset, None, datetime.datetime] = UNSET,
70+
) -> Response[Any]:
71+
kwargs = _get_kwargs(
72+
client=client,
73+
not_null_required=not_null_required,
74+
null_required=null_required,
75+
null_not_required=null_not_required,
76+
not_null_not_required=not_null_not_required,
77+
)
78+
79+
response = httpx.get(
80+
**kwargs,
81+
)
82+
83+
return _build_response(response=response)
84+
85+
86+
async def asyncio_detailed(
87+
*,
88+
client: Client,
89+
not_null_required: datetime.datetime,
90+
null_required: Union[Unset, None, datetime.datetime] = UNSET,
91+
null_not_required: Union[Unset, None, datetime.datetime] = UNSET,
92+
not_null_not_required: Union[Unset, None, datetime.datetime] = UNSET,
93+
) -> Response[Any]:
94+
kwargs = _get_kwargs(
95+
client=client,
96+
not_null_required=not_null_required,
97+
null_required=null_required,
98+
null_not_required=null_not_required,
99+
not_null_not_required=not_null_not_required,
100+
)
101+
102+
async with httpx.AsyncClient() as _client:
103+
response = await _client.get(**kwargs)
104+
105+
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: str,
13-
param_query: Union[Unset, str] = UNSET,
13+
param_query: Union[Unset, None, str] = UNSET,
1414
param_header: Union[Unset, str] = UNSET,
1515
param_cookie: Union[Unset, str] = UNSET,
1616
) -> Dict[str, Any]:
@@ -54,7 +54,7 @@ def sync_detailed(
5454
param_path: str,
5555
param_query: Union[Unset, str] = UNSET,
5656
param_header: Union[Unset, str] = UNSET,
57-
param_cookie: Union[Unset, str] = UNSET,
57+
param_cookie: Union[Unset, None, str] = UNSET,
5858
) -> Response[Any]:
5959
kwargs = _get_kwargs(
6060
client=client,
@@ -77,7 +77,7 @@ async def asyncio_detailed(
7777
param_path: str,
7878
param_query: Union[Unset, str] = UNSET,
7979
param_header: Union[Unset, str] = UNSET,
80-
param_cookie: Union[Unset, str] = UNSET,
80+
param_cookie: Union[Unset, None, str] = UNSET,
8181
) -> Response[Any]:
8282
kwargs = _get_kwargs(
8383
client=client,

0 commit comments

Comments
 (0)