forked from loafle/openapi-generator-original
Issue 5375 (#5403)
* use py3 instead of py34 * fixed test to test invalid enum * ADDED: assign variable in the ctor with property setter to check validity if possible. CHANGE: move required property check to proper place. CHANGE: remove double quotes from allowed_values for none-string enum property * rebuilt samples * comment for improvement * ADDED: post process enum model for python. * comment * rebuilt samples * rebuilt samples
This commit is contained in:
@@ -14,6 +14,13 @@ class {{classname}}(object):
|
||||
NOTE: This class is auto generated by the swagger code generator program.
|
||||
Do not edit the class manually.
|
||||
"""
|
||||
{{#allowableValues}}
|
||||
|
||||
{{#enumVars}}
|
||||
{{name}} = {{{value}}}
|
||||
{{/enumVars}}
|
||||
|
||||
{{/allowableValues}}
|
||||
def __init__(self{{#vars}}, {{name}}={{#defaultValue}}{{{defaultValue}}}{{/defaultValue}}{{^defaultValue}}None{{/defaultValue}}{{/vars}}):
|
||||
"""
|
||||
{{classname}} - a model defined in Swagger
|
||||
@@ -34,7 +41,15 @@ class {{classname}}(object):
|
||||
}
|
||||
|
||||
{{#vars}}
|
||||
self._{{name}} = {{name}}
|
||||
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}}
|
||||
if {{name}} is not None:
|
||||
self.{{name}} = {{name}}
|
||||
{{/vars}}
|
||||
|
||||
{{#vars}}
|
||||
@@ -62,9 +77,13 @@ class {{classname}}(object):
|
||||
:param {{name}}: The {{name}} of this {{classname}}.
|
||||
:type: {{datatype}}
|
||||
"""
|
||||
{{#required}}
|
||||
if {{name}} is None:
|
||||
raise ValueError("Invalid value for `{{name}}`, must not be `None`")
|
||||
{{/required}}
|
||||
{{#isEnum}}
|
||||
allowed_values = [{{#allowableValues}}{{#values}}"{{{this}}}"{{^-last}}, {{/-last}}{{/values}}{{/allowableValues}}]
|
||||
{{#isContainer}}
|
||||
allowed_values = [{{#allowableValues}}{{#values}}{{#items.isString}}"{{/items.isString}}{{{this}}}{{#items.isString}}"{{/items.isString}}{{^-last}}, {{/-last}}{{/values}}{{/allowableValues}}]
|
||||
{{#isListContainer}}
|
||||
if not set({{{name}}}).issubset(set(allowed_values)):
|
||||
raise ValueError(
|
||||
@@ -83,6 +102,7 @@ class {{classname}}(object):
|
||||
{{/isMapContainer}}
|
||||
{{/isContainer}}
|
||||
{{^isContainer}}
|
||||
allowed_values = [{{#allowableValues}}{{#values}}{{#isString}}"{{/isString}}{{{this}}}{{#isString}}"{{/isString}}{{^-last}}, {{/-last}}{{/values}}{{/allowableValues}}]
|
||||
if {{{name}}} not in allowed_values:
|
||||
raise ValueError(
|
||||
"Invalid value for `{{{name}}}` ({0}), must be one of {1}"
|
||||
@@ -91,10 +111,6 @@ class {{classname}}(object):
|
||||
{{/isContainer}}
|
||||
{{/isEnum}}
|
||||
{{^isEnum}}
|
||||
{{#required}}
|
||||
if {{name}} is None:
|
||||
raise ValueError("Invalid value for `{{name}}`, must not be `None`")
|
||||
{{/required}}
|
||||
{{#hasValidation}}
|
||||
{{#maxLength}}
|
||||
if {{name}} is not None and len({{name}}) > {{maxLength}}:
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
[tox]
|
||||
envlist = py27, py34
|
||||
envlist = py27, py3
|
||||
|
||||
[testenv]
|
||||
deps=-r{toxinidir}/requirements.txt
|
||||
|
||||
Reference in New Issue
Block a user