mirror of
https://github.com/jlengrand/openapi-generator.git
synced 2026-05-18 08:31:20 +00:00
Add to_str method in python client and add test cases.
This commit is contained in:
@@ -18,6 +18,8 @@ Copyright 2015 SmartBear Software
|
||||
"""
|
||||
{{#models}}
|
||||
{{#model}}
|
||||
from pprint import pformat
|
||||
from six import iteritems
|
||||
|
||||
|
||||
class {{classname}}(object):
|
||||
@@ -64,14 +66,37 @@ class {{classname}}(object):
|
||||
{{/isEnum}}self._{{name}} = {{name}}
|
||||
|
||||
{{/vars}}
|
||||
def __repr__(self):
|
||||
properties = []
|
||||
for p in self.__dict__:
|
||||
if p != 'swaggerTypes' and p != 'attributeMap':
|
||||
properties.append('{prop}={val!r}'
|
||||
.format(prop=p, val=self.__dict__[p]))
|
||||
def to_dict(self):
|
||||
"""
|
||||
Return model properties dict
|
||||
"""
|
||||
result = {}
|
||||
|
||||
return '<{name} {props}>'.format(name=__name__,
|
||||
props=' '.join(properties))
|
||||
for name, prop in iteritems(self.__dict__):
|
||||
if name == "attribute_map" or name == "swagger_types":
|
||||
continue
|
||||
if isinstance(prop, list):
|
||||
result[name[1:]] = list(map(
|
||||
lambda x: x.to_dict() if hasattr(x, "to_dict") else x,
|
||||
prop
|
||||
))
|
||||
elif hasattr(prop, "to_dict"):
|
||||
result[name[1:]] = prop.to_dict()
|
||||
else:
|
||||
result[name[1:]] = prop
|
||||
|
||||
return result
|
||||
|
||||
def to_str(self):
|
||||
"""
|
||||
Return model properties str
|
||||
"""
|
||||
return pformat(self.to_dict())
|
||||
|
||||
def __repr__(self):
|
||||
"""
|
||||
For `print` and `pprint`
|
||||
"""
|
||||
return self.to_str()
|
||||
{{/model}}
|
||||
{{/models}}
|
||||
|
||||
Reference in New Issue
Block a user