Skip to content

Commit fbec755

Browse files
authored
fix: Import error for types.FileType (#1274) (#1278)
Closes #1274 Co-authored-by: Dylan Anthony <[email protected]>
1 parent b46474c commit fbec755

File tree

7 files changed

+103
-20
lines changed

7 files changed

+103
-20
lines changed

end_to_end_tests/baseline_openapi_3.0.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -731,7 +731,13 @@
731731
"content": {
732732
"application/json": {
733733
"schema": {
734-
"type": "string"
734+
"type": "object",
735+
"properties": {
736+
"data": {
737+
"type": "string",
738+
"format": "binary"
739+
}
740+
}
735741
}
736742
}
737743
}

end_to_end_tests/baseline_openapi_3.1.yaml

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -714,7 +714,13 @@ info:
714714
"content": {
715715
"application/json": {
716716
"schema": {
717-
"type": "string"
717+
"type": "object",
718+
"properties": {
719+
"data": {
720+
"type": "string",
721+
"format": "binary"
722+
}
723+
}
718724
}
719725
}
720726
}
@@ -1110,7 +1116,7 @@ info:
11101116
},
11111117
"/tag_with_number": {
11121118
"get": {
1113-
"tags": ["1", "2"],
1119+
"tags": [ "1", "2" ],
11141120
"responses": {
11151121
"200": {
11161122
"description": "Success"
@@ -1643,7 +1649,7 @@ info:
16431649
"type": "string"
16441650
}
16451651
},
1646-
"required": ["type"]
1652+
"required": [ "type" ]
16471653
},
16481654
{
16491655
"type": "object",
@@ -1655,7 +1661,7 @@ info:
16551661
"type": "string"
16561662
}
16571663
},
1658-
"required": ["type"]
1664+
"required": [ "type" ]
16591665
}
16601666
]
16611667
}

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

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
from http import HTTPStatus
2-
from typing import Any, Optional, Union, cast
2+
from typing import Any, Optional, Union
33

44
import httpx
55

66
from ... import errors
77
from ...client import AuthenticatedClient, Client
88
from ...models.http_validation_error import HTTPValidationError
9+
from ...models.octet_stream_tests_octet_stream_post_response_200 import OctetStreamTestsOctetStreamPostResponse200
910
from ...types import File, Response
1011

1112

@@ -30,9 +31,10 @@ def _get_kwargs(
3031

3132
def _parse_response(
3233
*, client: Union[AuthenticatedClient, Client], response: httpx.Response
33-
) -> Optional[Union[HTTPValidationError, str]]:
34+
) -> Optional[Union[HTTPValidationError, OctetStreamTestsOctetStreamPostResponse200]]:
3435
if response.status_code == 200:
35-
response_200 = cast(str, response.json())
36+
response_200 = OctetStreamTestsOctetStreamPostResponse200.from_dict(response.json())
37+
3638
return response_200
3739
if response.status_code == 422:
3840
response_422 = HTTPValidationError.from_dict(response.json())
@@ -46,7 +48,7 @@ def _parse_response(
4648

4749
def _build_response(
4850
*, client: Union[AuthenticatedClient, Client], response: httpx.Response
49-
) -> Response[Union[HTTPValidationError, str]]:
51+
) -> Response[Union[HTTPValidationError, OctetStreamTestsOctetStreamPostResponse200]]:
5052
return Response(
5153
status_code=HTTPStatus(response.status_code),
5254
content=response.content,
@@ -59,7 +61,7 @@ def sync_detailed(
5961
*,
6062
client: Union[AuthenticatedClient, Client],
6163
body: File,
62-
) -> Response[Union[HTTPValidationError, str]]:
64+
) -> Response[Union[HTTPValidationError, OctetStreamTestsOctetStreamPostResponse200]]:
6365
"""Binary (octet stream) request body
6466
6567
Args:
@@ -70,7 +72,7 @@ def sync_detailed(
7072
httpx.TimeoutException: If the request takes longer than Client.timeout.
7173
7274
Returns:
73-
Response[Union[HTTPValidationError, str]]
75+
Response[Union[HTTPValidationError, OctetStreamTestsOctetStreamPostResponse200]]
7476
"""
7577

7678
kwargs = _get_kwargs(
@@ -88,7 +90,7 @@ def sync(
8890
*,
8991
client: Union[AuthenticatedClient, Client],
9092
body: File,
91-
) -> Optional[Union[HTTPValidationError, str]]:
93+
) -> Optional[Union[HTTPValidationError, OctetStreamTestsOctetStreamPostResponse200]]:
9294
"""Binary (octet stream) request body
9395
9496
Args:
@@ -99,7 +101,7 @@ def sync(
99101
httpx.TimeoutException: If the request takes longer than Client.timeout.
100102
101103
Returns:
102-
Union[HTTPValidationError, str]
104+
Union[HTTPValidationError, OctetStreamTestsOctetStreamPostResponse200]
103105
"""
104106

105107
return sync_detailed(
@@ -112,7 +114,7 @@ async def asyncio_detailed(
112114
*,
113115
client: Union[AuthenticatedClient, Client],
114116
body: File,
115-
) -> Response[Union[HTTPValidationError, str]]:
117+
) -> Response[Union[HTTPValidationError, OctetStreamTestsOctetStreamPostResponse200]]:
116118
"""Binary (octet stream) request body
117119
118120
Args:
@@ -123,7 +125,7 @@ async def asyncio_detailed(
123125
httpx.TimeoutException: If the request takes longer than Client.timeout.
124126
125127
Returns:
126-
Response[Union[HTTPValidationError, str]]
128+
Response[Union[HTTPValidationError, OctetStreamTestsOctetStreamPostResponse200]]
127129
"""
128130

129131
kwargs = _get_kwargs(
@@ -139,7 +141,7 @@ async def asyncio(
139141
*,
140142
client: Union[AuthenticatedClient, Client],
141143
body: File,
142-
) -> Optional[Union[HTTPValidationError, str]]:
144+
) -> Optional[Union[HTTPValidationError, OctetStreamTestsOctetStreamPostResponse200]]:
143145
"""Binary (octet stream) request body
144146
145147
Args:
@@ -150,7 +152,7 @@ async def asyncio(
150152
httpx.TimeoutException: If the request takes longer than Client.timeout.
151153
152154
Returns:
153-
Union[HTTPValidationError, str]
155+
Union[HTTPValidationError, OctetStreamTestsOctetStreamPostResponse200]
154156
"""
155157

156158
return (

end_to_end_tests/golden-record/my_test_api_client/models/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@
7575
from .model_with_union_property_inlined_fruit_type_0 import ModelWithUnionPropertyInlinedFruitType0
7676
from .model_with_union_property_inlined_fruit_type_1 import ModelWithUnionPropertyInlinedFruitType1
7777
from .none import None_
78+
from .octet_stream_tests_octet_stream_post_response_200 import OctetStreamTestsOctetStreamPostResponse200
7879
from .post_bodies_multiple_data_body import PostBodiesMultipleDataBody
7980
from .post_bodies_multiple_files_body import PostBodiesMultipleFilesBody
8081
from .post_bodies_multiple_json_body import PostBodiesMultipleJsonBody
@@ -157,6 +158,7 @@
157158
"ModelWithUnionPropertyInlinedFruitType0",
158159
"ModelWithUnionPropertyInlinedFruitType1",
159160
"None_",
161+
"OctetStreamTestsOctetStreamPostResponse200",
160162
"PostBodiesMultipleDataBody",
161163
"PostBodiesMultipleFilesBody",
162164
"PostBodiesMultipleJsonBody",

end_to_end_tests/golden-record/my_test_api_client/models/body_upload_file_tests_upload_post.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
from .. import types
1212
from ..models.different_enum import DifferentEnum
13-
from ..types import UNSET, File, Unset
13+
from ..types import UNSET, File, FileTypes, Unset
1414

1515
if TYPE_CHECKING:
1616
from ..models.a_form_data import AFormData
@@ -84,7 +84,7 @@ def to_dict(self) -> dict[str, Any]:
8484
else:
8585
some_nullable_object = self.some_nullable_object
8686

87-
some_optional_file: Union[Unset, types.FileTypes] = UNSET
87+
some_optional_file: Union[Unset, FileTypes] = UNSET
8888
if not isinstance(self.some_optional_file, Unset):
8989
some_optional_file = self.some_optional_file.to_tuple()
9090

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
from collections.abc import Mapping
2+
from io import BytesIO
3+
from typing import Any, TypeVar, Union
4+
5+
from attrs import define as _attrs_define
6+
from attrs import field as _attrs_field
7+
8+
from ..types import UNSET, File, FileTypes, Unset
9+
10+
T = TypeVar("T", bound="OctetStreamTestsOctetStreamPostResponse200")
11+
12+
13+
@_attrs_define
14+
class OctetStreamTestsOctetStreamPostResponse200:
15+
"""
16+
Attributes:
17+
data (Union[Unset, File]):
18+
"""
19+
20+
data: Union[Unset, File] = UNSET
21+
additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict)
22+
23+
def to_dict(self) -> dict[str, Any]:
24+
data: Union[Unset, FileTypes] = UNSET
25+
if not isinstance(self.data, Unset):
26+
data = self.data.to_tuple()
27+
28+
field_dict: dict[str, Any] = {}
29+
field_dict.update(self.additional_properties)
30+
field_dict.update({})
31+
if data is not UNSET:
32+
field_dict["data"] = data
33+
34+
return field_dict
35+
36+
@classmethod
37+
def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T:
38+
d = dict(src_dict)
39+
_data = d.pop("data", UNSET)
40+
data: Union[Unset, File]
41+
if isinstance(_data, Unset):
42+
data = UNSET
43+
else:
44+
data = File(payload=BytesIO(_data))
45+
46+
octet_stream_tests_octet_stream_post_response_200 = cls(
47+
data=data,
48+
)
49+
50+
octet_stream_tests_octet_stream_post_response_200.additional_properties = d
51+
return octet_stream_tests_octet_stream_post_response_200
52+
53+
@property
54+
def additional_keys(self) -> list[str]:
55+
return list(self.additional_properties.keys())
56+
57+
def __getitem__(self, key: str) -> Any:
58+
return self.additional_properties[key]
59+
60+
def __setitem__(self, key: str, value: Any) -> None:
61+
self.additional_properties[key] = value
62+
63+
def __delitem__(self, key: str) -> None:
64+
del self.additional_properties[key]
65+
66+
def __contains__(self, key: str) -> bool:
67+
return key in self.additional_properties

openapi_python_client/parser/properties/file.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class FileProperty(PropertyProtocol):
2222

2323
_type_string: ClassVar[str] = "File"
2424
# Return type of File.to_tuple()
25-
_json_type_string: ClassVar[str] = "types.FileTypes"
25+
_json_type_string: ClassVar[str] = "FileTypes"
2626
template: ClassVar[str] = "file_property.py.jinja"
2727

2828
@classmethod

0 commit comments

Comments
 (0)