From a442e1a60d995bd31429f737ab8f20c6ae8f4531 Mon Sep 17 00:00:00 2001 From: Tatsuki Sugiura Date: Wed, 10 Feb 2016 15:06:31 +0900 Subject: [PATCH 1/2] ruby: Fix boolean convertion on json to model attribute. Current code will converts boolean true of json to false because ruby's boolean is not matched with any regex. --- .../src/main/resources/ruby/base_object.mustache | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/swagger-codegen/src/main/resources/ruby/base_object.mustache b/modules/swagger-codegen/src/main/resources/ruby/base_object.mustache index d4ea5b334a6..d54354c982d 100644 --- a/modules/swagger-codegen/src/main/resources/ruby/base_object.mustache +++ b/modules/swagger-codegen/src/main/resources/ruby/base_object.mustache @@ -31,7 +31,7 @@ when :Float value.to_f when :BOOLEAN - if value =~ /^(true|t|yes|y|1)$/i + if value.to_s =~ /^(true|t|yes|y|1)$/i true else false From 0ea7ae1c1657e43c617213c6cc713a4a275cfedd Mon Sep 17 00:00:00 2001 From: Tatsuki Sugiura Date: Wed, 10 Feb 2016 19:18:03 +0900 Subject: [PATCH 2/2] ruby: Add test for boolean convertion. --- .../ruby/lib/petstore/models/category.rb | 2 +- .../ruby/lib/petstore/models/order.rb | 2 +- .../petstore/ruby/lib/petstore/models/pet.rb | 2 +- .../petstore/ruby/lib/petstore/models/tag.rb | 2 +- .../petstore/ruby/lib/petstore/models/user.rb | 2 +- .../petstore/ruby/spec/base_object_spec.rb | 29 +++++++++++++++---- 6 files changed, 29 insertions(+), 10 deletions(-) diff --git a/samples/client/petstore/ruby/lib/petstore/models/category.rb b/samples/client/petstore/ruby/lib/petstore/models/category.rb index 01126b58e89..5427f0d6b2e 100644 --- a/samples/client/petstore/ruby/lib/petstore/models/category.rb +++ b/samples/client/petstore/ruby/lib/petstore/models/category.rb @@ -110,7 +110,7 @@ def _deserialize(type, value) when :Float value.to_f when :BOOLEAN - if value =~ /^(true|t|yes|y|1)$/i + if value.to_s =~ /^(true|t|yes|y|1)$/i true else false diff --git a/samples/client/petstore/ruby/lib/petstore/models/order.rb b/samples/client/petstore/ruby/lib/petstore/models/order.rb index fd6264496d5..61d545e57b7 100644 --- a/samples/client/petstore/ruby/lib/petstore/models/order.rb +++ b/samples/client/petstore/ruby/lib/petstore/models/order.rb @@ -160,7 +160,7 @@ def _deserialize(type, value) when :Float value.to_f when :BOOLEAN - if value =~ /^(true|t|yes|y|1)$/i + if value.to_s =~ /^(true|t|yes|y|1)$/i true else false diff --git a/samples/client/petstore/ruby/lib/petstore/models/pet.rb b/samples/client/petstore/ruby/lib/petstore/models/pet.rb index 380d740fb97..78a2747de16 100644 --- a/samples/client/petstore/ruby/lib/petstore/models/pet.rb +++ b/samples/client/petstore/ruby/lib/petstore/models/pet.rb @@ -164,7 +164,7 @@ def _deserialize(type, value) when :Float value.to_f when :BOOLEAN - if value =~ /^(true|t|yes|y|1)$/i + if value.to_s =~ /^(true|t|yes|y|1)$/i true else false diff --git a/samples/client/petstore/ruby/lib/petstore/models/tag.rb b/samples/client/petstore/ruby/lib/petstore/models/tag.rb index 9289df5c01b..33362d56ce0 100644 --- a/samples/client/petstore/ruby/lib/petstore/models/tag.rb +++ b/samples/client/petstore/ruby/lib/petstore/models/tag.rb @@ -110,7 +110,7 @@ def _deserialize(type, value) when :Float value.to_f when :BOOLEAN - if value =~ /^(true|t|yes|y|1)$/i + if value.to_s =~ /^(true|t|yes|y|1)$/i true else false diff --git a/samples/client/petstore/ruby/lib/petstore/models/user.rb b/samples/client/petstore/ruby/lib/petstore/models/user.rb index 742a16b3b2d..9f61101cfda 100644 --- a/samples/client/petstore/ruby/lib/petstore/models/user.rb +++ b/samples/client/petstore/ruby/lib/petstore/models/user.rb @@ -171,7 +171,7 @@ def _deserialize(type, value) when :Float value.to_f when :BOOLEAN - if value =~ /^(true|t|yes|y|1)$/i + if value.to_s =~ /^(true|t|yes|y|1)$/i true else false diff --git a/samples/client/petstore/ruby/spec/base_object_spec.rb b/samples/client/petstore/ruby/spec/base_object_spec.rb index a2614ba9c16..61dcb4d6d9d 100644 --- a/samples/client/petstore/ruby/spec/base_object_spec.rb +++ b/samples/client/petstore/ruby/spec/base_object_spec.rb @@ -1,7 +1,7 @@ require 'spec_helper' class ArrayMapObject < Petstore::Category - attr_accessor :int_arr, :pet_arr, :int_map, :pet_map, :int_arr_map, :pet_arr_map + attr_accessor :int_arr, :pet_arr, :int_map, :pet_map, :int_arr_map, :pet_arr_map, :boolean_true_arr, :boolean_false_arr def self.attribute_map { @@ -10,7 +10,9 @@ def self.attribute_map :int_map => :int_map, :pet_map => :pet_map, :int_arr_map => :int_arr_map, - :pet_arr_map => :pet_arr_map + :pet_arr_map => :pet_arr_map, + :boolean_true_arr => :boolean_true_arr, + :boolean_false_arr => :boolean_false_arr, } end @@ -21,7 +23,9 @@ def self.swagger_types :int_map => :'Hash', :pet_map => :'Hash', :int_arr_map => :'Hash>', - :pet_arr_map => :'Hash>' + :pet_arr_map => :'Hash>', + :boolean_true_arr => :'Array', + :boolean_false_arr => :'Array', } end end @@ -37,7 +41,9 @@ def self.swagger_types int_map: {'int' => 123}, pet_map: {'pet' => {name: 'Kitty'}}, int_arr_map: {'int_arr' => [123, 456]}, - pet_arr_map: {'pet_arr' => [{name: 'Kitty'}]} + pet_arr_map: {'pet_arr' => [{name: 'Kitty'}]}, + boolean_true_arr: [true, "true", "TruE", 1, "y", "yes", "1", "t", "T"], + boolean_false_arr: [false, "", 0, "0", "f", nil, "null"], } end @@ -71,11 +77,24 @@ def self.swagger_types pet = arr.first pet.should be_a(Petstore::Pet) pet.name.should == 'Kitty' + + obj.boolean_true_arr.should be_a(Array) + obj.boolean_true_arr.each do |b| + b.should eq true + end + + obj.boolean_false_arr.should be_a(Array) + obj.boolean_false_arr.each do |b| + b.should eq false + end end it 'works for #to_hash' do obj.build_from_hash(data) - obj.to_hash.should == data + expect_data = data.dup + expect_data[:boolean_true_arr].map! {true} + expect_data[:boolean_false_arr].map! {false} + obj.to_hash.should == expect_data end end end