Skip to content

Commit d0a542b

Browse files
author
Constantinos Symeonides
committed
fix: Detect File fields correctly
1 parent f42b358 commit d0a542b

File tree

4 files changed

+18
-8
lines changed

4 files changed

+18
-8
lines changed

end_to_end_tests/golden_record/my_test_api_client/api/tests/upload_file_tests_upload_post.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from ...client import Client
66
from ...models.body_upload_file_tests_upload_post import BodyUploadFileTestsUploadPost
77
from ...models.http_validation_error import HTTPValidationError
8-
from ...types import UNSET, File, Response, Unset
8+
from ...types import UNSET, Response, Unset, is_file
99

1010

1111
def _get_kwargs(
@@ -25,7 +25,7 @@ def _get_kwargs(
2525
files = {}
2626
data = {}
2727
for key, value in multipart_data.to_dict().items():
28-
if isinstance(value, File):
28+
if is_file(value):
2929
files[key] = value
3030
else:
3131
data[key] = value

end_to_end_tests/golden_record/my_test_api_client/types.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
""" Contains some shared types for properties """
2-
from typing import BinaryIO, Generic, MutableMapping, Optional, TextIO, Tuple, TypeVar, Union
2+
from io import IOBase
3+
from typing import Any, BinaryIO, Generic, MutableMapping, Optional, TextIO, Tuple, TypeVar, Union
34

45
import attr
56

@@ -14,6 +15,10 @@ def __bool__(self) -> bool:
1415
FileJsonType = Tuple[Optional[str], Union[BinaryIO, TextIO], Optional[str]]
1516

1617

18+
def is_file(value: Any) -> bool:
19+
return isinstance(value, tuple) and len(value) == 3 and isinstance(value[1], IOBase)
20+
21+
1722
@attr.s(auto_attribs=True)
1823
class File:
1924
""" Contains information for file uploads """
@@ -40,4 +45,4 @@ class Response(Generic[T]):
4045
parsed: Optional[T]
4146

4247

43-
__all__ = ["File", "Response"]
48+
__all__ = ["File", "Response", "is_file"]

openapi_python_client/templates/endpoint_module.py.jinja

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import httpx
44
from attr import asdict
55

66
from ...client import AuthenticatedClient, Client
7-
from ...types import Response, UNSET{% if endpoint.multipart_body_reference %}, File {% endif %}
7+
from ...types import Response, UNSET{% if endpoint.multipart_body_reference %}, is_file {% endif %}
88

99
{% for relative in endpoint.relative_imports %}
1010
{{ relative }}
@@ -40,7 +40,7 @@ def _get_kwargs(
4040
files = {}
4141
data = {}
4242
for key, value in multipart_data.to_dict().items():
43-
if isinstance(value, File):
43+
if is_file(value):
4444
files[key] = value
4545
else:
4646
data[key] = value

openapi_python_client/templates/types.py.jinja

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
""" Contains some shared types for properties """
2-
from typing import BinaryIO, Generic, MutableMapping, Optional, TextIO, Tuple, TypeVar, Union
2+
from io import IOBase
3+
from typing import Any, BinaryIO, Generic, MutableMapping, Optional, TextIO, Tuple, TypeVar, Union
34

45
import attr
56

@@ -15,6 +16,10 @@ UNSET: Unset = Unset()
1516
FileJsonType = Tuple[Optional[str], Union[BinaryIO, TextIO], Optional[str]]
1617

1718

19+
def is_file(value: Any) -> bool:
20+
return isinstance(value, tuple) and len(value) == 3 and isinstance(value[1], IOBase)
21+
22+
1823
@attr.s(auto_attribs=True)
1924
class File:
2025
""" Contains information for file uploads """
@@ -41,4 +46,4 @@ class Response(Generic[T]):
4146
parsed: Optional[T]
4247

4348

44-
__all__ = ["File", "Response"]
49+
__all__ = ["File", "Response", "is_file"]

0 commit comments

Comments
 (0)