Skip to content

Commit 75d250d

Browse files
Add another check for nullable
1 parent d1b33b2 commit 75d250d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+2697
-5
lines changed

end_to_end_tests/golden-record-custom/custom_e2e/api/tests/defaults_tests_defaults_post.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,10 @@ def httpx_request(
4646
float_prop: Union[Unset, None, float] = 3.14,
4747
int_prop: Union[Unset, None, int] = 7,
4848
boolean_prop: Union[Unset, None, bool] = False,
49-
list_prop: Union[Unset, None, List[AnEnum]] = None,
49+
list_prop: Union[Unset, None, List[AnEnum]] = UNSET,
5050
union_prop: Union[Unset, None, float, str] = "not a float",
5151
union_prop_with_ref: Union[Unset, None, float, AnEnum] = 0.6,
52-
enum_prop: Union[Unset, None, AnEnum] = None,
52+
enum_prop: Union[Unset, None, AnEnum] = UNSET,
5353
) -> Response[Union[None, HTTPValidationError]]:
5454

5555
json_datetime_prop: Union[Unset, str] = UNSET

end_to_end_tests/golden-record-custom/custom_e2e/api/tests/optional_value_tests_optional_query_param.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def _build_response(*, response: httpx.Response) -> Response[Union[None, HTTPVal
3636
def httpx_request(
3737
*,
3838
client: Client,
39-
query_param: Union[Unset, None, List[str]] = None,
39+
query_param: Union[Unset, None, List[str]] = UNSET,
4040
) -> Response[Union[None, HTTPValidationError]]:
4141

4242
json_query_param: Union[Unset, List[Any]] = UNSET
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
__pycache__/
2+
build/
3+
dist/
4+
*.egg-info/
5+
.pytest_cache/
6+
7+
# pyenv
8+
.python-version
9+
10+
# Environments
11+
.env
12+
.venv
13+
14+
# mypy
15+
.mypy_cache/
16+
.dmypy.json
17+
dmypy.json
18+
19+
# JetBrains
20+
.idea/
21+
22+
/coverage.xml
23+
/.coverage
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# my-test-api-client
2+
A client library for accessing My Test API
3+
4+
## Usage
5+
First, create a client:
6+
7+
```python
8+
from my_test_api_client import Client
9+
10+
client = Client(base_url="https://api.example.com")
11+
```
12+
13+
If the endpoints you're going to hit require authentication, use `AuthenticatedClient` instead:
14+
15+
```python
16+
from my_test_api_client import AuthenticatedClient
17+
18+
client = AuthenticatedClient(base_url="https://api.example.com", token="SuperSecretToken")
19+
```
20+
21+
Now call your endpoint and use your models:
22+
23+
```python
24+
from my_test_api_client.models import MyDataModel
25+
from my_test_api_client.api.my_tag import get_my_data_model
26+
from my_test_api_client.types import Response
27+
28+
my_data: MyDataModel = get_my_data_model.sync(client=client)
29+
# or if you need more info (e.g. status_code)
30+
response: Response[MyDataModel] = get_my_data_model.sync_detailed(client=client)
31+
```
32+
33+
Or do the same thing with an async version:
34+
35+
```python
36+
from my_test_api_client.models import MyDataModel
37+
from my_test_api_client.async_api.my_tag import get_my_data_model
38+
from my_test_api_client.types import Response
39+
40+
my_data: MyDataModel = await get_my_data_model.asyncio(client=client)
41+
response: Response[MyDataModel] = await get_my_data_model.asyncio_detailed(client=client)
42+
```
43+
44+
Things to know:
45+
1. Every path/method combo becomes a Python module with four functions:
46+
1. `sync`: Blocking request that returns parsed data (if successful) or `None`
47+
1. `sync_detailed`: Blocking request that always returns a `Request`, optionally with `parsed` set if the request was successful.
48+
1. `asyncio`: Like `sync` but the async instead of blocking
49+
1. `asyncio_detailed`: Like `sync_detailed` by async instead of blocking
50+
51+
1. All path/query params, and bodies become method arguments.
52+
1. If your endpoint had any tags on it, the first tag will be used as a module name for the function (my_tag above)
53+
1. Any endpoint which did not have a tag will be in `my_test_api_client.api.default`
54+
55+
## Building / publishing this Client
56+
This project uses [Poetry](https://python-poetry.org/) to manage dependencies and packaging. Here are the basics:
57+
1. Update the metadata in pyproject.toml (e.g. authors, version)
58+
1. If you're using a private repository, configure it with Poetry
59+
1. `poetry config repositories.<your-repository-name> <url-to-your-repository>`
60+
1. `poetry config http-basic.<your-repository-name> <username> <password>`
61+
1. Publish the client with `poetry publish --build -r <your-repository-name>` or, if for public PyPI, just `poetry publish --build`
62+
63+
If you want to install this client into another project without publishing it (e.g. for development) then:
64+
1. If that project **is using Poetry**, you can simply do `poetry add <path-to-this-client>` from that project
65+
1. If that project is not using Poetry:
66+
1. Build a wheel with `poetry build -f wheel`
67+
1. Install that wheel from the other project `pip install <path-to-wheel>`
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
""" A client library for accessing My Test API """
2+
from .client import AuthenticatedClient, Client
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
""" Contains methods for accessing the API """

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

Whitespace-only changes.
Lines changed: 250 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,250 @@
1+
import datetime
2+
from typing import Any, Dict, List, Optional, Union
3+
4+
import httpx
5+
from dateutil.parser import isoparse
6+
7+
from ...client import Client
8+
from ...models.an_enum import AnEnum
9+
from ...models.http_validation_error import HTTPValidationError
10+
from ...types import UNSET, Response, Unset
11+
12+
13+
def _get_kwargs(
14+
*,
15+
client: Client,
16+
string_prop: Union[Unset, None, str] = "the default string",
17+
datetime_prop: Union[Unset, None, datetime.datetime] = isoparse("1010-10-10T00:00:00"),
18+
date_prop: Union[Unset, None, datetime.date] = isoparse("1010-10-10").date(),
19+
float_prop: Union[Unset, None, float] = 3.14,
20+
int_prop: Union[Unset, None, int] = 7,
21+
boolean_prop: Union[Unset, None, bool] = False,
22+
list_prop: Union[Unset, None, List[AnEnum]] = UNSET,
23+
union_prop: Union[Unset, None, float, str] = "not a float",
24+
union_prop_with_ref: Union[Unset, None, float, AnEnum] = 0.6,
25+
enum_prop: Union[Unset, None, AnEnum] = UNSET,
26+
) -> Dict[str, Any]:
27+
url = "{}/tests/defaults".format(client.base_url)
28+
29+
headers: Dict[str, Any] = client.get_headers()
30+
31+
json_datetime_prop: Union[Unset, str] = UNSET
32+
if not isinstance(datetime_prop, Unset) and datetime_prop is not None:
33+
json_datetime_prop = datetime_prop.isoformat()
34+
35+
json_date_prop: Union[Unset, str] = UNSET
36+
if not isinstance(date_prop, Unset) and date_prop is not None:
37+
json_date_prop = date_prop.isoformat()
38+
39+
json_list_prop: Union[Unset, List[Any]] = UNSET
40+
if not isinstance(list_prop, Unset) and list_prop is not None:
41+
json_list_prop = []
42+
for list_prop_item_data in list_prop:
43+
list_prop_item = list_prop_item_data.value
44+
45+
json_list_prop.append(list_prop_item)
46+
47+
json_union_prop: Union[Unset, float, str]
48+
if isinstance(union_prop, Unset) or union_prop is None:
49+
json_union_prop = UNSET
50+
else:
51+
json_union_prop = union_prop
52+
53+
json_union_prop_with_ref: Union[Unset, float, AnEnum]
54+
if isinstance(union_prop_with_ref, Unset) or union_prop_with_ref is None:
55+
json_union_prop_with_ref = UNSET
56+
elif isinstance(union_prop_with_ref, AnEnum):
57+
json_union_prop_with_ref = UNSET
58+
if not isinstance(union_prop_with_ref, Unset):
59+
json_union_prop_with_ref = union_prop_with_ref
60+
61+
else:
62+
json_union_prop_with_ref = union_prop_with_ref
63+
64+
json_enum_prop: Union[Unset, AnEnum] = UNSET
65+
if not isinstance(enum_prop, Unset) and enum_prop is not None:
66+
json_enum_prop = enum_prop
67+
68+
params: Dict[str, Any] = {}
69+
if string_prop is not UNSET and string_prop is not None:
70+
params["string_prop"] = string_prop
71+
if datetime_prop is not UNSET and datetime_prop is not None:
72+
params["datetime_prop"] = json_datetime_prop
73+
if date_prop is not UNSET and date_prop is not None:
74+
params["date_prop"] = json_date_prop
75+
if float_prop is not UNSET and float_prop is not None:
76+
params["float_prop"] = float_prop
77+
if int_prop is not UNSET and int_prop is not None:
78+
params["int_prop"] = int_prop
79+
if boolean_prop is not UNSET and boolean_prop is not None:
80+
params["boolean_prop"] = boolean_prop
81+
if list_prop is not UNSET and list_prop is not None:
82+
params["list_prop"] = json_list_prop
83+
if union_prop is not UNSET and union_prop is not None:
84+
params["union_prop"] = json_union_prop
85+
if union_prop_with_ref is not UNSET and union_prop_with_ref is not None:
86+
params["union_prop_with_ref"] = json_union_prop_with_ref
87+
if enum_prop is not UNSET and enum_prop is not None:
88+
params["enum_prop"] = json_enum_prop
89+
90+
return {
91+
"url": url,
92+
"headers": headers,
93+
"cookies": client.get_cookies(),
94+
"timeout": client.get_timeout(),
95+
"params": params,
96+
}
97+
98+
99+
def _parse_response(*, response: httpx.Response) -> Optional[Union[None, HTTPValidationError]]:
100+
if response.status_code == 200:
101+
response_200 = None
102+
103+
return response_200
104+
if response.status_code == 422:
105+
response_422 = HTTPValidationError.from_dict(response.json())
106+
107+
return response_422
108+
return None
109+
110+
111+
def _build_response(*, response: httpx.Response) -> Response[Union[None, HTTPValidationError]]:
112+
return Response(
113+
status_code=response.status_code,
114+
content=response.content,
115+
headers=response.headers,
116+
parsed=_parse_response(response=response),
117+
)
118+
119+
120+
def sync_detailed(
121+
*,
122+
client: Client,
123+
string_prop: Union[Unset, None, str] = "the default string",
124+
datetime_prop: Union[Unset, None, datetime.datetime] = isoparse("1010-10-10T00:00:00"),
125+
date_prop: Union[Unset, None, datetime.date] = isoparse("1010-10-10").date(),
126+
float_prop: Union[Unset, None, float] = 3.14,
127+
int_prop: Union[Unset, None, int] = 7,
128+
boolean_prop: Union[Unset, None, bool] = False,
129+
list_prop: Union[Unset, None, List[AnEnum]] = UNSET,
130+
union_prop: Union[Unset, None, float, str] = "not a float",
131+
union_prop_with_ref: Union[Unset, None, float, AnEnum] = 0.6,
132+
enum_prop: Union[Unset, None, AnEnum] = UNSET,
133+
) -> Response[Union[None, HTTPValidationError]]:
134+
kwargs = _get_kwargs(
135+
client=client,
136+
string_prop=string_prop,
137+
datetime_prop=datetime_prop,
138+
date_prop=date_prop,
139+
float_prop=float_prop,
140+
int_prop=int_prop,
141+
boolean_prop=boolean_prop,
142+
list_prop=list_prop,
143+
union_prop=union_prop,
144+
union_prop_with_ref=union_prop_with_ref,
145+
enum_prop=enum_prop,
146+
)
147+
148+
response = httpx.post(
149+
**kwargs,
150+
)
151+
152+
return _build_response(response=response)
153+
154+
155+
def sync(
156+
*,
157+
client: Client,
158+
string_prop: Union[Unset, None, str] = "the default string",
159+
datetime_prop: Union[Unset, None, datetime.datetime] = isoparse("1010-10-10T00:00:00"),
160+
date_prop: Union[Unset, None, datetime.date] = isoparse("1010-10-10").date(),
161+
float_prop: Union[Unset, None, float] = 3.14,
162+
int_prop: Union[Unset, None, int] = 7,
163+
boolean_prop: Union[Unset, None, bool] = False,
164+
list_prop: Union[Unset, None, List[AnEnum]] = UNSET,
165+
union_prop: Union[Unset, None, float, str] = "not a float",
166+
union_prop_with_ref: Union[Unset, None, float, AnEnum] = 0.6,
167+
enum_prop: Union[Unset, None, AnEnum] = UNSET,
168+
) -> Optional[Union[None, HTTPValidationError]]:
169+
""" """
170+
171+
return sync_detailed(
172+
client=client,
173+
string_prop=string_prop,
174+
datetime_prop=datetime_prop,
175+
date_prop=date_prop,
176+
float_prop=float_prop,
177+
int_prop=int_prop,
178+
boolean_prop=boolean_prop,
179+
list_prop=list_prop,
180+
union_prop=union_prop,
181+
union_prop_with_ref=union_prop_with_ref,
182+
enum_prop=enum_prop,
183+
).parsed
184+
185+
186+
async def asyncio_detailed(
187+
*,
188+
client: Client,
189+
string_prop: Union[Unset, None, str] = "the default string",
190+
datetime_prop: Union[Unset, None, datetime.datetime] = isoparse("1010-10-10T00:00:00"),
191+
date_prop: Union[Unset, None, datetime.date] = isoparse("1010-10-10").date(),
192+
float_prop: Union[Unset, None, float] = 3.14,
193+
int_prop: Union[Unset, None, int] = 7,
194+
boolean_prop: Union[Unset, None, bool] = False,
195+
list_prop: Union[Unset, None, List[AnEnum]] = UNSET,
196+
union_prop: Union[Unset, None, float, str] = "not a float",
197+
union_prop_with_ref: Union[Unset, None, float, AnEnum] = 0.6,
198+
enum_prop: Union[Unset, None, AnEnum] = UNSET,
199+
) -> Response[Union[None, HTTPValidationError]]:
200+
kwargs = _get_kwargs(
201+
client=client,
202+
string_prop=string_prop,
203+
datetime_prop=datetime_prop,
204+
date_prop=date_prop,
205+
float_prop=float_prop,
206+
int_prop=int_prop,
207+
boolean_prop=boolean_prop,
208+
list_prop=list_prop,
209+
union_prop=union_prop,
210+
union_prop_with_ref=union_prop_with_ref,
211+
enum_prop=enum_prop,
212+
)
213+
214+
async with httpx.AsyncClient() as _client:
215+
response = await _client.post(**kwargs)
216+
217+
return _build_response(response=response)
218+
219+
220+
async def asyncio(
221+
*,
222+
client: Client,
223+
string_prop: Union[Unset, None, str] = "the default string",
224+
datetime_prop: Union[Unset, None, datetime.datetime] = isoparse("1010-10-10T00:00:00"),
225+
date_prop: Union[Unset, None, datetime.date] = isoparse("1010-10-10").date(),
226+
float_prop: Union[Unset, None, float] = 3.14,
227+
int_prop: Union[Unset, None, int] = 7,
228+
boolean_prop: Union[Unset, None, bool] = False,
229+
list_prop: Union[Unset, None, List[AnEnum]] = UNSET,
230+
union_prop: Union[Unset, None, float, str] = "not a float",
231+
union_prop_with_ref: Union[Unset, None, float, AnEnum] = 0.6,
232+
enum_prop: Union[Unset, None, AnEnum] = UNSET,
233+
) -> Optional[Union[None, HTTPValidationError]]:
234+
""" """
235+
236+
return (
237+
await asyncio_detailed(
238+
client=client,
239+
string_prop=string_prop,
240+
datetime_prop=datetime_prop,
241+
date_prop=date_prop,
242+
float_prop=float_prop,
243+
int_prop=int_prop,
244+
boolean_prop=boolean_prop,
245+
list_prop=list_prop,
246+
union_prop=union_prop,
247+
union_prop_with_ref=union_prop_with_ref,
248+
enum_prop=enum_prop,
249+
)
250+
).parsed

0 commit comments

Comments
 (0)