forked from loafle/openapi-generator-original
Python improved (#5512)
* ignore .vscode * fixed test case for models requiring mandatory attributes. added deserialize test for enum class * construct model with mandatory attributes. improve class reflection (e.g. deserialize). disable generated empty model unit test for further FIXME * rebuilt samples * FIXME comment * FIXME comment * fix deserialization enum test
This commit is contained in:
@@ -608,16 +608,17 @@ class ApiClient(object):
|
||||
:param klass: class literal.
|
||||
:return: model object.
|
||||
"""
|
||||
instance = klass()
|
||||
|
||||
if not instance.swagger_types:
|
||||
if not klass.swagger_types:
|
||||
return data
|
||||
|
||||
for attr, attr_type in iteritems(instance.swagger_types):
|
||||
kwargs = {}
|
||||
for attr, attr_type in iteritems(klass.swagger_types):
|
||||
if data is not None \
|
||||
and instance.attribute_map[attr] in data \
|
||||
and klass.attribute_map[attr] in data \
|
||||
and isinstance(data, (list, dict)):
|
||||
value = data[instance.attribute_map[attr]]
|
||||
setattr(instance, attr, self.__deserialize(value, attr_type))
|
||||
value = data[klass.attribute_map[attr]]
|
||||
kwargs[attr] = self.__deserialize(value, attr_type)
|
||||
|
||||
instance = klass(**kwargs)
|
||||
|
||||
return instance
|
||||
|
||||
@@ -14,42 +14,50 @@ class {{classname}}(object):
|
||||
NOTE: This class is auto generated by the swagger code generator program.
|
||||
Do not edit the class manually.
|
||||
"""
|
||||
{{#allowableValues}}
|
||||
|
||||
{{#allowableValues}}
|
||||
"""
|
||||
allowed enum values
|
||||
"""
|
||||
{{#enumVars}}
|
||||
{{name}} = {{{value}}}
|
||||
{{/enumVars}}
|
||||
|
||||
{{/allowableValues}}
|
||||
|
||||
"""
|
||||
Attributes:
|
||||
swagger_types (dict): The key is attribute name
|
||||
and the value is attribute type.
|
||||
attribute_map (dict): The key is attribute name
|
||||
and the value is json key in definition.
|
||||
"""
|
||||
swagger_types = {
|
||||
{{#vars}}'{{name}}': '{{{datatype}}}'{{#hasMore}},
|
||||
{{/hasMore}}{{/vars}}
|
||||
}
|
||||
|
||||
attribute_map = {
|
||||
{{#vars}}'{{name}}': '{{baseName}}'{{#hasMore}},
|
||||
{{/hasMore}}{{/vars}}
|
||||
}
|
||||
|
||||
def __init__(self{{#vars}}, {{name}}={{#defaultValue}}{{{defaultValue}}}{{/defaultValue}}{{^defaultValue}}None{{/defaultValue}}{{/vars}}):
|
||||
"""
|
||||
{{classname}} - a model defined in Swagger
|
||||
|
||||
:param dict swaggerTypes: The key is attribute name
|
||||
and the value is attribute type.
|
||||
:param dict attributeMap: The key is attribute name
|
||||
and the value is json key in definition.
|
||||
"""
|
||||
self.swagger_types = {
|
||||
{{#vars}}'{{name}}': '{{{datatype}}}'{{#hasMore}},
|
||||
{{/hasMore}}{{/vars}}
|
||||
}
|
||||
|
||||
self.attribute_map = {
|
||||
{{#vars}}'{{name}}': '{{baseName}}'{{#hasMore}},
|
||||
{{/hasMore}}{{/vars}}
|
||||
}
|
||||
|
||||
{{#vars}}
|
||||
self._{{name}} = None
|
||||
{{/vars}}
|
||||
|
||||
# TODO: let required properties as mandatory parameter in the constructor.
|
||||
# - to check if required property is not None (e.g. by calling setter)
|
||||
# - ApiClient.__deserialize_model has to be adapted as well
|
||||
{{#vars}}
|
||||
{{#required}}
|
||||
self.{{name}} = {{name}}
|
||||
{{/required}}
|
||||
{{^required}}
|
||||
if {{name}} is not None:
|
||||
self.{{name}} = {{name}}
|
||||
{{/required}}
|
||||
{{/vars}}
|
||||
|
||||
{{#vars}}
|
||||
|
||||
@@ -28,7 +28,9 @@ class Test{{classname}}(unittest.TestCase):
|
||||
"""
|
||||
Test {{classname}}
|
||||
"""
|
||||
model = {{packageName}}.models.{{classFilename}}.{{classname}}()
|
||||
# FIXME: construct object with mandatory attributes with example values
|
||||
#model = {{packageName}}.models.{{classFilename}}.{{classname}}()
|
||||
pass
|
||||
|
||||
{{/model}}
|
||||
{{/models}}
|
||||
|
||||
Reference in New Issue
Block a user