mirror of
https://github.com/valitydev/openapi-generator.git
synced 2024-11-08 11:23:58 +00:00
Merge pull request #755 from wing328/ruby_cleanup_sample
[Ruby] Cleanup Ruby Petstore sample and bug fix
This commit is contained in:
commit
72a4d2df2f
@ -72,7 +72,7 @@ public class RubyClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
supportingFiles.add(new SupportingFile("swagger/response.mustache", "", "lib/swagger/response.rb"));
|
||||
supportingFiles.add(new SupportingFile("swagger/version.mustache", "", "lib/swagger/version.rb"));
|
||||
supportingFiles.add(new SupportingFile("swagger/configuration.mustache", "", "lib/swagger/configuration.rb"));
|
||||
supportingFiles.add(new SupportingFile("base_object.mustache", "", "lib/model/base_object.rb"));
|
||||
supportingFiles.add(new SupportingFile("base_object.mustache", "", "models/base_object.rb"));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -31,7 +31,7 @@ class BaseObject
|
||||
end
|
||||
|
||||
def _deserialize(type, value)
|
||||
case type.to_s
|
||||
case type.to_sym
|
||||
when :DateTime
|
||||
DateTime.parse(value)
|
||||
when :string
|
||||
|
@ -36,84 +36,6 @@ require_relative 'base_object'
|
||||
{{/vars}}
|
||||
end
|
||||
|
||||
# # return the object in the form of hash
|
||||
# def to_body
|
||||
# body = {}
|
||||
# self.class.attribute_map.each_pair do |key, value|
|
||||
# body[value] = self.send(key) unless self.send(key).nil?
|
||||
# end
|
||||
# body
|
||||
# end
|
||||
#
|
||||
# # build the object from hash
|
||||
# def build_from_hash(attributes)
|
||||
# self.class.swagger_types.each_pair do |key, type|
|
||||
# if type =~ /^array\[(.*)\]/i
|
||||
# if attributes[self.class.attribute_map[key]].is_a?(Array)
|
||||
# self.send("#{key}=", attributes[self.class.attribute_map[key]].map{ |v| _deserialize($1, v) } )
|
||||
# else
|
||||
# #TODO show warning in debug mode
|
||||
# end
|
||||
# elsif !attributes[self.class.attribute_map[key]].nil?
|
||||
# self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
|
||||
# else
|
||||
# # data not found in attributes(hash), not an issue as the data can be optional
|
||||
# end
|
||||
# end
|
||||
#
|
||||
# self
|
||||
# end
|
||||
#
|
||||
# def _deserialize(type, value)
|
||||
# case type
|
||||
# when :DateTime
|
||||
# DateTime.parse(value)
|
||||
# when :string
|
||||
# value.to_s
|
||||
# when :int
|
||||
# value.to_i
|
||||
# when :double
|
||||
# value.to_f
|
||||
# when :boolean
|
||||
# if value =~ /^(true|t|yes|y|1)$/i
|
||||
# true
|
||||
# else
|
||||
# false
|
||||
# end
|
||||
# else # model
|
||||
# _model = Object.const_get(type).new
|
||||
# _model.build_from_hash(value)
|
||||
# end
|
||||
# end
|
||||
#
|
||||
#
|
||||
#
|
||||
# # to_body is an alias to to_body (backward compatibility)
|
||||
# def to_hash
|
||||
# hash = {}
|
||||
# self.class.attribute_map.each_pair do |key, value|
|
||||
# if self.send(key).is_a?(Array)
|
||||
# next if self.send(key).empty?
|
||||
# hash[value] = self.send(key).select{|v| !v.nil?}.map{ |v| _to_hash v} unless self.send(key).nil?
|
||||
# else
|
||||
# unless (_tmp_value = _to_hash self.send(key)).nil?
|
||||
# hash[value] = _tmp_value
|
||||
# end
|
||||
# end
|
||||
# end
|
||||
# hash
|
||||
# end
|
||||
#
|
||||
# # Method to output non-array value in the form of hash
|
||||
# # For object, use to_hash. Otherwise, just return the value
|
||||
# def _to_hash(value)
|
||||
# if value.respond_to? :to_hash
|
||||
# value.to_hash
|
||||
# else
|
||||
# value
|
||||
# end
|
||||
# end
|
||||
|
||||
end
|
||||
{{/model}}
|
||||
{{/models}}
|
||||
|
@ -1,83 +0,0 @@
|
||||
# base class containing fundamental method such as to_hash, build_from_hash and more
|
||||
class BaseObject
|
||||
|
||||
# return the object in the form of hash
|
||||
def to_body
|
||||
body = {}
|
||||
self.class.attribute_map.each_pair do |key, value|
|
||||
body[value] = self.send(key) unless self.send(key).nil?
|
||||
end
|
||||
body
|
||||
end
|
||||
|
||||
# build the object from hash
|
||||
def build_from_hash(attributes)
|
||||
return nil unless attributes.is_a?(Hash)
|
||||
self.class.swagger_types.each_pair do |key, type|
|
||||
if type =~ /^array\[(.*)\]/i
|
||||
if attributes[self.class.attribute_map[key]].is_a?(Array)
|
||||
self.send("#{key}=", attributes[self.class.attribute_map[key]].map{ |v| _deserialize($1, v) } )
|
||||
else
|
||||
#TODO show warning in debug mode
|
||||
end
|
||||
elsif !attributes[self.class.attribute_map[key]].nil?
|
||||
self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
|
||||
else
|
||||
# data not found in attributes(hash), not an issue as the data can be optional
|
||||
end
|
||||
end
|
||||
|
||||
self
|
||||
end
|
||||
|
||||
def _deserialize(type, value)
|
||||
case type.to_s
|
||||
when :DateTime
|
||||
DateTime.parse(value)
|
||||
when :string
|
||||
value.to_s
|
||||
when :int
|
||||
value.to_i
|
||||
when :double
|
||||
value.to_f
|
||||
when :boolean
|
||||
if value =~ /^(true|t|yes|y|1)$/i
|
||||
true
|
||||
else
|
||||
false
|
||||
end
|
||||
else # model
|
||||
_model = Object.const_get(type).new
|
||||
_model.build_from_hash(value)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
# to_body is an alias to to_body (backward compatibility)
|
||||
def to_hash
|
||||
hash = {}
|
||||
self.class.attribute_map.each_pair do |key, value|
|
||||
if self.send(key).is_a?(Array)
|
||||
next if self.send(key).empty?
|
||||
hash[value] = self.send(key).select{|v| !v.nil?}.map{ |v| _to_hash v} unless self.send(key).nil?
|
||||
else
|
||||
unless (_tmp_value = _to_hash self.send(key)).nil?
|
||||
hash[value] = _tmp_value
|
||||
end
|
||||
end
|
||||
end
|
||||
hash
|
||||
end
|
||||
|
||||
# Method to output non-array value in the form of hash
|
||||
# For object, use to_hash. Otherwise, just return the value
|
||||
def _to_hash(value)
|
||||
if value.respond_to? :to_hash
|
||||
value.to_hash
|
||||
else
|
||||
value
|
||||
end
|
||||
end
|
||||
|
||||
end
|
@ -1,5 +1,4 @@
|
||||
require 'json'
|
||||
#
|
||||
# base class containing fundamental method such as to_hash, build_from_hash and more
|
||||
class BaseObject
|
||||
|
||||
# return the object in the form of hash
|
||||
@ -13,6 +12,7 @@ class BaseObject
|
||||
|
||||
# build the object from hash
|
||||
def build_from_hash(attributes)
|
||||
return nil unless attributes.is_a?(Hash)
|
||||
self.class.swagger_types.each_pair do |key, type|
|
||||
if type =~ /^array\[(.*)\]/i
|
||||
if attributes[self.class.attribute_map[key]].is_a?(Array)
|
||||
@ -30,7 +30,6 @@ class BaseObject
|
||||
self
|
||||
end
|
||||
|
||||
# deserialize value based on type
|
||||
def _deserialize(type, value)
|
||||
case type.to_sym
|
||||
when :DateTime
|
||||
@ -53,9 +52,7 @@ class BaseObject
|
||||
end
|
||||
end
|
||||
|
||||
#def to_json
|
||||
# self.to_hash.to_json
|
||||
#end
|
||||
|
||||
|
||||
# to_body is an alias to to_body (backward compatibility)
|
||||
def to_hash
|
||||
|
@ -42,82 +42,4 @@ class Category < BaseObject
|
||||
|
||||
end
|
||||
|
||||
# # return the object in the form of hash
|
||||
# def to_body
|
||||
# body = {}
|
||||
# self.class.attribute_map.each_pair do |key, value|
|
||||
# body[value] = self.send(key) unless self.send(key).nil?
|
||||
# end
|
||||
# body
|
||||
# end
|
||||
#
|
||||
# # build the object from hash
|
||||
# def build_from_hash(attributes)
|
||||
# self.class.swagger_types.each_pair do |key, type|
|
||||
# if type =~ /^array\[(.*)\]/i
|
||||
# if attributes[self.class.attribute_map[key]].is_a?(Array)
|
||||
# self.send("#{key}=", attributes[self.class.attribute_map[key]].map{ |v| _deserialize($1, v) } )
|
||||
# else
|
||||
# #TODO show warning in debug mode
|
||||
# end
|
||||
# elsif !attributes[self.class.attribute_map[key]].nil?
|
||||
# self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
|
||||
# else
|
||||
# # data not found in attributes(hash), not an issue as the data can be optional
|
||||
# end
|
||||
# end
|
||||
#
|
||||
# self
|
||||
# end
|
||||
#
|
||||
# def _deserialize(type, value)
|
||||
# case type
|
||||
# when :DateTime
|
||||
# DateTime.parse(value)
|
||||
# when :string
|
||||
# value.to_s
|
||||
# when :int
|
||||
# value.to_i
|
||||
# when :double
|
||||
# value.to_f
|
||||
# when :boolean
|
||||
# if value =~ /^(true|t|yes|y|1)$/i
|
||||
# true
|
||||
# else
|
||||
# false
|
||||
# end
|
||||
# else # model
|
||||
# _model = Object.const_get(type).new
|
||||
# _model.build_from_hash(value)
|
||||
# end
|
||||
# end
|
||||
#
|
||||
#
|
||||
#
|
||||
# # to_body is an alias to to_body (backward compatibility)
|
||||
# def to_hash
|
||||
# hash = {}
|
||||
# self.class.attribute_map.each_pair do |key, value|
|
||||
# if self.send(key).is_a?(Array)
|
||||
# next if self.send(key).empty?
|
||||
# hash[value] = self.send(key).select{|v| !v.nil?}.map{ |v| _to_hash v} unless self.send(key).nil?
|
||||
# else
|
||||
# unless (_tmp_value = _to_hash self.send(key)).nil?
|
||||
# hash[value] = _tmp_value
|
||||
# end
|
||||
# end
|
||||
# end
|
||||
# hash
|
||||
# end
|
||||
#
|
||||
# # Method to output non-array value in the form of hash
|
||||
# # For object, use to_hash. Otherwise, just return the value
|
||||
# def _to_hash(value)
|
||||
# if value.respond_to? :to_hash
|
||||
# value.to_hash
|
||||
# else
|
||||
# value
|
||||
# end
|
||||
# end
|
||||
|
||||
end
|
||||
|
@ -74,82 +74,4 @@ class Order < BaseObject
|
||||
|
||||
end
|
||||
|
||||
# # return the object in the form of hash
|
||||
# def to_body
|
||||
# body = {}
|
||||
# self.class.attribute_map.each_pair do |key, value|
|
||||
# body[value] = self.send(key) unless self.send(key).nil?
|
||||
# end
|
||||
# body
|
||||
# end
|
||||
#
|
||||
# # build the object from hash
|
||||
# def build_from_hash(attributes)
|
||||
# self.class.swagger_types.each_pair do |key, type|
|
||||
# if type =~ /^array\[(.*)\]/i
|
||||
# if attributes[self.class.attribute_map[key]].is_a?(Array)
|
||||
# self.send("#{key}=", attributes[self.class.attribute_map[key]].map{ |v| _deserialize($1, v) } )
|
||||
# else
|
||||
# #TODO show warning in debug mode
|
||||
# end
|
||||
# elsif !attributes[self.class.attribute_map[key]].nil?
|
||||
# self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
|
||||
# else
|
||||
# # data not found in attributes(hash), not an issue as the data can be optional
|
||||
# end
|
||||
# end
|
||||
#
|
||||
# self
|
||||
# end
|
||||
#
|
||||
# def _deserialize(type, value)
|
||||
# case type
|
||||
# when :DateTime
|
||||
# DateTime.parse(value)
|
||||
# when :string
|
||||
# value.to_s
|
||||
# when :int
|
||||
# value.to_i
|
||||
# when :double
|
||||
# value.to_f
|
||||
# when :boolean
|
||||
# if value =~ /^(true|t|yes|y|1)$/i
|
||||
# true
|
||||
# else
|
||||
# false
|
||||
# end
|
||||
# else # model
|
||||
# _model = Object.const_get(type).new
|
||||
# _model.build_from_hash(value)
|
||||
# end
|
||||
# end
|
||||
#
|
||||
#
|
||||
#
|
||||
# # to_body is an alias to to_body (backward compatibility)
|
||||
# def to_hash
|
||||
# hash = {}
|
||||
# self.class.attribute_map.each_pair do |key, value|
|
||||
# if self.send(key).is_a?(Array)
|
||||
# next if self.send(key).empty?
|
||||
# hash[value] = self.send(key).select{|v| !v.nil?}.map{ |v| _to_hash v} unless self.send(key).nil?
|
||||
# else
|
||||
# unless (_tmp_value = _to_hash self.send(key)).nil?
|
||||
# hash[value] = _tmp_value
|
||||
# end
|
||||
# end
|
||||
# end
|
||||
# hash
|
||||
# end
|
||||
#
|
||||
# # Method to output non-array value in the form of hash
|
||||
# # For object, use to_hash. Otherwise, just return the value
|
||||
# def _to_hash(value)
|
||||
# if value.respond_to? :to_hash
|
||||
# value.to_hash
|
||||
# else
|
||||
# value
|
||||
# end
|
||||
# end
|
||||
|
||||
end
|
||||
|
@ -78,82 +78,4 @@ class Pet < BaseObject
|
||||
|
||||
end
|
||||
|
||||
# # return the object in the form of hash
|
||||
# def to_body
|
||||
# body = {}
|
||||
# self.class.attribute_map.each_pair do |key, value|
|
||||
# body[value] = self.send(key) unless self.send(key).nil?
|
||||
# end
|
||||
# body
|
||||
# end
|
||||
#
|
||||
# # build the object from hash
|
||||
# def build_from_hash(attributes)
|
||||
# self.class.swagger_types.each_pair do |key, type|
|
||||
# if type =~ /^array\[(.*)\]/i
|
||||
# if attributes[self.class.attribute_map[key]].is_a?(Array)
|
||||
# self.send("#{key}=", attributes[self.class.attribute_map[key]].map{ |v| _deserialize($1, v) } )
|
||||
# else
|
||||
# #TODO show warning in debug mode
|
||||
# end
|
||||
# elsif !attributes[self.class.attribute_map[key]].nil?
|
||||
# self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
|
||||
# else
|
||||
# # data not found in attributes(hash), not an issue as the data can be optional
|
||||
# end
|
||||
# end
|
||||
#
|
||||
# self
|
||||
# end
|
||||
#
|
||||
# def _deserialize(type, value)
|
||||
# case type
|
||||
# when :DateTime
|
||||
# DateTime.parse(value)
|
||||
# when :string
|
||||
# value.to_s
|
||||
# when :int
|
||||
# value.to_i
|
||||
# when :double
|
||||
# value.to_f
|
||||
# when :boolean
|
||||
# if value =~ /^(true|t|yes|y|1)$/i
|
||||
# true
|
||||
# else
|
||||
# false
|
||||
# end
|
||||
# else # model
|
||||
# _model = Object.const_get(type).new
|
||||
# _model.build_from_hash(value)
|
||||
# end
|
||||
# end
|
||||
#
|
||||
#
|
||||
#
|
||||
# # to_body is an alias to to_body (backward compatibility)
|
||||
# def to_hash
|
||||
# hash = {}
|
||||
# self.class.attribute_map.each_pair do |key, value|
|
||||
# if self.send(key).is_a?(Array)
|
||||
# next if self.send(key).empty?
|
||||
# hash[value] = self.send(key).select{|v| !v.nil?}.map{ |v| _to_hash v} unless self.send(key).nil?
|
||||
# else
|
||||
# unless (_tmp_value = _to_hash self.send(key)).nil?
|
||||
# hash[value] = _tmp_value
|
||||
# end
|
||||
# end
|
||||
# end
|
||||
# hash
|
||||
# end
|
||||
#
|
||||
# # Method to output non-array value in the form of hash
|
||||
# # For object, use to_hash. Otherwise, just return the value
|
||||
# def _to_hash(value)
|
||||
# if value.respond_to? :to_hash
|
||||
# value.to_hash
|
||||
# else
|
||||
# value
|
||||
# end
|
||||
# end
|
||||
|
||||
end
|
||||
|
@ -42,82 +42,4 @@ class Tag < BaseObject
|
||||
|
||||
end
|
||||
|
||||
# # return the object in the form of hash
|
||||
# def to_body
|
||||
# body = {}
|
||||
# self.class.attribute_map.each_pair do |key, value|
|
||||
# body[value] = self.send(key) unless self.send(key).nil?
|
||||
# end
|
||||
# body
|
||||
# end
|
||||
#
|
||||
# # build the object from hash
|
||||
# def build_from_hash(attributes)
|
||||
# self.class.swagger_types.each_pair do |key, type|
|
||||
# if type =~ /^array\[(.*)\]/i
|
||||
# if attributes[self.class.attribute_map[key]].is_a?(Array)
|
||||
# self.send("#{key}=", attributes[self.class.attribute_map[key]].map{ |v| _deserialize($1, v) } )
|
||||
# else
|
||||
# #TODO show warning in debug mode
|
||||
# end
|
||||
# elsif !attributes[self.class.attribute_map[key]].nil?
|
||||
# self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
|
||||
# else
|
||||
# # data not found in attributes(hash), not an issue as the data can be optional
|
||||
# end
|
||||
# end
|
||||
#
|
||||
# self
|
||||
# end
|
||||
#
|
||||
# def _deserialize(type, value)
|
||||
# case type
|
||||
# when :DateTime
|
||||
# DateTime.parse(value)
|
||||
# when :string
|
||||
# value.to_s
|
||||
# when :int
|
||||
# value.to_i
|
||||
# when :double
|
||||
# value.to_f
|
||||
# when :boolean
|
||||
# if value =~ /^(true|t|yes|y|1)$/i
|
||||
# true
|
||||
# else
|
||||
# false
|
||||
# end
|
||||
# else # model
|
||||
# _model = Object.const_get(type).new
|
||||
# _model.build_from_hash(value)
|
||||
# end
|
||||
# end
|
||||
#
|
||||
#
|
||||
#
|
||||
# # to_body is an alias to to_body (backward compatibility)
|
||||
# def to_hash
|
||||
# hash = {}
|
||||
# self.class.attribute_map.each_pair do |key, value|
|
||||
# if self.send(key).is_a?(Array)
|
||||
# next if self.send(key).empty?
|
||||
# hash[value] = self.send(key).select{|v| !v.nil?}.map{ |v| _to_hash v} unless self.send(key).nil?
|
||||
# else
|
||||
# unless (_tmp_value = _to_hash self.send(key)).nil?
|
||||
# hash[value] = _tmp_value
|
||||
# end
|
||||
# end
|
||||
# end
|
||||
# hash
|
||||
# end
|
||||
#
|
||||
# # Method to output non-array value in the form of hash
|
||||
# # For object, use to_hash. Otherwise, just return the value
|
||||
# def _to_hash(value)
|
||||
# if value.respond_to? :to_hash
|
||||
# value.to_hash
|
||||
# else
|
||||
# value
|
||||
# end
|
||||
# end
|
||||
|
||||
end
|
||||
|
@ -90,82 +90,4 @@ class User < BaseObject
|
||||
|
||||
end
|
||||
|
||||
# # return the object in the form of hash
|
||||
# def to_body
|
||||
# body = {}
|
||||
# self.class.attribute_map.each_pair do |key, value|
|
||||
# body[value] = self.send(key) unless self.send(key).nil?
|
||||
# end
|
||||
# body
|
||||
# end
|
||||
#
|
||||
# # build the object from hash
|
||||
# def build_from_hash(attributes)
|
||||
# self.class.swagger_types.each_pair do |key, type|
|
||||
# if type =~ /^array\[(.*)\]/i
|
||||
# if attributes[self.class.attribute_map[key]].is_a?(Array)
|
||||
# self.send("#{key}=", attributes[self.class.attribute_map[key]].map{ |v| _deserialize($1, v) } )
|
||||
# else
|
||||
# #TODO show warning in debug mode
|
||||
# end
|
||||
# elsif !attributes[self.class.attribute_map[key]].nil?
|
||||
# self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
|
||||
# else
|
||||
# # data not found in attributes(hash), not an issue as the data can be optional
|
||||
# end
|
||||
# end
|
||||
#
|
||||
# self
|
||||
# end
|
||||
#
|
||||
# def _deserialize(type, value)
|
||||
# case type
|
||||
# when :DateTime
|
||||
# DateTime.parse(value)
|
||||
# when :string
|
||||
# value.to_s
|
||||
# when :int
|
||||
# value.to_i
|
||||
# when :double
|
||||
# value.to_f
|
||||
# when :boolean
|
||||
# if value =~ /^(true|t|yes|y|1)$/i
|
||||
# true
|
||||
# else
|
||||
# false
|
||||
# end
|
||||
# else # model
|
||||
# _model = Object.const_get(type).new
|
||||
# _model.build_from_hash(value)
|
||||
# end
|
||||
# end
|
||||
#
|
||||
#
|
||||
#
|
||||
# # to_body is an alias to to_body (backward compatibility)
|
||||
# def to_hash
|
||||
# hash = {}
|
||||
# self.class.attribute_map.each_pair do |key, value|
|
||||
# if self.send(key).is_a?(Array)
|
||||
# next if self.send(key).empty?
|
||||
# hash[value] = self.send(key).select{|v| !v.nil?}.map{ |v| _to_hash v} unless self.send(key).nil?
|
||||
# else
|
||||
# unless (_tmp_value = _to_hash self.send(key)).nil?
|
||||
# hash[value] = _tmp_value
|
||||
# end
|
||||
# end
|
||||
# end
|
||||
# hash
|
||||
# end
|
||||
#
|
||||
# # Method to output non-array value in the form of hash
|
||||
# # For object, use to_hash. Otherwise, just return the value
|
||||
# def _to_hash(value)
|
||||
# if value.respond_to? :to_hash
|
||||
# value.to_hash
|
||||
# else
|
||||
# value
|
||||
# end
|
||||
# end
|
||||
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user