From 4aeaa64ec07b48d37c60ef6fe671039e6040013f Mon Sep 17 00:00:00 2001 From: Forest Tong Date: Wed, 14 Apr 2021 12:52:09 -0400 Subject: [PATCH 1/2] ModelFromOneof --- .../my_test_api_client/models/__init__.py | 1 + .../models/model_from_all_of.py | 21 +------ .../models/model_from_one_of.py | 61 +++++++++++++++++++ end_to_end_tests/openapi.json | 9 +++ 4 files changed, 72 insertions(+), 20 deletions(-) create mode 100644 end_to_end_tests/golden-record/my_test_api_client/models/model_from_one_of.py 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 61c8c56c3..091141e5a 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 @@ -10,6 +10,7 @@ from .free_form_model import FreeFormModel from .http_validation_error import HTTPValidationError from .model_from_all_of import ModelFromAllOf +from .model_from_one_of import ModelFromOneOf from .model_with_additional_properties_inlined import ModelWithAdditionalPropertiesInlined from .model_with_additional_properties_inlined_additional_property import ( ModelWithAdditionalPropertiesInlinedAdditionalProperty, diff --git a/end_to_end_tests/golden-record/my_test_api_client/models/model_from_all_of.py b/end_to_end_tests/golden-record/my_test_api_client/models/model_from_all_of.py index ce26a3bbb..dc7f876a3 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/models/model_from_all_of.py +++ b/end_to_end_tests/golden-record/my_test_api_client/models/model_from_all_of.py @@ -1,4 +1,4 @@ -from typing import Any, Dict, List, Type, TypeVar, Union +from typing import Any, Dict, Type, TypeVar, Union import attr @@ -13,14 +13,12 @@ class ModelFromAllOf: a_sub_property: Union[Unset, str] = UNSET another_sub_property: Union[Unset, str] = UNSET - additional_properties: Dict[str, Any] = attr.ib(init=False, factory=dict) def to_dict(self) -> Dict[str, Any]: a_sub_property = self.a_sub_property another_sub_property = self.another_sub_property field_dict: Dict[str, Any] = {} - field_dict.update(self.additional_properties) field_dict.update({}) if a_sub_property is not UNSET: field_dict["a_sub_property"] = a_sub_property @@ -41,21 +39,4 @@ def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: another_sub_property=another_sub_property, ) - model_from_all_of.additional_properties = d return model_from_all_of - - @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/end_to_end_tests/golden-record/my_test_api_client/models/model_from_one_of.py b/end_to_end_tests/golden-record/my_test_api_client/models/model_from_one_of.py new file mode 100644 index 000000000..15c1a1a7b --- /dev/null +++ b/end_to_end_tests/golden-record/my_test_api_client/models/model_from_one_of.py @@ -0,0 +1,61 @@ +from typing import Any, Dict, List, Type, TypeVar, Union + +import attr + +from ..types import UNSET, Unset + +T = TypeVar("T", bound="ModelFromOneOf") + + +@attr.s(auto_attribs=True) +class ModelFromOneOf: + """ """ + + a_sub_property: Union[Unset, str] = UNSET + another_sub_property: Union[Unset, str] = UNSET + additional_properties: Dict[str, Any] = attr.ib(init=False, factory=dict) + + def to_dict(self) -> Dict[str, Any]: + a_sub_property = self.a_sub_property + another_sub_property = self.another_sub_property + + field_dict: Dict[str, Any] = {} + field_dict.update(self.additional_properties) + field_dict.update({}) + if a_sub_property is not UNSET: + field_dict["a_sub_property"] = a_sub_property + if another_sub_property is not UNSET: + field_dict["another_sub_property"] = another_sub_property + + return field_dict + + @classmethod + def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: + d = src_dict.copy() + a_sub_property = d.pop("a_sub_property", UNSET) + + another_sub_property = d.pop("another_sub_property", UNSET) + + model_from_one_of = cls( + a_sub_property=a_sub_property, + another_sub_property=another_sub_property, + ) + + model_from_one_of.additional_properties = d + return model_from_one_of + + @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/end_to_end_tests/openapi.json b/end_to_end_tests/openapi.json index ed0de8918..c2b639976 100644 --- a/end_to_end_tests/openapi.json +++ b/end_to_end_tests/openapi.json @@ -1098,6 +1098,15 @@ "ModelFromAllOf": { "title": "ModelFromAllOf", "type": "object", + "additionalProperties": false, + "allOf": [ + {"$ref": "#/components/schemas/AllOfSubModel"}, + {"$ref": "#/components/schemas/AnotherAllOfSubModel"} + ] + }, + "ModelFromOneOf": { + "title": "ModelFromOneOf", + "type": "object", "allOf": [ {"$ref": "#/components/schemas/AllOfSubModel"}, {"$ref": "#/components/schemas/AnotherAllOfSubModel"} From d4eb9ff0831bc44f8d34a371ac34a8345dc277d7 Mon Sep 17 00:00:00 2001 From: Forest Tong Date: Wed, 14 Apr 2021 12:56:46 -0400 Subject: [PATCH 2/2] Fix --- .../models/model_from_one_of.py | 21 ++----------------- end_to_end_tests/openapi.json | 2 +- 2 files changed, 3 insertions(+), 20 deletions(-) diff --git a/end_to_end_tests/golden-record/my_test_api_client/models/model_from_one_of.py b/end_to_end_tests/golden-record/my_test_api_client/models/model_from_one_of.py index 15c1a1a7b..0f222c329 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/models/model_from_one_of.py +++ b/end_to_end_tests/golden-record/my_test_api_client/models/model_from_one_of.py @@ -1,9 +1,7 @@ -from typing import Any, Dict, List, Type, TypeVar, Union +from typing import Any, Dict, List, Type, TypeVar import attr -from ..types import UNSET, Unset - T = TypeVar("T", bound="ModelFromOneOf") @@ -11,35 +9,20 @@ class ModelFromOneOf: """ """ - a_sub_property: Union[Unset, str] = UNSET - another_sub_property: Union[Unset, str] = UNSET additional_properties: Dict[str, Any] = attr.ib(init=False, factory=dict) def to_dict(self) -> Dict[str, Any]: - a_sub_property = self.a_sub_property - another_sub_property = self.another_sub_property field_dict: Dict[str, Any] = {} field_dict.update(self.additional_properties) field_dict.update({}) - if a_sub_property is not UNSET: - field_dict["a_sub_property"] = a_sub_property - if another_sub_property is not UNSET: - field_dict["another_sub_property"] = another_sub_property return field_dict @classmethod def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: d = src_dict.copy() - a_sub_property = d.pop("a_sub_property", UNSET) - - another_sub_property = d.pop("another_sub_property", UNSET) - - model_from_one_of = cls( - a_sub_property=a_sub_property, - another_sub_property=another_sub_property, - ) + model_from_one_of = cls() model_from_one_of.additional_properties = d return model_from_one_of diff --git a/end_to_end_tests/openapi.json b/end_to_end_tests/openapi.json index c2b639976..19173119c 100644 --- a/end_to_end_tests/openapi.json +++ b/end_to_end_tests/openapi.json @@ -1107,7 +1107,7 @@ "ModelFromOneOf": { "title": "ModelFromOneOf", "type": "object", - "allOf": [ + "oneOf": [ {"$ref": "#/components/schemas/AllOfSubModel"}, {"$ref": "#/components/schemas/AnotherAllOfSubModel"} ]