Skip to content

Commit b2e8e7d

Browse files
author
Constantinos Symeonides
committed
feat: Support non-file fields in Multipart requests
1 parent 339fce7 commit b2e8e7d

20 files changed

+247
-30
lines changed

Diff for: end_to_end_tests/golden-record-custom/custom_e2e/models/body_upload_file_tests_upload_post.py

+10-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
from io import BytesIO
2-
from typing import Any, Dict, Type, TypeVar
2+
from typing import Any, Dict, Type, TypeVar, Union
33

44
import attr
55

6-
from ..types import File
6+
from ..types import UNSET, File, Unset
77

88
T = TypeVar("T", bound="BodyUploadFileTestsUploadPost")
99

@@ -13,16 +13,21 @@ class BodyUploadFileTestsUploadPost:
1313
""" """
1414

1515
some_file: File
16+
some_string: Union[Unset, str] = "some_default_string"
1617

1718
def to_dict(self) -> Dict[str, Any]:
1819
some_file = self.some_file.to_tuple()
1920

21+
some_string = self.some_string
22+
2023
field_dict: Dict[str, Any] = {}
2124
field_dict.update(
2225
{
2326
"some_file": some_file,
2427
}
2528
)
29+
if some_string is not UNSET:
30+
field_dict["some_string"] = some_string
2631

2732
return field_dict
2833

@@ -31,8 +36,11 @@ def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T:
3136
d = src_dict.copy()
3237
some_file = File(payload=BytesIO(d.pop("some_file")))
3338

39+
some_string = d.pop("some_string", UNSET)
40+
3441
body_upload_file_tests_upload_post = cls(
3542
some_file=some_file,
43+
some_string=some_string,
3644
)
3745

3846
return body_upload_file_tests_upload_post

Diff for: end_to_end_tests/golden-record/my_test_api_client/api/tests/defaults_tests_defaults_post.py

+11-1
Original file line numberDiff line numberDiff line change
@@ -130,14 +130,24 @@ def _get_kwargs(
130130
params.update(json_required_model_prop)
131131
params = {k: v for k, v in params.items() if v is not UNSET and v is not None}
132132

133-
return {
133+
data: Dict[str, Any] = {}
134+
files: Dict[str, Any] = {}
135+
136+
kwargs = {
134137
"url": url,
135138
"headers": headers,
136139
"cookies": cookies,
137140
"timeout": client.get_timeout(),
138141
"params": params,
139142
}
140143

144+
if data:
145+
kwargs["data"] = data
146+
if files:
147+
kwargs["files"] = files
148+
149+
return kwargs
150+
141151

142152
def _parse_response(*, response: httpx.Response) -> Optional[Union[None, HTTPValidationError]]:
143153
if response.status_code == 200:

Diff for: end_to_end_tests/golden-record/my_test_api_client/api/tests/get_basic_list_of_booleans.py

+11-1
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,23 @@ def _get_kwargs(
1515
headers: Dict[str, Any] = client.get_headers()
1616
cookies: Dict[str, Any] = client.get_cookies()
1717

18-
return {
18+
data: Dict[str, Any] = {}
19+
files: Dict[str, Any] = {}
20+
21+
kwargs = {
1922
"url": url,
2023
"headers": headers,
2124
"cookies": cookies,
2225
"timeout": client.get_timeout(),
2326
}
2427

28+
if data:
29+
kwargs["data"] = data
30+
if files:
31+
kwargs["files"] = files
32+
33+
return kwargs
34+
2535

2636
def _parse_response(*, response: httpx.Response) -> Optional[List[bool]]:
2737
if response.status_code == 200:

Diff for: end_to_end_tests/golden-record/my_test_api_client/api/tests/get_basic_list_of_floats.py

+11-1
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,23 @@ def _get_kwargs(
1515
headers: Dict[str, Any] = client.get_headers()
1616
cookies: Dict[str, Any] = client.get_cookies()
1717

18-
return {
18+
data: Dict[str, Any] = {}
19+
files: Dict[str, Any] = {}
20+
21+
kwargs = {
1922
"url": url,
2023
"headers": headers,
2124
"cookies": cookies,
2225
"timeout": client.get_timeout(),
2326
}
2427

28+
if data:
29+
kwargs["data"] = data
30+
if files:
31+
kwargs["files"] = files
32+
33+
return kwargs
34+
2535

2636
def _parse_response(*, response: httpx.Response) -> Optional[List[float]]:
2737
if response.status_code == 200:

Diff for: end_to_end_tests/golden-record/my_test_api_client/api/tests/get_basic_list_of_integers.py

+11-1
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,23 @@ def _get_kwargs(
1515
headers: Dict[str, Any] = client.get_headers()
1616
cookies: Dict[str, Any] = client.get_cookies()
1717

18-
return {
18+
data: Dict[str, Any] = {}
19+
files: Dict[str, Any] = {}
20+
21+
kwargs = {
1922
"url": url,
2023
"headers": headers,
2124
"cookies": cookies,
2225
"timeout": client.get_timeout(),
2326
}
2427

28+
if data:
29+
kwargs["data"] = data
30+
if files:
31+
kwargs["files"] = files
32+
33+
return kwargs
34+
2535

2636
def _parse_response(*, response: httpx.Response) -> Optional[List[int]]:
2737
if response.status_code == 200:

Diff for: end_to_end_tests/golden-record/my_test_api_client/api/tests/get_basic_list_of_strings.py

+11-1
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,23 @@ def _get_kwargs(
1515
headers: Dict[str, Any] = client.get_headers()
1616
cookies: Dict[str, Any] = client.get_cookies()
1717

18-
return {
18+
data: Dict[str, Any] = {}
19+
files: Dict[str, Any] = {}
20+
21+
kwargs = {
1922
"url": url,
2023
"headers": headers,
2124
"cookies": cookies,
2225
"timeout": client.get_timeout(),
2326
}
2427

28+
if data:
29+
kwargs["data"] = data
30+
if files:
31+
kwargs["files"] = files
32+
33+
return kwargs
34+
2535

2636
def _parse_response(*, response: httpx.Response) -> Optional[List[str]]:
2737
if response.status_code == 200:

Diff for: end_to_end_tests/golden-record/my_test_api_client/api/tests/get_user_list.py

+11-1
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,24 @@ def _get_kwargs(
3838
}
3939
params = {k: v for k, v in params.items() if v is not UNSET and v is not None}
4040

41-
return {
41+
data: Dict[str, Any] = {}
42+
files: Dict[str, Any] = {}
43+
44+
kwargs = {
4245
"url": url,
4346
"headers": headers,
4447
"cookies": cookies,
4548
"timeout": client.get_timeout(),
4649
"params": params,
4750
}
4851

52+
if data:
53+
kwargs["data"] = data
54+
if files:
55+
kwargs["files"] = files
56+
57+
return kwargs
58+
4959

5060
def _parse_response(*, response: httpx.Response) -> Optional[Union[List[AModel], HTTPValidationError]]:
5161
if response.status_code == 200:

Diff for: end_to_end_tests/golden-record/my_test_api_client/api/tests/int_enum_tests_int_enum_post.py

+11-1
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,24 @@ def _get_kwargs(
2525
}
2626
params = {k: v for k, v in params.items() if v is not UNSET and v is not None}
2727

28-
return {
28+
data: Dict[str, Any] = {}
29+
files: Dict[str, Any] = {}
30+
31+
kwargs = {
2932
"url": url,
3033
"headers": headers,
3134
"cookies": cookies,
3235
"timeout": client.get_timeout(),
3336
"params": params,
3437
}
3538

39+
if data:
40+
kwargs["data"] = data
41+
if files:
42+
kwargs["files"] = files
43+
44+
return kwargs
45+
3646

3747
def _parse_response(*, response: httpx.Response) -> Optional[Union[None, HTTPValidationError]]:
3848
if response.status_code == 200:

Diff for: end_to_end_tests/golden-record/my_test_api_client/api/tests/json_body_tests_json_body_post.py

+11-1
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,24 @@ def _get_kwargs(
2020

2121
json_json_body = json_body.to_dict()
2222

23-
return {
23+
data: Dict[str, Any] = {}
24+
files: Dict[str, Any] = {}
25+
26+
kwargs = {
2427
"url": url,
2528
"headers": headers,
2629
"cookies": cookies,
2730
"timeout": client.get_timeout(),
2831
"json": json_json_body,
2932
}
3033

34+
if data:
35+
kwargs["data"] = data
36+
if files:
37+
kwargs["files"] = files
38+
39+
return kwargs
40+
3141

3242
def _parse_response(*, response: httpx.Response) -> Optional[Union[None, HTTPValidationError]]:
3343
if response.status_code == 200:

Diff for: end_to_end_tests/golden-record/my_test_api_client/api/tests/no_response_tests_no_response_get.py

+11-1
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,23 @@ def _get_kwargs(
1515
headers: Dict[str, Any] = client.get_headers()
1616
cookies: Dict[str, Any] = client.get_cookies()
1717

18-
return {
18+
data: Dict[str, Any] = {}
19+
files: Dict[str, Any] = {}
20+
21+
kwargs = {
1922
"url": url,
2023
"headers": headers,
2124
"cookies": cookies,
2225
"timeout": client.get_timeout(),
2326
}
2427

28+
if data:
29+
kwargs["data"] = data
30+
if files:
31+
kwargs["files"] = files
32+
33+
return kwargs
34+
2535

2636
def _build_response(*, response: httpx.Response) -> Response[None]:
2737
return Response(

Diff for: end_to_end_tests/golden-record/my_test_api_client/api/tests/octet_stream_tests_octet_stream_get.py

+11-1
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,23 @@ def _get_kwargs(
1616
headers: Dict[str, Any] = client.get_headers()
1717
cookies: Dict[str, Any] = client.get_cookies()
1818

19-
return {
19+
data: Dict[str, Any] = {}
20+
files: Dict[str, Any] = {}
21+
22+
kwargs = {
2023
"url": url,
2124
"headers": headers,
2225
"cookies": cookies,
2326
"timeout": client.get_timeout(),
2427
}
2528

29+
if data:
30+
kwargs["data"] = data
31+
if files:
32+
kwargs["files"] = files
33+
34+
return kwargs
35+
2636

2737
def _parse_response(*, response: httpx.Response) -> Optional[File]:
2838
if response.status_code == 200:

Diff for: end_to_end_tests/golden-record/my_test_api_client/api/tests/optional_value_tests_optional_query_param.py

+11-1
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,24 @@ def _get_kwargs(
2626
}
2727
params = {k: v for k, v in params.items() if v is not UNSET and v is not None}
2828

29-
return {
29+
data: Dict[str, Any] = {}
30+
files: Dict[str, Any] = {}
31+
32+
kwargs = {
3033
"url": url,
3134
"headers": headers,
3235
"cookies": cookies,
3336
"timeout": client.get_timeout(),
3437
"params": params,
3538
}
3639

40+
if data:
41+
kwargs["data"] = data
42+
if files:
43+
kwargs["files"] = files
44+
45+
return kwargs
46+
3747

3848
def _parse_response(*, response: httpx.Response) -> Optional[Union[None, HTTPValidationError]]:
3949
if response.status_code == 200:

Diff for: end_to_end_tests/golden-record/my_test_api_client/api/tests/test_inline_objects.py

+11-1
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,24 @@ def _get_kwargs(
2020

2121
json_json_body = json_body.to_dict()
2222

23-
return {
23+
data: Dict[str, Any] = {}
24+
files: Dict[str, Any] = {}
25+
26+
kwargs = {
2427
"url": url,
2528
"headers": headers,
2629
"cookies": cookies,
2730
"timeout": client.get_timeout(),
2831
"json": json_json_body,
2932
}
3033

34+
if data:
35+
kwargs["data"] = data
36+
if files:
37+
kwargs["files"] = files
38+
39+
return kwargs
40+
3141

3242
def _parse_response(*, response: httpx.Response) -> Optional[TestInlineObjectsResponse_200]:
3343
if response.status_code == 200:

Diff for: end_to_end_tests/golden-record/my_test_api_client/api/tests/token_with_cookie_auth_token_with_cookie_get.py

+11-1
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,23 @@ def _get_kwargs(
1818

1919
cookies["MyToken"] = my_token
2020

21-
return {
21+
data: Dict[str, Any] = {}
22+
files: Dict[str, Any] = {}
23+
24+
kwargs = {
2225
"url": url,
2326
"headers": headers,
2427
"cookies": cookies,
2528
"timeout": client.get_timeout(),
2629
}
2730

31+
if data:
32+
kwargs["data"] = data
33+
if files:
34+
kwargs["files"] = files
35+
36+
return kwargs
37+
2838

2939
def _parse_response(*, response: httpx.Response) -> Optional[Union[None, None]]:
3040
if response.status_code == 200:

0 commit comments

Comments
 (0)