Skip to content

fix: Import error for types.FileType (#1274) #1278

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion end_to_end_tests/baseline_openapi_3.0.json
Original file line number Diff line number Diff line change
Expand Up @@ -731,7 +731,13 @@
"content": {
"application/json": {
"schema": {
"type": "string"
"type": "object",
"properties": {
"data": {
"type": "string",
"format": "binary"
}
}
}
}
}
Expand Down
14 changes: 10 additions & 4 deletions end_to_end_tests/baseline_openapi_3.1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -714,7 +714,13 @@ info:
"content": {
"application/json": {
"schema": {
"type": "string"
"type": "object",
"properties": {
"data": {
"type": "string",
"format": "binary"
}
}
}
}
}
Expand Down Expand Up @@ -1110,7 +1116,7 @@ info:
},
"/tag_with_number": {
"get": {
"tags": ["1", "2"],
"tags": [ "1", "2" ],
"responses": {
"200": {
"description": "Success"
Expand Down Expand Up @@ -1643,7 +1649,7 @@ info:
"type": "string"
}
},
"required": ["type"]
"required": [ "type" ]
},
{
"type": "object",
Expand All @@ -1655,7 +1661,7 @@ info:
"type": "string"
}
},
"required": ["type"]
"required": [ "type" ]
}
]
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
from http import HTTPStatus
from typing import Any, Optional, Union, cast
from typing import Any, Optional, Union

import httpx

from ... import errors
from ...client import AuthenticatedClient, Client
from ...models.http_validation_error import HTTPValidationError
from ...models.octet_stream_tests_octet_stream_post_response_200 import OctetStreamTestsOctetStreamPostResponse200
from ...types import File, Response


Expand All @@ -30,9 +31,10 @@ def _get_kwargs(

def _parse_response(
*, client: Union[AuthenticatedClient, Client], response: httpx.Response
) -> Optional[Union[HTTPValidationError, str]]:
) -> Optional[Union[HTTPValidationError, OctetStreamTestsOctetStreamPostResponse200]]:
if response.status_code == 200:
response_200 = cast(str, response.json())
response_200 = OctetStreamTestsOctetStreamPostResponse200.from_dict(response.json())

return response_200
if response.status_code == 422:
response_422 = HTTPValidationError.from_dict(response.json())
Expand All @@ -46,7 +48,7 @@ def _parse_response(

def _build_response(
*, client: Union[AuthenticatedClient, Client], response: httpx.Response
) -> Response[Union[HTTPValidationError, str]]:
) -> Response[Union[HTTPValidationError, OctetStreamTestsOctetStreamPostResponse200]]:
return Response(
status_code=HTTPStatus(response.status_code),
content=response.content,
Expand All @@ -59,7 +61,7 @@ def sync_detailed(
*,
client: Union[AuthenticatedClient, Client],
body: File,
) -> Response[Union[HTTPValidationError, str]]:
) -> Response[Union[HTTPValidationError, OctetStreamTestsOctetStreamPostResponse200]]:
"""Binary (octet stream) request body

Args:
Expand All @@ -70,7 +72,7 @@ def sync_detailed(
httpx.TimeoutException: If the request takes longer than Client.timeout.

Returns:
Response[Union[HTTPValidationError, str]]
Response[Union[HTTPValidationError, OctetStreamTestsOctetStreamPostResponse200]]
"""

kwargs = _get_kwargs(
Expand All @@ -88,7 +90,7 @@ def sync(
*,
client: Union[AuthenticatedClient, Client],
body: File,
) -> Optional[Union[HTTPValidationError, str]]:
) -> Optional[Union[HTTPValidationError, OctetStreamTestsOctetStreamPostResponse200]]:
"""Binary (octet stream) request body

Args:
Expand All @@ -99,7 +101,7 @@ def sync(
httpx.TimeoutException: If the request takes longer than Client.timeout.

Returns:
Union[HTTPValidationError, str]
Union[HTTPValidationError, OctetStreamTestsOctetStreamPostResponse200]
"""

return sync_detailed(
Expand All @@ -112,7 +114,7 @@ async def asyncio_detailed(
*,
client: Union[AuthenticatedClient, Client],
body: File,
) -> Response[Union[HTTPValidationError, str]]:
) -> Response[Union[HTTPValidationError, OctetStreamTestsOctetStreamPostResponse200]]:
"""Binary (octet stream) request body

Args:
Expand All @@ -123,7 +125,7 @@ async def asyncio_detailed(
httpx.TimeoutException: If the request takes longer than Client.timeout.

Returns:
Response[Union[HTTPValidationError, str]]
Response[Union[HTTPValidationError, OctetStreamTestsOctetStreamPostResponse200]]
"""

kwargs = _get_kwargs(
Expand All @@ -139,7 +141,7 @@ async def asyncio(
*,
client: Union[AuthenticatedClient, Client],
body: File,
) -> Optional[Union[HTTPValidationError, str]]:
) -> Optional[Union[HTTPValidationError, OctetStreamTestsOctetStreamPostResponse200]]:
"""Binary (octet stream) request body

Args:
Expand All @@ -150,7 +152,7 @@ async def asyncio(
httpx.TimeoutException: If the request takes longer than Client.timeout.

Returns:
Union[HTTPValidationError, str]
Union[HTTPValidationError, OctetStreamTestsOctetStreamPostResponse200]
"""

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
from .model_with_union_property_inlined_fruit_type_0 import ModelWithUnionPropertyInlinedFruitType0
from .model_with_union_property_inlined_fruit_type_1 import ModelWithUnionPropertyInlinedFruitType1
from .none import None_
from .octet_stream_tests_octet_stream_post_response_200 import OctetStreamTestsOctetStreamPostResponse200
from .post_bodies_multiple_data_body import PostBodiesMultipleDataBody
from .post_bodies_multiple_files_body import PostBodiesMultipleFilesBody
from .post_bodies_multiple_json_body import PostBodiesMultipleJsonBody
Expand Down Expand Up @@ -157,6 +158,7 @@
"ModelWithUnionPropertyInlinedFruitType0",
"ModelWithUnionPropertyInlinedFruitType1",
"None_",
"OctetStreamTestsOctetStreamPostResponse200",
"PostBodiesMultipleDataBody",
"PostBodiesMultipleFilesBody",
"PostBodiesMultipleJsonBody",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

from .. import types
from ..models.different_enum import DifferentEnum
from ..types import UNSET, File, Unset
from ..types import UNSET, File, FileTypes, Unset

if TYPE_CHECKING:
from ..models.a_form_data import AFormData
Expand Down Expand Up @@ -84,7 +84,7 @@ def to_dict(self) -> dict[str, Any]:
else:
some_nullable_object = self.some_nullable_object

some_optional_file: Union[Unset, types.FileTypes] = UNSET
some_optional_file: Union[Unset, FileTypes] = UNSET
if not isinstance(self.some_optional_file, Unset):
some_optional_file = self.some_optional_file.to_tuple()

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
from collections.abc import Mapping
from io import BytesIO
from typing import Any, TypeVar, Union

from attrs import define as _attrs_define
from attrs import field as _attrs_field

from ..types import UNSET, File, FileTypes, Unset

T = TypeVar("T", bound="OctetStreamTestsOctetStreamPostResponse200")


@_attrs_define
class OctetStreamTestsOctetStreamPostResponse200:
"""
Attributes:
data (Union[Unset, File]):
"""

data: Union[Unset, File] = UNSET
additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict)

def to_dict(self) -> dict[str, Any]:
data: Union[Unset, FileTypes] = UNSET
if not isinstance(self.data, Unset):
data = self.data.to_tuple()

field_dict: dict[str, Any] = {}
field_dict.update(self.additional_properties)
field_dict.update({})
if data is not UNSET:
field_dict["data"] = data

return field_dict

@classmethod
def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T:
d = dict(src_dict)
_data = d.pop("data", UNSET)
data: Union[Unset, File]
if isinstance(_data, Unset):
data = UNSET
else:
data = File(payload=BytesIO(_data))

octet_stream_tests_octet_stream_post_response_200 = cls(
data=data,
)

octet_stream_tests_octet_stream_post_response_200.additional_properties = d
return octet_stream_tests_octet_stream_post_response_200

@property
def additional_keys(self) -> list[str]:
return list(self.additional_properties.keys())

def __getitem__(self, key: str) -> Any:
return self.additional_properties[key]

def __setitem__(self, key: str, value: Any) -> None:
self.additional_properties[key] = value

def __delitem__(self, key: str) -> None:
del self.additional_properties[key]

def __contains__(self, key: str) -> bool:
return key in self.additional_properties
2 changes: 1 addition & 1 deletion openapi_python_client/parser/properties/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class FileProperty(PropertyProtocol):

_type_string: ClassVar[str] = "File"
# Return type of File.to_tuple()
_json_type_string: ClassVar[str] = "types.FileTypes"
_json_type_string: ClassVar[str] = "FileTypes"
template: ClassVar[str] = "file_property.py.jinja"

@classmethod
Expand Down