Skip to content
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

feat: Add allOf support for model definitions (#98) #321

Merged
merged 13 commits into from Mar 23, 2021
Merged
Expand Up @@ -5,12 +5,15 @@
from .a_model_not_required_model import AModelNotRequiredModel
from .a_model_not_required_nullable_model import AModelNotRequiredNullableModel
from .a_model_nullable_model import AModelNullableModel
from .all_of_sub_model import AllOfSubModel
from .an_enum import AnEnum
from .an_int_enum import AnIntEnum
from .another_all_of_sub_model import AnotherAllOfSubModel
from .body_upload_file_tests_upload_post import BodyUploadFileTestsUploadPost
from .different_enum import DifferentEnum
from .free_form_model import FreeFormModel
from .http_validation_error import HTTPValidationError
from .model_from_all_of import ModelFromAllOf
from .model_with_additional_properties_inlined import ModelWithAdditionalPropertiesInlined
from .model_with_additional_properties_inlined_additional_property import (
ModelWithAdditionalPropertiesInlinedAdditionalProperty,
Expand Down
@@ -1,28 +1,71 @@
from typing import Any, Dict, List, Type, TypeVar
from typing import Any, Dict, List, Type, TypeVar, Union

import attr

from ..models.an_enum import AnEnum
from ..models.an_int_enum import AnIntEnum
from ..types import UNSET, Unset

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


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

a_property: Union[Unset, AnEnum, AnIntEnum] = UNSET
additional_properties: Dict[str, Any] = attr.ib(init=False, factory=dict)

def to_dict(self) -> Dict[str, Any]:
a_property: Union[Unset, AnEnum, AnIntEnum]
if isinstance(self.a_property, Unset):
a_property = UNSET
elif isinstance(self.a_property, AnEnum):
a_property = UNSET
if not isinstance(self.a_property, Unset):
a_property = self.a_property

else:
a_property = UNSET
if not isinstance(self.a_property, Unset):
a_property = self.a_property

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

return field_dict

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

def _parse_a_property(data: Any) -> Union[Unset, AnEnum, AnIntEnum]:
data = None if isinstance(data, Unset) else data
a_property: Union[Unset, AnEnum, AnIntEnum]
try:
a_property = UNSET
_a_property = data
if not isinstance(_a_property, Unset):
a_property = AnEnum(_a_property)

return a_property
except: # noqa: E722
pass
a_property = UNSET
_a_property = data
if not isinstance(_a_property, Unset):
a_property = AnIntEnum(_a_property)

return a_property

a_property = _parse_a_property(d.pop("a_property", UNSET))

a_model_model = cls(
a_property=a_property,
)

a_model_model.additional_properties = d
return a_model_model
Expand Down
@@ -1,28 +1,71 @@
from typing import Any, Dict, List, Type, TypeVar
from typing import Any, Dict, List, Type, TypeVar, Union

import attr

from ..models.an_enum import AnEnum
from ..models.an_int_enum import AnIntEnum
from ..types import UNSET, Unset

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


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

a_property: Union[Unset, AnEnum, AnIntEnum] = UNSET
additional_properties: Dict[str, Any] = attr.ib(init=False, factory=dict)

def to_dict(self) -> Dict[str, Any]:
a_property: Union[Unset, AnEnum, AnIntEnum]
if isinstance(self.a_property, Unset):
a_property = UNSET
elif isinstance(self.a_property, AnEnum):
a_property = UNSET
if not isinstance(self.a_property, Unset):
a_property = self.a_property

else:
a_property = UNSET
if not isinstance(self.a_property, Unset):
a_property = self.a_property

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

return field_dict

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

def _parse_a_property(data: Any) -> Union[Unset, AnEnum, AnIntEnum]:
data = None if isinstance(data, Unset) else data
a_property: Union[Unset, AnEnum, AnIntEnum]
try:
a_property = UNSET
_a_property = data
if not isinstance(_a_property, Unset):
a_property = AnEnum(_a_property)

return a_property
except: # noqa: E722
pass
a_property = UNSET
_a_property = data
if not isinstance(_a_property, Unset):
a_property = AnIntEnum(_a_property)

return a_property

a_property = _parse_a_property(d.pop("a_property", UNSET))

a_model_not_required_model = cls(
a_property=a_property,
)

a_model_not_required_model.additional_properties = d
return a_model_not_required_model
Expand Down
@@ -1,28 +1,71 @@
from typing import Any, Dict, List, Type, TypeVar
from typing import Any, Dict, List, Type, TypeVar, Union

import attr

from ..models.an_enum import AnEnum
from ..models.an_int_enum import AnIntEnum
from ..types import UNSET, Unset

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


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

a_property: Union[Unset, AnEnum, AnIntEnum] = UNSET
additional_properties: Dict[str, Any] = attr.ib(init=False, factory=dict)

def to_dict(self) -> Dict[str, Any]:
a_property: Union[Unset, AnEnum, AnIntEnum]
if isinstance(self.a_property, Unset):
a_property = UNSET
elif isinstance(self.a_property, AnEnum):
a_property = UNSET
if not isinstance(self.a_property, Unset):
a_property = self.a_property

else:
a_property = UNSET
if not isinstance(self.a_property, Unset):
a_property = self.a_property

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

return field_dict

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

def _parse_a_property(data: Any) -> Union[Unset, AnEnum, AnIntEnum]:
data = None if isinstance(data, Unset) else data
a_property: Union[Unset, AnEnum, AnIntEnum]
try:
a_property = UNSET
_a_property = data
if not isinstance(_a_property, Unset):
a_property = AnEnum(_a_property)

return a_property
except: # noqa: E722
pass
a_property = UNSET
_a_property = data
if not isinstance(_a_property, Unset):
a_property = AnIntEnum(_a_property)

return a_property

a_property = _parse_a_property(d.pop("a_property", UNSET))

a_model_not_required_nullable_model = cls(
a_property=a_property,
)

a_model_not_required_nullable_model.additional_properties = d
return a_model_not_required_nullable_model
Expand Down
@@ -1,28 +1,71 @@
from typing import Any, Dict, List, Type, TypeVar
from typing import Any, Dict, List, Type, TypeVar, Union

import attr

from ..models.an_enum import AnEnum
from ..models.an_int_enum import AnIntEnum
from ..types import UNSET, Unset

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


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

a_property: Union[Unset, AnEnum, AnIntEnum] = UNSET
additional_properties: Dict[str, Any] = attr.ib(init=False, factory=dict)

def to_dict(self) -> Dict[str, Any]:
a_property: Union[Unset, AnEnum, AnIntEnum]
if isinstance(self.a_property, Unset):
a_property = UNSET
elif isinstance(self.a_property, AnEnum):
a_property = UNSET
if not isinstance(self.a_property, Unset):
a_property = self.a_property

else:
a_property = UNSET
if not isinstance(self.a_property, Unset):
a_property = self.a_property

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

return field_dict

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

def _parse_a_property(data: Any) -> Union[Unset, AnEnum, AnIntEnum]:
data = None if isinstance(data, Unset) else data
a_property: Union[Unset, AnEnum, AnIntEnum]
try:
a_property = UNSET
_a_property = data
if not isinstance(_a_property, Unset):
a_property = AnEnum(_a_property)

return a_property
except: # noqa: E722
pass
a_property = UNSET
_a_property = data
if not isinstance(_a_property, Unset):
a_property = AnIntEnum(_a_property)

return a_property

a_property = _parse_a_property(d.pop("a_property", UNSET))

a_model_nullable_model = cls(
a_property=a_property,
)

a_model_nullable_model.additional_properties = d
return a_model_nullable_model
Expand Down
@@ -0,0 +1,54 @@
from typing import Any, Dict, List, Type, TypeVar, Union

import attr

from ..types import UNSET, Unset

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


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

a_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

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

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)

all_of_sub_model = cls(
a_sub_property=a_sub_property,
)

all_of_sub_model.additional_properties = d
return all_of_sub_model

@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