Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ruby: Fix boolean convertion on json to model attribute. #2092

Merged
merged 2 commits into from
Feb 10, 2016
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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/ruby/lib/petstore/models/order.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/ruby/lib/petstore/models/pet.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/ruby/lib/petstore/models/tag.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/ruby/lib/petstore/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
29 changes: 24 additions & 5 deletions samples/client/petstore/ruby/spec/base_object_spec.rb
Original file line number Diff line number Diff line change
@@ -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
{
Expand All @@ -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

Expand All @@ -21,7 +23,9 @@ def self.swagger_types
:int_map => :'Hash<String, Integer>',
:pet_map => :'Hash<String, Pet>',
:int_arr_map => :'Hash<String, Array<Integer>>',
:pet_arr_map => :'Hash<String, Array<Pet>>'
:pet_arr_map => :'Hash<String, Array<Pet>>',
:boolean_true_arr => :'Array<BOOLEAN>',
:boolean_false_arr => :'Array<BOOLEAN>',
}
end
end
Expand All @@ -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

Expand Down Expand Up @@ -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