| 1 | import pprint
|
|---|
| 2 |
|
|---|
| 3 | import six
|
|---|
| 4 | {{^supportPython2}}
|
|---|
| 5 | import typing
|
|---|
| 6 | {{/supportPython2}}
|
|---|
| 7 |
|
|---|
| 8 | from {{packageName}} import util
|
|---|
| 9 | {{^supportPython2}}
|
|---|
| 10 |
|
|---|
| 11 | T = typing.TypeVar('T')
|
|---|
| 12 | {{/supportPython2}}
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 | class Model(object):
|
|---|
| 16 | # openapiTypes: The key is attribute name and the
|
|---|
| 17 | # value is attribute type.
|
|---|
| 18 | openapi_types = {}
|
|---|
| 19 |
|
|---|
| 20 | # attributeMap: The key is attribute name and the
|
|---|
| 21 | # value is json key in definition.
|
|---|
| 22 | attribute_map = {}
|
|---|
| 23 |
|
|---|
| 24 | @classmethod
|
|---|
| 25 | def from_dict(cls{{^supportPython2}}: typing.Type[T]{{/supportPython2}}, dikt){{^supportPython2}} -> T{{/supportPython2}}:
|
|---|
| 26 | """Returns the dict as a model"""
|
|---|
| 27 | return util.deserialize_model(dikt, cls)
|
|---|
| 28 |
|
|---|
| 29 | def to_dict(self):
|
|---|
| 30 | """Returns the model properties as a dict
|
|---|
| 31 |
|
|---|
| 32 | :rtype: dict
|
|---|
| 33 | """
|
|---|
| 34 | result = {}
|
|---|
| 35 |
|
|---|
| 36 | for attr, _ in six.iteritems(self.openapi_types):
|
|---|
| 37 | value = getattr(self, attr)
|
|---|
| 38 | if isinstance(value, list):
|
|---|
| 39 | result[attr] = list(map(
|
|---|
| 40 | lambda x: x.to_dict() if hasattr(x, "to_dict") else x,
|
|---|
| 41 | value
|
|---|
| 42 | ))
|
|---|
| 43 | elif hasattr(value, "to_dict"):
|
|---|
| 44 | result[attr] = value.to_dict()
|
|---|
| 45 | elif isinstance(value, dict):
|
|---|
| 46 | result[attr] = dict(map(
|
|---|
| 47 | lambda item: (item[0], item[1].to_dict())
|
|---|
| 48 | if hasattr(item[1], "to_dict") else item,
|
|---|
| 49 | value.items()
|
|---|
| 50 | ))
|
|---|
| 51 | else:
|
|---|
| 52 | result[attr] = value
|
|---|
| 53 |
|
|---|
| 54 | return result
|
|---|
| 55 |
|
|---|
| 56 | def to_str(self):
|
|---|
| 57 | """Returns the string representation of the model
|
|---|
| 58 |
|
|---|
| 59 | :rtype: str
|
|---|
| 60 | """
|
|---|
| 61 | return pprint.pformat(self.to_dict())
|
|---|
| 62 |
|
|---|
| 63 | def __repr__(self):
|
|---|
| 64 | """For `print` and `pprint`"""
|
|---|
| 65 | return self.to_str()
|
|---|
| 66 |
|
|---|
| 67 | def __eq__(self, other):
|
|---|
| 68 | """Returns true if both objects are equal"""
|
|---|
| 69 | return self.__dict__ == other.__dict__
|
|---|
| 70 |
|
|---|
| 71 | def __ne__(self, other):
|
|---|
| 72 | """Returns true if both objects are not equal"""
|
|---|
| 73 | return not self == other
|
|---|