diff --git a/end_to_end_tests/baseline_openapi_3.0.json b/end_to_end_tests/baseline_openapi_3.0.json index b07f3cc7b..b536f7432 100644 --- a/end_to_end_tests/baseline_openapi_3.0.json +++ b/end_to_end_tests/baseline_openapi_3.0.json @@ -731,7 +731,13 @@ "content": { "application/json": { "schema": { - "type": "string" + "type": "object", + "properties": { + "data": { + "type": "string", + "format": "binary" + } + } } } } diff --git a/end_to_end_tests/baseline_openapi_3.1.yaml b/end_to_end_tests/baseline_openapi_3.1.yaml index 5364e34ad..b9fb3e9f6 100644 --- a/end_to_end_tests/baseline_openapi_3.1.yaml +++ b/end_to_end_tests/baseline_openapi_3.1.yaml @@ -714,7 +714,13 @@ info: "content": { "application/json": { "schema": { - "type": "string" + "type": "object", + "properties": { + "data": { + "type": "string", + "format": "binary" + } + } } } } @@ -1110,7 +1116,7 @@ info: }, "/tag_with_number": { "get": { - "tags": ["1", "2"], + "tags": [ "1", "2" ], "responses": { "200": { "description": "Success" @@ -1643,7 +1649,7 @@ info: "type": "string" } }, - "required": ["type"] + "required": [ "type" ] }, { "type": "object", @@ -1655,7 +1661,7 @@ info: "type": "string" } }, - "required": ["type"] + "required": [ "type" ] } ] } diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/tests/octet_stream_tests_octet_stream_post.py b/end_to_end_tests/golden-record/my_test_api_client/api/tests/octet_stream_tests_octet_stream_post.py index f4e58f35a..bf4a1fcb0 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/tests/octet_stream_tests_octet_stream_post.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/tests/octet_stream_tests_octet_stream_post.py @@ -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 @@ -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()) @@ -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, @@ -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: @@ -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( @@ -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: @@ -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( @@ -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: @@ -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( @@ -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: @@ -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 ( diff --git a/end_to_end_tests/golden-record/my_test_api_client/models/__init__.py b/end_to_end_tests/golden-record/my_test_api_client/models/__init__.py index f354c31c7..4274c3235 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/models/__init__.py +++ b/end_to_end_tests/golden-record/my_test_api_client/models/__init__.py @@ -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 @@ -157,6 +158,7 @@ "ModelWithUnionPropertyInlinedFruitType0", "ModelWithUnionPropertyInlinedFruitType1", "None_", + "OctetStreamTestsOctetStreamPostResponse200", "PostBodiesMultipleDataBody", "PostBodiesMultipleFilesBody", "PostBodiesMultipleJsonBody", diff --git a/end_to_end_tests/golden-record/my_test_api_client/models/body_upload_file_tests_upload_post.py b/end_to_end_tests/golden-record/my_test_api_client/models/body_upload_file_tests_upload_post.py index 642fbf703..5dcb8c936 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/models/body_upload_file_tests_upload_post.py +++ b/end_to_end_tests/golden-record/my_test_api_client/models/body_upload_file_tests_upload_post.py @@ -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 @@ -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() diff --git a/end_to_end_tests/golden-record/my_test_api_client/models/octet_stream_tests_octet_stream_post_response_200.py b/end_to_end_tests/golden-record/my_test_api_client/models/octet_stream_tests_octet_stream_post_response_200.py new file mode 100644 index 000000000..01a6c9273 --- /dev/null +++ b/end_to_end_tests/golden-record/my_test_api_client/models/octet_stream_tests_octet_stream_post_response_200.py @@ -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 diff --git a/openapi_python_client/parser/properties/file.py b/openapi_python_client/parser/properties/file.py index 97de3e093..90bbf6aec 100644 --- a/openapi_python_client/parser/properties/file.py +++ b/openapi_python_client/parser/properties/file.py @@ -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