Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions modules/swagger-codegen/src/main/resources/python/model.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -88,37 +88,37 @@ class {{classname}}(object):
{{/isContainer}}
{{/isEnum}}
{{^isEnum}}
{{#hasValidation}}
{{#required}}
if {{name}} is None:
raise ValueError("Invalid value for `{{name}}`, must not be `None`")
{{/required}}
{{#hasValidation}}
{{#maxLength}}
if len({{name}}) > {{maxLength}}:
if {{name}} is not None and len({{name}}) > {{maxLength}}:
raise ValueError("Invalid value for `{{name}}`, length must be less than or equal to `{{maxLength}}`")
{{/maxLength}}
{{#minLength}}
if len({{name}}) < {{minLength}}:
if {{name}} is not None and len({{name}}) < {{minLength}}:
raise ValueError("Invalid value for `{{name}}`, length must be greater than or equal to `{{minLength}}`")
{{/minLength}}
{{#maximum}}
if {{name}} >{{#exclusiveMaximum}}={{/exclusiveMaximum}} {{maximum}}:
if {{name}} is not None and {{name}} >{{#exclusiveMaximum}}={{/exclusiveMaximum}} {{maximum}}:
raise ValueError("Invalid value for `{{name}}`, must be a value less than {{^exclusiveMaximum}}or equal to {{/exclusiveMaximum}}`{{maximum}}`")
{{/maximum}}
{{#minimum}}
if {{name}} <{{#exclusiveMinimum}}={{/exclusiveMinimum}} {{minimum}}:
if {{name}} is not None and {{name}} <{{#exclusiveMinimum}}={{/exclusiveMinimum}} {{minimum}}:
raise ValueError("Invalid value for `{{name}}`, must be a value greater than {{^exclusiveMinimum}}or equal to {{/exclusiveMinimum}}`{{minimum}}`")
{{/minimum}}
{{#pattern}}
if not re.search('{{{vendorExtensions.x-regex}}}', {{name}}{{#vendorExtensions.x-modifiers}}{{#-first}}, flags={{/-first}}re.{{.}}{{^-last}} | {{/-last}}{{/vendorExtensions.x-modifiers}}):
if {{name}} is not None and not re.search('{{{vendorExtensions.x-regex}}}', {{name}}{{#vendorExtensions.x-modifiers}}{{#-first}}, flags={{/-first}}re.{{.}}{{^-last}} | {{/-last}}{{/vendorExtensions.x-modifiers}}):
raise ValueError("Invalid value for `{{name}}`, must be a follow pattern or equal to `{{{pattern}}}`")
{{/pattern}}
{{#maxItems}}
if len({{name}}) > {{maxItems}}:
if {{name}} is not None and len({{name}}) > {{maxItems}}:
raise ValueError("Invalid value for `{{name}}`, number of items must be less than or equal to `{{maxItems}}`")
{{/maxItems}}
{{#minItems}}
if len({{name}}) < {{minItems}}:
if {{name}} is not None and len({{name}}) < {{minItems}}:
raise ValueError("Invalid value for `{{name}}`, number of items must be greater than or equal to `{{minItems}}`")
{{/minItems}}
{{/hasValidation}}
Expand Down
2 changes: 2 additions & 0 deletions samples/client/petstore/python/petstore_api/models/animal.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ def class_name(self, class_name):
:param class_name: The class_name of this Animal.
:type: str
"""
if class_name is None:
raise ValueError("Invalid value for `class_name`, must not be `None`")

self._class_name = class_name

Expand Down
2 changes: 2 additions & 0 deletions samples/client/petstore/python/petstore_api/models/cat.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ def class_name(self, class_name):
:param class_name: The class_name of this Cat.
:type: str
"""
if class_name is None:
raise ValueError("Invalid value for `class_name`, must not be `None`")

self._class_name = class_name

Expand Down
2 changes: 2 additions & 0 deletions samples/client/petstore/python/petstore_api/models/dog.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ def class_name(self, class_name):
:param class_name: The class_name of this Dog.
:type: str
"""
if class_name is None:
raise ValueError("Invalid value for `class_name`, must not be `None`")

self._class_name = class_name

Expand Down
34 changes: 19 additions & 15 deletions samples/client/petstore/python/petstore_api/models/format_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,9 @@ def integer(self, integer):
:param integer: The integer of this FormatTest.
:type: int
"""
if integer > 100.0:
if integer is not None and integer > 100.0:
raise ValueError("Invalid value for `integer`, must be a value less than or equal to `100.0`")
if integer < 10.0:
if integer is not None and integer < 10.0:
raise ValueError("Invalid value for `integer`, must be a value greater than or equal to `10.0`")

self._integer = integer
Expand All @@ -135,9 +135,9 @@ def int32(self, int32):
:param int32: The int32 of this FormatTest.
:type: int
"""
if int32 > 200.0:
if int32 is not None and int32 > 200.0:
raise ValueError("Invalid value for `int32`, must be a value less than or equal to `200.0`")
if int32 < 20.0:
if int32 is not None and int32 < 20.0:
raise ValueError("Invalid value for `int32`, must be a value greater than or equal to `20.0`")

self._int32 = int32
Expand Down Expand Up @@ -185,11 +185,11 @@ def number(self, number):
:param number: The number of this FormatTest.
:type: float
"""
if not number:
if number is None:
raise ValueError("Invalid value for `number`, must not be `None`")
if number > 543.2:
if number is not None and number > 543.2:
raise ValueError("Invalid value for `number`, must be a value less than or equal to `543.2`")
if number < 32.1:
if number is not None and number < 32.1:
raise ValueError("Invalid value for `number`, must be a value greater than or equal to `32.1`")

self._number = number
Expand All @@ -214,9 +214,9 @@ def float(self, float):
:param float: The float of this FormatTest.
:type: float
"""
if float > 987.6:
if float is not None and float > 987.6:
raise ValueError("Invalid value for `float`, must be a value less than or equal to `987.6`")
if float < 54.3:
if float is not None and float < 54.3:
raise ValueError("Invalid value for `float`, must be a value greater than or equal to `54.3`")

self._float = float
Expand All @@ -241,9 +241,9 @@ def double(self, double):
:param double: The double of this FormatTest.
:type: float
"""
if double > 123.4:
if double is not None and double > 123.4:
raise ValueError("Invalid value for `double`, must be a value less than or equal to `123.4`")
if double < 67.8:
if double is not None and double < 67.8:
raise ValueError("Invalid value for `double`, must be a value greater than or equal to `67.8`")

self._double = double
Expand All @@ -268,7 +268,7 @@ def string(self, string):
:param string: The string of this FormatTest.
:type: str
"""
if not re.search('[a-z]', string, flags=re.IGNORECASE):
if string is not None and not re.search('[a-z]', string, flags=re.IGNORECASE):
raise ValueError("Invalid value for `string`, must be a follow pattern or equal to `/[a-z]/i`")

self._string = string
Expand All @@ -293,6 +293,8 @@ def byte(self, byte):
:param byte: The byte of this FormatTest.
:type: str
"""
if byte is None:
raise ValueError("Invalid value for `byte`, must not be `None`")

self._byte = byte

Expand Down Expand Up @@ -339,6 +341,8 @@ def date(self, date):
:param date: The date of this FormatTest.
:type: date
"""
if date is None:
raise ValueError("Invalid value for `date`, must not be `None`")

self._date = date

Expand Down Expand Up @@ -408,11 +412,11 @@ def password(self, password):
:param password: The password of this FormatTest.
:type: str
"""
if not password:
if password is None:
raise ValueError("Invalid value for `password`, must not be `None`")
if len(password) > 64:
if password is not None and len(password) > 64:
raise ValueError("Invalid value for `password`, length must be less than or equal to `64`")
if len(password) < 10:
if password is not None and len(password) < 10:
raise ValueError("Invalid value for `password`, length must be greater than or equal to `10`")

self._password = password
Expand Down
2 changes: 2 additions & 0 deletions samples/client/petstore/python/petstore_api/models/name.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ def name(self, name):
:param name: The name of this Name.
:type: int
"""
if name is None:
raise ValueError("Invalid value for `name`, must not be `None`")

self._name = name

Expand Down
4 changes: 4 additions & 0 deletions samples/client/petstore/python/petstore_api/models/pet.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ def name(self, name):
:param name: The name of this Pet.
:type: str
"""
if name is None:
raise ValueError("Invalid value for `name`, must not be `None`")

self._name = name

Expand All @@ -156,6 +158,8 @@ def photo_urls(self, photo_urls):
:param photo_urls: The photo_urls of this Pet.
:type: list[str]
"""
if photo_urls is None:
raise ValueError("Invalid value for `photo_urls`, must not be `None`")

self._photo_urls = photo_urls

Expand Down