Skip to content

Commit b1c6513

Browse files
authored
[Ruby] Added Support for Building Models from Hashes with Strings as Keys (#11243)
* [Ruby] Added Support for Building Models from Hashes with Strings as Keys * generate samples
1 parent 16fd760 commit b1c6513

85 files changed

Lines changed: 85 additions & 0 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

modules/openapi-generator/src/main/resources/ruby-client/base_object.mustache

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
{{#parent}}
1414
super(attributes)
1515
{{/parent}}
16+
attributes = attributes.transform_keys(&:to_sym)
1617
self.class.openapi_types.each_pair do |key, type|
1718
if attributes[self.class.attribute_map[key]].nil? && self.class.openapi_nullable.include?(key)
1819
self.send("#{key}=", nil)

samples/client/petstore/ruby-faraday/lib/petstore/models/additional_properties_class.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ def self.build_from_hash(attributes)
120120
# @return [Object] Returns the model itself
121121
def build_from_hash(attributes)
122122
return nil unless attributes.is_a?(Hash)
123+
attributes = attributes.transform_keys(&:to_sym)
123124
self.class.openapi_types.each_pair do |key, type|
124125
if attributes[self.class.attribute_map[key]].nil? && self.class.openapi_nullable.include?(key)
125126
self.send("#{key}=", nil)

samples/client/petstore/ruby-faraday/lib/petstore/models/animal.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ def self.build_from_hash(attributes)
128128
# @return [Object] Returns the model itself
129129
def build_from_hash(attributes)
130130
return nil unless attributes.is_a?(Hash)
131+
attributes = attributes.transform_keys(&:to_sym)
131132
self.class.openapi_types.each_pair do |key, type|
132133
if attributes[self.class.attribute_map[key]].nil? && self.class.openapi_nullable.include?(key)
133134
self.send("#{key}=", nil)

samples/client/petstore/ruby-faraday/lib/petstore/models/api_response.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ def self.build_from_hash(attributes)
125125
# @return [Object] Returns the model itself
126126
def build_from_hash(attributes)
127127
return nil unless attributes.is_a?(Hash)
128+
attributes = attributes.transform_keys(&:to_sym)
128129
self.class.openapi_types.each_pair do |key, type|
129130
if attributes[self.class.attribute_map[key]].nil? && self.class.openapi_nullable.include?(key)
130131
self.send("#{key}=", nil)

samples/client/petstore/ruby-faraday/lib/petstore/models/array_of_array_of_number_only.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ def self.build_from_hash(attributes)
109109
# @return [Object] Returns the model itself
110110
def build_from_hash(attributes)
111111
return nil unless attributes.is_a?(Hash)
112+
attributes = attributes.transform_keys(&:to_sym)
112113
self.class.openapi_types.each_pair do |key, type|
113114
if attributes[self.class.attribute_map[key]].nil? && self.class.openapi_nullable.include?(key)
114115
self.send("#{key}=", nil)

samples/client/petstore/ruby-faraday/lib/petstore/models/array_of_number_only.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ def self.build_from_hash(attributes)
109109
# @return [Object] Returns the model itself
110110
def build_from_hash(attributes)
111111
return nil unless attributes.is_a?(Hash)
112+
attributes = attributes.transform_keys(&:to_sym)
112113
self.class.openapi_types.each_pair do |key, type|
113114
if attributes[self.class.attribute_map[key]].nil? && self.class.openapi_nullable.include?(key)
114115
self.send("#{key}=", nil)

samples/client/petstore/ruby-faraday/lib/petstore/models/array_test.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ def self.build_from_hash(attributes)
155155
# @return [Object] Returns the model itself
156156
def build_from_hash(attributes)
157157
return nil unless attributes.is_a?(Hash)
158+
attributes = attributes.transform_keys(&:to_sym)
158159
self.class.openapi_types.each_pair do |key, type|
159160
if attributes[self.class.attribute_map[key]].nil? && self.class.openapi_nullable.include?(key)
160161
self.send("#{key}=", nil)

samples/client/petstore/ruby-faraday/lib/petstore/models/capitalization.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ def self.build_from_hash(attributes)
153153
# @return [Object] Returns the model itself
154154
def build_from_hash(attributes)
155155
return nil unless attributes.is_a?(Hash)
156+
attributes = attributes.transform_keys(&:to_sym)
156157
self.class.openapi_types.each_pair do |key, type|
157158
if attributes[self.class.attribute_map[key]].nil? && self.class.openapi_nullable.include?(key)
158159
self.send("#{key}=", nil)

samples/client/petstore/ruby-faraday/lib/petstore/models/cat.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ def self.build_from_hash(attributes)
119119
def build_from_hash(attributes)
120120
return nil unless attributes.is_a?(Hash)
121121
super(attributes)
122+
attributes = attributes.transform_keys(&:to_sym)
122123
self.class.openapi_types.each_pair do |key, type|
123124
if attributes[self.class.attribute_map[key]].nil? && self.class.openapi_nullable.include?(key)
124125
self.send("#{key}=", nil)

samples/client/petstore/ruby-faraday/lib/petstore/models/cat_all_of.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ def self.build_from_hash(attributes)
107107
# @return [Object] Returns the model itself
108108
def build_from_hash(attributes)
109109
return nil unless attributes.is_a?(Hash)
110+
attributes = attributes.transform_keys(&:to_sym)
110111
self.class.openapi_types.each_pair do |key, type|
111112
if attributes[self.class.attribute_map[key]].nil? && self.class.openapi_nullable.include?(key)
112113
self.send("#{key}=", nil)

0 commit comments

Comments
 (0)