Regard bare "object" type as Object, add comments

The handling of base "object" type (without definions of
"additionalProperties") is similar to Java generator now.
This commit is contained in:
xhh 2015-06-15 12:49:17 +08:00
parent 80616b4c2b
commit e9c1dd7842
3 changed files with 35 additions and 21 deletions

View File

@ -62,7 +62,7 @@ public class RubyClientCodegen extends DefaultCodegen implements CodegenConfig {
typeMapping.put("array", "Array"); typeMapping.put("array", "Array");
typeMapping.put("List", "Array"); typeMapping.put("List", "Array");
typeMapping.put("map", "Hash"); typeMapping.put("map", "Hash");
typeMapping.put("object", "Hash"); typeMapping.put("object", "Object");
String baseFolder = "lib" + File.separatorChar + gemName; String baseFolder = "lib" + File.separatorChar + gemName;
String swaggerFolder = baseFolder + File.separatorChar + "swagger"; String swaggerFolder = baseFolder + File.separatorChar + "swagger";

View File

@ -49,24 +49,31 @@ module {{moduleName}}
build_models data, return_type build_models data, return_type
end end
# Build model(s) from Hash data for array/hash values of the response. # Walk through the given data and, when necessary, build model(s) from
# Hash data for array/hash values of the response.
def build_models(data, return_type) def build_models(data, return_type)
case return_type case return_type
when /\AArray<(.+)>\z/
sub_type = $1
data.map {|item| build_models(item, sub_type) }
when /\AHash\<String, (.+)\>\z/
sub_type = $1
{}.tap do |hash|
data.each {|k, v| hash[k] = build_models(v, sub_type) }
end
when 'String', 'Integer', 'Float', 'BOOLEAN' when 'String', 'Integer', 'Float', 'BOOLEAN'
# primitives, return directly # primitives, return directly
data data
when 'DateTime' when 'DateTime'
# parse date time (expecting ISO 8601 format)
DateTime.parse data DateTime.parse data
when 'Object'
# generic object, return directly
data
when /\AArray<(.+)>\z/
# e.g. Array<Pet>
sub_type = $1
data.map {|item| build_models(item, sub_type) }
when /\AHash\<String, (.+)\>\z/
# e.g. Hash<String, Integer>
sub_type = $1
{}.tap do |hash|
data.each {|k, v| hash[k] = build_models(v, sub_type) }
end
else else
# models # models, e.g. Pet
{{moduleName}}.const_get(return_type).new.tap do |model| {{moduleName}}.const_get(return_type).new.tap do |model|
model.build_from_hash data model.build_from_hash data
end end

View File

@ -49,24 +49,31 @@ module SwaggerClient
build_models data, return_type build_models data, return_type
end end
# Build model(s) from Hash data for array/hash values of the response. # Walk through the given data and, when necessary, build model(s) from
# Hash data for array/hash values of the response.
def build_models(data, return_type) def build_models(data, return_type)
case return_type case return_type
when /\AArray<(.+)>\z/
sub_type = $1
data.map {|item| build_models(item, sub_type) }
when /\AHash\<String, (.+)\>\z/
sub_type = $1
{}.tap do |hash|
data.each {|k, v| hash[k] = build_models(v, sub_type) }
end
when 'String', 'Integer', 'Float', 'BOOLEAN' when 'String', 'Integer', 'Float', 'BOOLEAN'
# primitives, return directly # primitives, return directly
data data
when 'DateTime' when 'DateTime'
# parse date time (expecting ISO 8601 format)
DateTime.parse data DateTime.parse data
when 'Object'
# generic object, return directly
data
when /\AArray<(.+)>\z/
# e.g. Array<Pet>
sub_type = $1
data.map {|item| build_models(item, sub_type) }
when /\AHash\<String, (.+)\>\z/
# e.g. Hash<String, Integer>
sub_type = $1
{}.tap do |hash|
data.each {|k, v| hash[k] = build_models(v, sub_type) }
end
else else
# models # models, e.g. Pet
SwaggerClient.const_get(return_type).new.tap do |model| SwaggerClient.const_get(return_type).new.tap do |model|
model.build_from_hash data model.build_from_hash data
end end