add nullable to Ruby client (#1059)

This commit is contained in:
William Cheng 2018-09-20 19:31:47 +08:00 committed by GitHub
parent cc6efe01c7
commit 29e9f5bda0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 0 deletions

View File

@ -43,6 +43,7 @@ module {{moduleName}}
@api_client.config.logger.debug 'Calling API: {{classname}}.{{operationId}} ...'
end
{{#allParams}}
{{^isNullable}}
{{#required}}
# verify the required parameter '{{paramName}}' is set
if @api_client.config.client_side_validation && {{{paramName}}}.nil?
@ -57,6 +58,7 @@ module {{moduleName}}
{{/isContainer}}
{{/isEnum}}
{{/required}}
{{/isNullable}}
{{^required}}
{{#isEnum}}
{{#collectionFormat}}

View File

@ -87,12 +87,14 @@
def list_invalid_properties
invalid_properties = Array.new
{{#vars}}
{{^isNullable}}
{{#required}}
if @{{{name}}}.nil?
invalid_properties.push('invalid value for "{{{name}}}", {{{name}}} cannot be nil.')
end
{{/required}}
{{/isNullable}}
{{#hasValidation}}
{{#maxLength}}
if {{^required}}!@{{{name}}}.nil? && {{/required}}@{{{name}}}.to_s.length > {{{maxLength}}}
@ -145,9 +147,11 @@
# @return true if the model is valid
def valid?
{{#vars}}
{{^isNullable}}
{{#required}}
return false if @{{{name}}}.nil?
{{/required}}
{{/isNullable}}
{{#isEnum}}
{{^isContainer}}
{{{name}}}_validator = EnumAttributeValidator.new('{{{dataType}}}', [{{#allowableValues}}{{#values}}'{{{this}}}'{{^-last}}, {{/-last}}{{/values}}{{/allowableValues}}])
@ -201,12 +205,14 @@
# Custom attribute writer method with validation
# @param [Object] {{{name}}} Value to be assigned
def {{{name}}}=({{{name}}})
{{^isNullable}}
{{#required}}
if {{{name}}}.nil?
fail ArgumentError, '{{{name}}} cannot be nil'
end
{{/required}}
{{/isNullable}}
{{#maxLength}}
if {{^required}}!{{{name}}}.nil? && {{/required}}{{{name}}}.to_s.length > {{{maxLength}}}
fail ArgumentError, 'invalid value for "{{{name}}}", the character length must be smaller than or equal to {{{maxLength}}}.'