diff --git a/modules/openapi-generator/src/main/resources/ruby-client/api.mustache b/modules/openapi-generator/src/main/resources/ruby-client/api.mustache index b65c0578a17..568f9c1903c 100644 --- a/modules/openapi-generator/src/main/resources/ruby-client/api.mustache +++ b/modules/openapi-generator/src/main/resources/ruby-client/api.mustache @@ -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}} diff --git a/modules/openapi-generator/src/main/resources/ruby-client/partial_model_generic.mustache b/modules/openapi-generator/src/main/resources/ruby-client/partial_model_generic.mustache index eb91155ed06..576a8444f02 100644 --- a/modules/openapi-generator/src/main/resources/ruby-client/partial_model_generic.mustache +++ b/modules/openapi-generator/src/main/resources/ruby-client/partial_model_generic.mustache @@ -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}}}.'