Add additionalProperties handling in python code genrator by adding dictionary handling in model's to_dict() method

This commit is contained in:
Matan Goldman 2016-02-07 13:11:28 +02:00
parent a9ab8a6e98
commit ab39eff8a1
6 changed files with 42 additions and 12 deletions

View File

@ -95,6 +95,11 @@ class {{classname}}(object):
lambda x: x.to_dict() if hasattr(x, "to_dict") else x,
value
))
elif isinstance(value, dict):
result[attr] = dict(map(
lambda (k, v): (k, v.to_dict()) if hasattr(v, "to_dict") else (k, v),
value.iteritems()
))
elif hasattr(value, "to_dict"):
result[attr] = value.to_dict()
else:
@ -114,14 +119,14 @@ class {{classname}}(object):
"""
return self.to_str()
def __eq__(self, other):
def __eq__(self, other):
"""
Returns true if both objects are equal
"""
return self.__dict__ == other.__dict__
def __ne__(self, other):
"""
"""
Returns true if both objects are not equal
"""
return not self == other

View File

@ -106,6 +106,11 @@ class Category(object):
lambda x: x.to_dict() if hasattr(x, "to_dict") else x,
value
))
elif isinstance(value, dict):
result[attr] = dict(map(
lambda (k, v): (k, v.to_dict()) if hasattr(v, "to_dict") else (k, v),
value.iteritems()
))
elif hasattr(value, "to_dict"):
result[attr] = value.to_dict()
else:
@ -125,14 +130,14 @@ class Category(object):
"""
return self.to_str()
def __eq__(self, other):
def __eq__(self, other):
"""
Returns true if both objects are equal
"""
return self.__dict__ == other.__dict__
def __ne__(self, other):
"""
"""
Returns true if both objects are not equal
"""
return not self == other

View File

@ -212,6 +212,11 @@ class Order(object):
lambda x: x.to_dict() if hasattr(x, "to_dict") else x,
value
))
elif isinstance(value, dict):
result[attr] = dict(map(
lambda (k, v): (k, v.to_dict()) if hasattr(v, "to_dict") else (k, v),
value.iteritems()
))
elif hasattr(value, "to_dict"):
result[attr] = value.to_dict()
else:
@ -231,14 +236,14 @@ class Order(object):
"""
return self.to_str()
def __eq__(self, other):
def __eq__(self, other):
"""
Returns true if both objects are equal
"""
return self.__dict__ == other.__dict__
def __ne__(self, other):
"""
"""
Returns true if both objects are not equal
"""
return not self == other

View File

@ -212,6 +212,11 @@ class Pet(object):
lambda x: x.to_dict() if hasattr(x, "to_dict") else x,
value
))
elif isinstance(value, dict):
result[attr] = dict(map(
lambda (k, v): (k, v.to_dict()) if hasattr(v, "to_dict") else (k, v),
value.iteritems()
))
elif hasattr(value, "to_dict"):
result[attr] = value.to_dict()
else:
@ -231,14 +236,14 @@ class Pet(object):
"""
return self.to_str()
def __eq__(self, other):
def __eq__(self, other):
"""
Returns true if both objects are equal
"""
return self.__dict__ == other.__dict__
def __ne__(self, other):
"""
"""
Returns true if both objects are not equal
"""
return not self == other

View File

@ -106,6 +106,11 @@ class Tag(object):
lambda x: x.to_dict() if hasattr(x, "to_dict") else x,
value
))
elif isinstance(value, dict):
result[attr] = dict(map(
lambda (k, v): (k, v.to_dict()) if hasattr(v, "to_dict") else (k, v),
value.iteritems()
))
elif hasattr(value, "to_dict"):
result[attr] = value.to_dict()
else:
@ -125,14 +130,14 @@ class Tag(object):
"""
return self.to_str()
def __eq__(self, other):
def __eq__(self, other):
"""
Returns true if both objects are equal
"""
return self.__dict__ == other.__dict__
def __ne__(self, other):
"""
"""
Returns true if both objects are not equal
"""
return not self == other

View File

@ -256,6 +256,11 @@ class User(object):
lambda x: x.to_dict() if hasattr(x, "to_dict") else x,
value
))
elif isinstance(value, dict):
result[attr] = dict(map(
lambda (k, v): (k, v.to_dict()) if hasattr(v, "to_dict") else (k, v),
value.iteritems()
))
elif hasattr(value, "to_dict"):
result[attr] = value.to_dict()
else:
@ -275,14 +280,14 @@ class User(object):
"""
return self.to_str()
def __eq__(self, other):
def __eq__(self, other):
"""
Returns true if both objects are equal
"""
return self.__dict__ == other.__dict__
def __ne__(self, other):
"""
"""
Returns true if both objects are not equal
"""
return not self == other