Skip to content

Commit 39faebf

Browse files
Merge remote-tracking branch 'upstream/main' into forest-union-3
2 parents 682c5ab + d98e349 commit 39faebf

32 files changed

+475
-91
lines changed

CHANGELOG.md

+7-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8-
## 0.8.0 - Unreleased
8+
## 0.8.0 - 2021-02-19
99

1010
### Breaking Changes
1111

@@ -19,9 +19,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1919
project info.
2020
- `none` will not create a project folder at all, only the inner package folder (which won't be inner anymore)
2121
- Attempt to detect and alert users if they are using an unsupported version of OpenAPI (#281).
22-
- Fixes `Enum` deserialization when the value is `UNSET`.
23-
- Add handling of application/vnd.api+json media type.
22+
- The media type application/vnd.api+json will now be handled just like application/json (#307). Thanks @jrversteegh!
2423
- Support passing models into query parameters (#316). Thanks @forest-benchling!
24+
- Add support for cookie parameters (#326).
25+
- New `--file-encoding` command line option (#330). Sets the encoding used when writing generated files (defaults to utf-8). Thanks @dongfangtianyu!
2526

2627
### Changes
2728

@@ -31,10 +32,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3132

3233
### Fixes
3334

35+
- Endpoint tags are now sanitized during parsing to fix an issue where `My Tag` and `MyTag` are seen as two different tags but are then later unified, causing errors when creating directories. Thanks @p1-ra! (#328)
3436
- Parser will softly ignore value error during schema responses' status code convertion from string to integer (not a number). Errors will be reported to the end user and parsing will continue to proceed (#327).
3537
- The generated `from_dict` and `to_dict` methods of models will now properly handle `nullable` and `not required` properties that are themselves generated models (#315). Thanks @forest-benchling!
38+
- Fixed a typo in the async example in generated README.md files (#337). Thanks @synchronizing!
3639
- Fix deserialization of `None` and `Unset` properties for all types by unifying the checks (#334). Thanks @forest-benchling!
3740
- If duplicate model names are detected during generation, you'll now get an error message instead of broken code (#336). Thanks @forest-benchling!
41+
- Fixes `Enum` deserialization when the value is `UNSET` (#306). Thanks @bowenwr!
3842

3943
## 0.7.3 - 2020-12-21
4044

end_to_end_tests/golden-record-custom/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ Or do the same thing with an async version:
3434

3535
```python
3636
from custom_e2e.models import MyDataModel
37-
from custom_e2e.async_api.my_tag import get_my_data_model
37+
from custom_e2e.api.my_tag import get_my_data_model
3838
from custom_e2e.types import Response
3939

4040
my_data: MyDataModel = await get_my_data_model.asyncio(client=client)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
from typing import Optional
2+
3+
import httpx
4+
5+
from ...types import Response
6+
7+
Client = httpx.Client
8+
9+
10+
def _parse_response(*, response: httpx.Response) -> Optional[Union[None, None]]:
11+
if response.status_code == 200:
12+
response_200 = None
13+
14+
return response_200
15+
if response.status_code == 401:
16+
response_401 = None
17+
18+
return response_401
19+
return None
20+
21+
22+
def _build_response(*, response: httpx.Response) -> Response[Union[None, None]]:
23+
return Response(
24+
status_code=response.status_code,
25+
content=response.content,
26+
headers=response.headers,
27+
parsed=_parse_response(response=response),
28+
)
29+
30+
31+
def httpx_request(
32+
*,
33+
client: Client,
34+
my_token: str,
35+
) -> Response[Union[None, None]]:
36+
37+
response = client.request(
38+
"get",
39+
"/auth/token_with_cookie",
40+
)
41+
42+
return _build_response(response=response)

end_to_end_tests/golden-record/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ Or do the same thing with an async version:
3434

3535
```python
3636
from my_test_api_client.models import MyDataModel
37-
from my_test_api_client.async_api.my_tag import get_my_data_model
37+
from my_test_api_client.api.my_tag import get_my_data_model
3838
from my_test_api_client.types import Response
3939

4040
my_data: MyDataModel = await get_my_data_model.asyncio(client=client)

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ def _get_kwargs(
3535
url = "{}/tests/defaults".format(client.base_url)
3636

3737
headers: Dict[str, Any] = client.get_headers()
38+
cookies: Dict[str, Any] = client.get_cookies()
3839

3940
json_not_required_not_nullable_datetime_prop: Union[Unset, str] = UNSET
4041
if not isinstance(not_required_not_nullable_datetime_prop, Unset):
@@ -132,7 +133,7 @@ def _get_kwargs(
132133
return {
133134
"url": url,
134135
"headers": headers,
135-
"cookies": client.get_cookies(),
136+
"cookies": cookies,
136137
"timeout": client.get_timeout(),
137138
"params": params,
138139
}

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,12 @@ def _get_kwargs(
1313
url = "{}/tests/basic_lists/booleans".format(client.base_url)
1414

1515
headers: Dict[str, Any] = client.get_headers()
16+
cookies: Dict[str, Any] = client.get_cookies()
1617

1718
return {
1819
"url": url,
1920
"headers": headers,
20-
"cookies": client.get_cookies(),
21+
"cookies": cookies,
2122
"timeout": client.get_timeout(),
2223
}
2324

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,12 @@ def _get_kwargs(
1313
url = "{}/tests/basic_lists/floats".format(client.base_url)
1414

1515
headers: Dict[str, Any] = client.get_headers()
16+
cookies: Dict[str, Any] = client.get_cookies()
1617

1718
return {
1819
"url": url,
1920
"headers": headers,
20-
"cookies": client.get_cookies(),
21+
"cookies": cookies,
2122
"timeout": client.get_timeout(),
2223
}
2324

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,12 @@ def _get_kwargs(
1313
url = "{}/tests/basic_lists/integers".format(client.base_url)
1414

1515
headers: Dict[str, Any] = client.get_headers()
16+
cookies: Dict[str, Any] = client.get_cookies()
1617

1718
return {
1819
"url": url,
1920
"headers": headers,
20-
"cookies": client.get_cookies(),
21+
"cookies": cookies,
2122
"timeout": client.get_timeout(),
2223
}
2324

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,12 @@ def _get_kwargs(
1313
url = "{}/tests/basic_lists/strings".format(client.base_url)
1414

1515
headers: Dict[str, Any] = client.get_headers()
16+
cookies: Dict[str, Any] = client.get_cookies()
1617

1718
return {
1819
"url": url,
1920
"headers": headers,
20-
"cookies": client.get_cookies(),
21+
"cookies": cookies,
2122
"timeout": client.get_timeout(),
2223
}
2324

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ def _get_kwargs(
1919
url = "{}/tests/".format(client.base_url)
2020

2121
headers: Dict[str, Any] = client.get_headers()
22+
cookies: Dict[str, Any] = client.get_cookies()
2223

2324
json_an_enum_value = []
2425
for an_enum_value_item_data in an_enum_value:
@@ -40,7 +41,7 @@ def _get_kwargs(
4041
return {
4142
"url": url,
4243
"headers": headers,
43-
"cookies": client.get_cookies(),
44+
"cookies": cookies,
4445
"timeout": client.get_timeout(),
4546
"params": params,
4647
}

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ def _get_kwargs(
1616
url = "{}/tests/int_enum".format(client.base_url)
1717

1818
headers: Dict[str, Any] = client.get_headers()
19+
cookies: Dict[str, Any] = client.get_cookies()
1920

2021
json_int_enum = int_enum.value
2122

@@ -27,7 +28,7 @@ def _get_kwargs(
2728
return {
2829
"url": url,
2930
"headers": headers,
30-
"cookies": client.get_cookies(),
31+
"cookies": cookies,
3132
"timeout": client.get_timeout(),
3233
"params": params,
3334
}

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,14 @@ def _get_kwargs(
1616
url = "{}/tests/json_body".format(client.base_url)
1717

1818
headers: Dict[str, Any] = client.get_headers()
19+
cookies: Dict[str, Any] = client.get_cookies()
1920

2021
json_json_body = json_body.to_dict()
2122

2223
return {
2324
"url": url,
2425
"headers": headers,
25-
"cookies": client.get_cookies(),
26+
"cookies": cookies,
2627
"timeout": client.get_timeout(),
2728
"json": json_json_body,
2829
}

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,12 @@ def _get_kwargs(
1313
url = "{}/tests/no_response".format(client.base_url)
1414

1515
headers: Dict[str, Any] = client.get_headers()
16+
cookies: Dict[str, Any] = client.get_cookies()
1617

1718
return {
1819
"url": url,
1920
"headers": headers,
20-
"cookies": client.get_cookies(),
21+
"cookies": cookies,
2122
"timeout": client.get_timeout(),
2223
}
2324

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,12 @@ def _get_kwargs(
1414
url = "{}/tests/octet_stream".format(client.base_url)
1515

1616
headers: Dict[str, Any] = client.get_headers()
17+
cookies: Dict[str, Any] = client.get_cookies()
1718

1819
return {
1920
"url": url,
2021
"headers": headers,
21-
"cookies": client.get_cookies(),
22+
"cookies": cookies,
2223
"timeout": client.get_timeout(),
2324
}
2425

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ def _get_kwargs(
1515
url = "{}/tests/optional_query_param/".format(client.base_url)
1616

1717
headers: Dict[str, Any] = client.get_headers()
18+
cookies: Dict[str, Any] = client.get_cookies()
1819

1920
json_query_param: Union[Unset, List[str]] = UNSET
2021
if not isinstance(query_param, Unset):
@@ -28,7 +29,7 @@ def _get_kwargs(
2829
return {
2930
"url": url,
3031
"headers": headers,
31-
"cookies": client.get_cookies(),
32+
"cookies": cookies,
3233
"timeout": client.get_timeout(),
3334
"params": params,
3435
}

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,14 @@ def _get_kwargs(
1616
url = "{}/tests/inline_objects".format(client.base_url)
1717

1818
headers: Dict[str, Any] = client.get_headers()
19+
cookies: Dict[str, Any] = client.get_cookies()
1920

2021
json_json_body = json_body.to_dict()
2122

2223
return {
2324
"url": url,
2425
"headers": headers,
25-
"cookies": client.get_cookies(),
26+
"cookies": cookies,
2627
"timeout": client.get_timeout(),
2728
"json": json_json_body,
2829
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
from typing import Any, Dict, Optional, Union
2+
3+
import httpx
4+
5+
from ...client import Client
6+
from ...types import Response
7+
8+
9+
def _get_kwargs(
10+
*,
11+
client: Client,
12+
my_token: str,
13+
) -> Dict[str, Any]:
14+
url = "{}/auth/token_with_cookie".format(client.base_url)
15+
16+
headers: Dict[str, Any] = client.get_headers()
17+
cookies: Dict[str, Any] = client.get_cookies()
18+
19+
cookies["MyToken"] = my_token
20+
21+
return {
22+
"url": url,
23+
"headers": headers,
24+
"cookies": cookies,
25+
"timeout": client.get_timeout(),
26+
}
27+
28+
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]]:
42+
return Response(
43+
status_code=response.status_code,
44+
content=response.content,
45+
headers=response.headers,
46+
parsed=_parse_response(response=response),
47+
)
48+
49+
50+
def sync_detailed(
51+
*,
52+
client: Client,
53+
my_token: str,
54+
) -> Response[Union[None, None]]:
55+
kwargs = _get_kwargs(
56+
client=client,
57+
my_token=my_token,
58+
)
59+
60+
response = httpx.get(
61+
**kwargs,
62+
)
63+
64+
return _build_response(response=response)
65+
66+
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+
80+
async def asyncio_detailed(
81+
*,
82+
client: Client,
83+
my_token: str,
84+
) -> Response[Union[None, None]]:
85+
kwargs = _get_kwargs(
86+
client=client,
87+
my_token=my_token,
88+
)
89+
90+
async with httpx.AsyncClient() as _client:
91+
response = await _client.get(**kwargs)
92+
93+
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)