Improve model class of ruby-client (#1670)

* Add Model.build_from_hash

* Use Model.build_from_hash instead of Model.new.build_from_hash

* Update sample for ruby-client

* Update sample for openapi3 ruby-client
This commit is contained in:
meganemura
2018-12-15 17:24:03 +09:00
committed by William Cheng
parent cacce1f707
commit 82fcde1d91
76 changed files with 581 additions and 148 deletions

View File

@@ -204,9 +204,7 @@ module {{moduleName}}
end
else
# models, e.g. Pet
{{moduleName}}.const_get(return_type).new.tap do |model|
model.build_from_hash data
end
{{moduleName}}.const_get(return_type).build_from_hash(data)
end
end

View File

@@ -1,3 +1,10 @@
# Builds the object from hash
# @param [Hash] attributes Model attributes in the form of hash
# @return [Object] Returns the model itself
def self.build_from_hash(attributes)
new.build_from_hash(attributes)
end
# Builds the object from hash
# @param [Hash] attributes Model attributes in the form of hash
# @return [Object] Returns the model itself
@@ -58,8 +65,7 @@
end
end
else # model
temp_model = {{moduleName}}.const_get(type).new
temp_model.build_from_hash(value)
{{moduleName}}.const_get(type).build_from_hash(value)
end
end

View File

@@ -2,6 +2,13 @@
{{#allowableValues}}{{#enumVars}}
{{{name}}} = {{{value}}}.freeze{{/enumVars}}{{/allowableValues}}
# Builds the enum from string
# @param [String] The enum value in the form of the string
# @return [String] The enum value
def self.build_from_hash(value)
new.build_from_hash(value)
end
# Builds the enum from string
# @param [String] The enum value in the form of the string
# @return [String] The enum value
@@ -10,4 +17,4 @@
raise "Invalid ENUM value #{value} for class #{{{classname}}}" if constantValues.empty?
value
end
end
end

View File

@@ -239,8 +239,7 @@
{{#-first}}
_any_of_found = false
openapi_any_of.each do |_class|
_any_of = {{moduleName}}.const_get(_class).new
_any_of.build_from_hash(self.to_hash)
_any_of = {{moduleName}}.const_get(_class).build_from_hash(self.to_hash)
if _any_of.valid?
_any_of_found = true
end
@@ -256,8 +255,7 @@
{{#-first}}
_one_of_found = false
openapi_one_of.each do |_class|
_one_of = {{moduleName}}.const_get(_class).new
_one_of.build_from_hash(self.to_hash)
_one_of = {{moduleName}}.const_get(_class).build_from_hash(self.to_hash)
if _one_of.valid?
if _one_of_found?
return false