Skip to content

Bug in oneOf model generation #387

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

Closed
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any, Dict, List, Type, TypeVar, Union
from typing import Any, Dict, Type, TypeVar, Union

import attr

Expand All @@ -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
Expand All @@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
from typing import Any, Dict, List, Type, TypeVar

import attr

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


@attr.s(auto_attribs=True)
class ModelFromOneOf:
""" """

additional_properties: Dict[str, Any] = attr.ib(init=False, factory=dict)

def to_dict(self) -> Dict[str, Any]:

field_dict: Dict[str, Any] = {}
field_dict.update(self.additional_properties)
field_dict.update({})

return field_dict

@classmethod
def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T:
d = src_dict.copy()
model_from_one_of = cls()

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
9 changes: 9 additions & 0 deletions end_to_end_tests/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -1098,11 +1098,20 @@
"ModelFromAllOf": {
"title": "ModelFromAllOf",
"type": "object",
"additionalProperties": false,
"allOf": [
{"$ref": "#/components/schemas/AllOfSubModel"},
{"$ref": "#/components/schemas/AnotherAllOfSubModel"}
]
},
"ModelFromOneOf": {
"title": "ModelFromOneOf",
"type": "object",
"oneOf": [
{"$ref": "#/components/schemas/AllOfSubModel"},
{"$ref": "#/components/schemas/AnotherAllOfSubModel"}
]
},
"AllOfSubModel": {
"title": "AllOfSubModel",
"type": "object",
Expand Down