Skip to content

Commit 5de5920

Browse files
dbantyJohn98Zakaria
andcommitted
fix: Non-string header values [#552, #553, #566]. Thanks @John98Zakaria!
Closes #552. BREAKING CHANGE: Header values will be explicitly transformed or omitted instead of blindly passed to httpx as-is. Co-authored-by: John Sorial <[email protected]> Co-authored-by: dbanty <[email protected]>
1 parent 23aebd1 commit 5de5920

File tree

59 files changed

+805
-270
lines changed

Some content is hidden

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

59 files changed

+805
-270
lines changed

end_to_end_tests/custom-templates-golden-record/my_test_api_client/api/location/__init__.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,14 @@
22

33
import types
44

5-
from . import get_location_query_optionality
5+
from . import get_location_header_types, get_location_query_optionality
66

77

88
class LocationEndpoints:
99
@classmethod
1010
def get_location_query_optionality(cls) -> types.ModuleType:
1111
return get_location_query_optionality
12+
13+
@classmethod
14+
def get_location_header_types(cls) -> types.ModuleType:
15+
return get_location_header_types

end_to_end_tests/golden-record/my_test_api_client/api/default/get_common_parameters.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ def _get_kwargs(
1313
) -> Dict[str, Any]:
1414
url = "{}/common_parameters".format(client.base_url)
1515

16-
headers: Dict[str, Any] = client.get_headers()
16+
headers: Dict[str, str] = client.get_headers()
1717
cookies: Dict[str, Any] = client.get_cookies()
1818

19-
params: Dict[str, Any] = {
20-
"common": common,
21-
}
19+
params: Dict[str, Any] = {}
20+
params["common"] = common
21+
2222
params = {k: v for k, v in params.items() if v is not UNSET and v is not None}
2323

2424
return {

end_to_end_tests/golden-record/my_test_api_client/api/default/post_common_parameters.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ def _get_kwargs(
1313
) -> Dict[str, Any]:
1414
url = "{}/common_parameters".format(client.base_url)
1515

16-
headers: Dict[str, Any] = client.get_headers()
16+
headers: Dict[str, str] = client.get_headers()
1717
cookies: Dict[str, Any] = client.get_cookies()
1818

19-
params: Dict[str, Any] = {
20-
"common": common,
21-
}
19+
params: Dict[str, Any] = {}
20+
params["common"] = common
21+
2222
params = {k: v for k, v in params.items() if v is not UNSET and v is not None}
2323

2424
return {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
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+
boolean_header: Union[Unset, bool] = UNSET,
13+
string_header: Union[Unset, str] = UNSET,
14+
number_header: Union[Unset, float] = UNSET,
15+
integer_header: Union[Unset, int] = UNSET,
16+
) -> Dict[str, Any]:
17+
url = "{}/location/header/types".format(client.base_url)
18+
19+
headers: Dict[str, str] = client.get_headers()
20+
cookies: Dict[str, Any] = client.get_cookies()
21+
22+
if not isinstance(boolean_header, Unset):
23+
headers["Boolean-Header"] = "true" if boolean_header else "false"
24+
25+
if not isinstance(string_header, Unset):
26+
headers["String-Header"] = string_header
27+
28+
if not isinstance(number_header, Unset):
29+
headers["Number-Header"] = str(number_header)
30+
31+
if not isinstance(integer_header, Unset):
32+
headers["Integer-Header"] = str(integer_header)
33+
34+
return {
35+
"method": "get",
36+
"url": url,
37+
"headers": headers,
38+
"cookies": cookies,
39+
"timeout": client.get_timeout(),
40+
}
41+
42+
43+
def _build_response(*, response: httpx.Response) -> Response[Any]:
44+
return Response(
45+
status_code=response.status_code,
46+
content=response.content,
47+
headers=response.headers,
48+
parsed=None,
49+
)
50+
51+
52+
def sync_detailed(
53+
*,
54+
client: Client,
55+
boolean_header: Union[Unset, bool] = UNSET,
56+
string_header: Union[Unset, str] = UNSET,
57+
number_header: Union[Unset, float] = UNSET,
58+
integer_header: Union[Unset, int] = UNSET,
59+
) -> Response[Any]:
60+
"""
61+
Args:
62+
boolean_header (Union[Unset, bool]):
63+
string_header (Union[Unset, str]):
64+
number_header (Union[Unset, float]):
65+
integer_header (Union[Unset, int]):
66+
67+
Returns:
68+
Response[Any]
69+
"""
70+
71+
kwargs = _get_kwargs(
72+
client=client,
73+
boolean_header=boolean_header,
74+
string_header=string_header,
75+
number_header=number_header,
76+
integer_header=integer_header,
77+
)
78+
79+
response = httpx.request(
80+
verify=client.verify_ssl,
81+
**kwargs,
82+
)
83+
84+
return _build_response(response=response)
85+
86+
87+
async def asyncio_detailed(
88+
*,
89+
client: Client,
90+
boolean_header: Union[Unset, bool] = UNSET,
91+
string_header: Union[Unset, str] = UNSET,
92+
number_header: Union[Unset, float] = UNSET,
93+
integer_header: Union[Unset, int] = UNSET,
94+
) -> Response[Any]:
95+
"""
96+
Args:
97+
boolean_header (Union[Unset, bool]):
98+
string_header (Union[Unset, str]):
99+
number_header (Union[Unset, float]):
100+
integer_header (Union[Unset, int]):
101+
102+
Returns:
103+
Response[Any]
104+
"""
105+
106+
kwargs = _get_kwargs(
107+
client=client,
108+
boolean_header=boolean_header,
109+
string_header=string_header,
110+
number_header=number_header,
111+
integer_header=integer_header,
112+
)
113+
114+
async with httpx.AsyncClient(verify=client.verify_ssl) as _client:
115+
response = await _client.request(**kwargs)
116+
117+
return _build_response(response=response)

end_to_end_tests/golden-record/my_test_api_client/api/location/get_location_query_optionality.py

+10-7
Original file line numberDiff line numberDiff line change
@@ -17,29 +17,32 @@ def _get_kwargs(
1717
) -> Dict[str, Any]:
1818
url = "{}/location/query/optionality".format(client.base_url)
1919

20-
headers: Dict[str, Any] = client.get_headers()
20+
headers: Dict[str, str] = client.get_headers()
2121
cookies: Dict[str, Any] = client.get_cookies()
2222

23+
params: Dict[str, Any] = {}
2324
json_not_null_required = not_null_required.isoformat()
2425

26+
params["not_null_required"] = json_not_null_required
27+
2528
json_null_required: Union[Unset, None, str] = UNSET
2629
if not isinstance(null_required, Unset):
2730
json_null_required = null_required.isoformat() if null_required else None
2831

32+
params["null_required"] = json_null_required
33+
2934
json_null_not_required: Union[Unset, None, str] = UNSET
3035
if not isinstance(null_not_required, Unset):
3136
json_null_not_required = null_not_required.isoformat() if null_not_required else None
3237

38+
params["null_not_required"] = json_null_not_required
39+
3340
json_not_null_not_required: Union[Unset, None, str] = UNSET
3441
if not isinstance(not_null_not_required, Unset):
3542
json_not_null_not_required = not_null_not_required.isoformat() if not_null_not_required else None
3643

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-
}
44+
params["not_null_not_required"] = json_not_null_not_required
45+
4346
params = {k: v for k, v in params.items() if v is not UNSET and v is not None}
4447

4548
return {

end_to_end_tests/golden-record/my_test_api_client/api/parameters/delete_common_parameters_overriding_param.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ def _get_kwargs(
1414
) -> Dict[str, Any]:
1515
url = "{}/common_parameters_overriding/{param}".format(client.base_url, param=param_path)
1616

17-
headers: Dict[str, Any] = client.get_headers()
17+
headers: Dict[str, str] = client.get_headers()
1818
cookies: Dict[str, Any] = client.get_cookies()
1919

20-
params: Dict[str, Any] = {
21-
"param": param_query,
22-
}
20+
params: Dict[str, Any] = {}
21+
params["param"] = param_query
22+
2323
params = {k: v for k, v in params.items() if v is not UNSET and v is not None}
2424

2525
return {

end_to_end_tests/golden-record/my_test_api_client/api/parameters/get_common_parameters_overriding_param.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ def _get_kwargs(
1414
) -> Dict[str, Any]:
1515
url = "{}/common_parameters_overriding/{param}".format(client.base_url, param=param_path)
1616

17-
headers: Dict[str, Any] = client.get_headers()
17+
headers: Dict[str, str] = client.get_headers()
1818
cookies: Dict[str, Any] = client.get_cookies()
1919

20-
params: Dict[str, Any] = {
21-
"param": param_query,
22-
}
20+
params: Dict[str, Any] = {}
21+
params["param"] = param_query
22+
2323
params = {k: v for k, v in params.items() if v is not UNSET and v is not None}
2424

2525
return {

end_to_end_tests/golden-record/my_test_api_client/api/parameters/get_same_name_multiple_locations_param.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,18 @@ def _get_kwargs(
1616
) -> Dict[str, Any]:
1717
url = "{}/same-name-multiple-locations/{param}".format(client.base_url, param=param_path)
1818

19-
headers: Dict[str, Any] = client.get_headers()
19+
headers: Dict[str, str] = client.get_headers()
2020
cookies: Dict[str, Any] = client.get_cookies()
2121

22-
if param_header is not UNSET:
22+
if not isinstance(param_header, Unset):
2323
headers["param"] = param_header
2424

2525
if param_cookie is not UNSET:
2626
cookies["param"] = param_cookie
2727

28-
params: Dict[str, Any] = {
29-
"param": param_query,
30-
}
28+
params: Dict[str, Any] = {}
29+
params["param"] = param_query
30+
3131
params = {k: v for k, v in params.items() if v is not UNSET and v is not None}
3232

3333
return {

end_to_end_tests/golden-record/my_test_api_client/api/parameters/multiple_path_parameters.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def _get_kwargs(
1818
client.base_url, param4=param4, param2=param2, param1=param1, param3=param3
1919
)
2020

21-
headers: Dict[str, Any] = client.get_headers()
21+
headers: Dict[str, str] = client.get_headers()
2222
cookies: Dict[str, Any] = client.get_cookies()
2323

2424
return {

end_to_end_tests/golden-record/my_test_api_client/api/tag1/get_tag_with_number.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def _get_kwargs(
1212
) -> Dict[str, Any]:
1313
url = "{}/tag_with_number".format(client.base_url)
1414

15-
headers: Dict[str, Any] = client.get_headers()
15+
headers: Dict[str, str] = client.get_headers()
1616
cookies: Dict[str, Any] = client.get_cookies()
1717

1818
return {

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

+26-16
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import datetime
2-
from typing import Any, Dict, List, Optional, Union
2+
from typing import Any, Dict, List, Optional, Union, cast
33

44
import httpx
55
from dateutil.parser import isoparse
@@ -28,23 +28,39 @@ def _get_kwargs(
2828
) -> Dict[str, Any]:
2929
url = "{}/tests/defaults".format(client.base_url)
3030

31-
headers: Dict[str, Any] = client.get_headers()
31+
headers: Dict[str, str] = client.get_headers()
3232
cookies: Dict[str, Any] = client.get_cookies()
3333

34+
params: Dict[str, Any] = {}
35+
params["string_prop"] = string_prop
36+
3437
json_date_prop = date_prop.isoformat()
38+
params["date_prop"] = json_date_prop
39+
40+
params["float_prop"] = float_prop
41+
42+
params["int_prop"] = int_prop
43+
44+
params["boolean_prop"] = boolean_prop
45+
3546
json_list_prop = []
3647
for list_prop_item_data in list_prop:
3748
list_prop_item = list_prop_item_data.value
3849

3950
json_list_prop.append(list_prop_item)
4051

52+
params["list_prop"] = json_list_prop
53+
4154
json_union_prop = union_prop
4255

56+
params["union_prop"] = json_union_prop
57+
4358
json_union_prop_with_ref: Union[None, Unset, float, str]
4459
if isinstance(union_prop_with_ref, Unset):
4560
json_union_prop_with_ref = UNSET
4661
elif union_prop_with_ref is None:
4762
json_union_prop_with_ref = None
63+
4864
elif isinstance(union_prop_with_ref, AnEnum):
4965
json_union_prop_with_ref = UNSET
5066
if not isinstance(union_prop_with_ref, Unset):
@@ -53,25 +69,20 @@ def _get_kwargs(
5369
else:
5470
json_union_prop_with_ref = union_prop_with_ref
5571

72+
params["union_prop_with_ref"] = json_union_prop_with_ref
73+
5674
json_enum_prop = enum_prop.value
5775

76+
params["enum_prop"] = json_enum_prop
77+
5878
json_model_prop = model_prop.to_dict()
5979

80+
params.update(json_model_prop)
81+
6082
json_required_model_prop = required_model_prop.to_dict()
6183

62-
params: Dict[str, Any] = {
63-
"string_prop": string_prop,
64-
"date_prop": json_date_prop,
65-
"float_prop": float_prop,
66-
"int_prop": int_prop,
67-
"boolean_prop": boolean_prop,
68-
"list_prop": json_list_prop,
69-
"union_prop": json_union_prop,
70-
"union_prop_with_ref": json_union_prop_with_ref,
71-
"enum_prop": json_enum_prop,
72-
}
73-
params.update(json_model_prop)
7484
params.update(json_required_model_prop)
85+
7586
params = {k: v for k, v in params.items() if v is not UNSET and v is not None}
7687

7788
return {
@@ -86,8 +97,7 @@ def _get_kwargs(
8697

8798
def _parse_response(*, response: httpx.Response) -> Optional[Union[Any, HTTPValidationError]]:
8899
if response.status_code == 200:
89-
response_200 = response.json()
90-
100+
response_200 = cast(Any, response.json())
91101
return response_200
92102
if response.status_code == 422:
93103
response_422 = HTTPValidationError.from_dict(response.json())

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def _get_kwargs(
1212
) -> Dict[str, Any]:
1313
url = "{}/tests/basic_lists/booleans".format(client.base_url)
1414

15-
headers: Dict[str, Any] = client.get_headers()
15+
headers: Dict[str, str] = client.get_headers()
1616
cookies: Dict[str, Any] = client.get_cookies()
1717

1818
return {

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def _get_kwargs(
1212
) -> Dict[str, Any]:
1313
url = "{}/tests/basic_lists/floats".format(client.base_url)
1414

15-
headers: Dict[str, Any] = client.get_headers()
15+
headers: Dict[str, str] = client.get_headers()
1616
cookies: Dict[str, Any] = client.get_cookies()
1717

1818
return {

0 commit comments

Comments
 (0)