From 47c387470c12f6e3f69225e1ff95409dd117074e Mon Sep 17 00:00:00 2001 From: wing328 Date: Thu, 13 Oct 2016 16:38:39 +0800 Subject: [PATCH] fix required prop check for ruby client --- .../resources/ruby/partial_model_generic.mustache | 4 ++-- .../petstore/ruby/lib/petstore/models/animal.rb | 4 ++++ .../client/petstore/ruby/lib/petstore/models/cat.rb | 4 ++++ .../client/petstore/ruby/lib/petstore/models/dog.rb | 4 ++++ .../ruby/lib/petstore/models/format_test.rb | 13 ++++++++----- .../petstore/ruby/lib/petstore/models/name.rb | 4 ++++ .../client/petstore/ruby/lib/petstore/models/pet.rb | 8 ++++++++ 7 files changed, 34 insertions(+), 7 deletions(-) diff --git a/modules/swagger-codegen/src/main/resources/ruby/partial_model_generic.mustache b/modules/swagger-codegen/src/main/resources/ruby/partial_model_generic.mustache index 20662ae9771..00a75b25396 100644 --- a/modules/swagger-codegen/src/main/resources/ruby/partial_model_generic.mustache +++ b/modules/swagger-codegen/src/main/resources/ruby/partial_model_generic.mustache @@ -78,13 +78,13 @@ def list_invalid_properties invalid_properties = Array.new {{#vars}} - {{#hasValidation}} {{#required}} if @{{{name}}}.nil? invalid_properties.push("invalid value for '{{{name}}}', {{{name}}} cannot be nil.") end - {{/required}} + {{/required}} + {{#hasValidation}} {{#maxLength}} if {{^required}}!@{{{name}}}.nil? && {{/required}}@{{{name}}}.to_s.length > {{{maxLength}}} invalid_properties.push("invalid value for '{{{name}}}', the character length must be smaller than or equal to {{{maxLength}}}.") diff --git a/samples/client/petstore/ruby/lib/petstore/models/animal.rb b/samples/client/petstore/ruby/lib/petstore/models/animal.rb index 7dad66580fa..0e941aa2657 100644 --- a/samples/client/petstore/ruby/lib/petstore/models/animal.rb +++ b/samples/client/petstore/ruby/lib/petstore/models/animal.rb @@ -71,6 +71,10 @@ module Petstore # @return Array for valid properies with the reasons def list_invalid_properties invalid_properties = Array.new + if @class_name.nil? + invalid_properties.push("invalid value for 'class_name', class_name cannot be nil.") + end + return invalid_properties end diff --git a/samples/client/petstore/ruby/lib/petstore/models/cat.rb b/samples/client/petstore/ruby/lib/petstore/models/cat.rb index 7ed6e12ddd0..3d42282a5f4 100644 --- a/samples/client/petstore/ruby/lib/petstore/models/cat.rb +++ b/samples/client/petstore/ruby/lib/petstore/models/cat.rb @@ -79,6 +79,10 @@ module Petstore # @return Array for valid properies with the reasons def list_invalid_properties invalid_properties = Array.new + if @class_name.nil? + invalid_properties.push("invalid value for 'class_name', class_name cannot be nil.") + end + return invalid_properties end diff --git a/samples/client/petstore/ruby/lib/petstore/models/dog.rb b/samples/client/petstore/ruby/lib/petstore/models/dog.rb index 0e8a993caea..addfdcfec84 100644 --- a/samples/client/petstore/ruby/lib/petstore/models/dog.rb +++ b/samples/client/petstore/ruby/lib/petstore/models/dog.rb @@ -79,6 +79,10 @@ module Petstore # @return Array for valid properies with the reasons def list_invalid_properties invalid_properties = Array.new + if @class_name.nil? + invalid_properties.push("invalid value for 'class_name', class_name cannot be nil.") + end + return invalid_properties end diff --git a/samples/client/petstore/ruby/lib/petstore/models/format_test.rb b/samples/client/petstore/ruby/lib/petstore/models/format_test.rb index f734b42b993..75b105e8678 100644 --- a/samples/client/petstore/ruby/lib/petstore/models/format_test.rb +++ b/samples/client/petstore/ruby/lib/petstore/models/format_test.rb @@ -157,7 +157,6 @@ module Petstore # @return Array for valid properies with the reasons def list_invalid_properties invalid_properties = Array.new - if !@integer.nil? && @integer > 100.0 invalid_properties.push("invalid value for 'integer', must be smaller than or equal to 100.0.") end @@ -166,7 +165,6 @@ module Petstore invalid_properties.push("invalid value for 'integer', must be greater than or equal to 10.0.") end - if !@int32.nil? && @int32 > 200.0 invalid_properties.push("invalid value for 'int32', must be smaller than or equal to 200.0.") end @@ -187,7 +185,6 @@ module Petstore invalid_properties.push("invalid value for 'number', must be greater than or equal to 32.1.") end - if !@float.nil? && @float > 987.6 invalid_properties.push("invalid value for 'float', must be smaller than or equal to 987.6.") end @@ -196,7 +193,6 @@ module Petstore invalid_properties.push("invalid value for 'float', must be greater than or equal to 54.3.") end - if !@double.nil? && @double > 123.4 invalid_properties.push("invalid value for 'double', must be smaller than or equal to 123.4.") end @@ -205,11 +201,18 @@ module Petstore invalid_properties.push("invalid value for 'double', must be greater than or equal to 67.8.") end - if !@string.nil? && @string !~ Regexp.new(/[a-z]/i) invalid_properties.push("invalid value for 'string', must conform to the pattern /[a-z]/i.") end + if @byte.nil? + invalid_properties.push("invalid value for 'byte', byte cannot be nil.") + end + + if @date.nil? + invalid_properties.push("invalid value for 'date', date cannot be nil.") + end + if @password.nil? invalid_properties.push("invalid value for 'password', password cannot be nil.") end diff --git a/samples/client/petstore/ruby/lib/petstore/models/name.rb b/samples/client/petstore/ruby/lib/petstore/models/name.rb index 27a37cdc19c..47b1319b638 100644 --- a/samples/client/petstore/ruby/lib/petstore/models/name.rb +++ b/samples/client/petstore/ruby/lib/petstore/models/name.rb @@ -85,6 +85,10 @@ module Petstore # @return Array for valid properies with the reasons def list_invalid_properties invalid_properties = Array.new + if @name.nil? + invalid_properties.push("invalid value for 'name', name cannot be nil.") + end + return invalid_properties end diff --git a/samples/client/petstore/ruby/lib/petstore/models/pet.rb b/samples/client/petstore/ruby/lib/petstore/models/pet.rb index 52191258d7a..18ad44b0830 100644 --- a/samples/client/petstore/ruby/lib/petstore/models/pet.rb +++ b/samples/client/petstore/ruby/lib/petstore/models/pet.rb @@ -127,6 +127,14 @@ module Petstore # @return Array for valid properies with the reasons def list_invalid_properties invalid_properties = Array.new + if @name.nil? + invalid_properties.push("invalid value for 'name', name cannot be nil.") + end + + if @photo_urls.nil? + invalid_properties.push("invalid value for 'photo_urls', photo_urls cannot be nil.") + end + return invalid_properties end