forked from loafle/openapi-generator-original
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:
parent
80616b4c2b
commit
e9c1dd7842
@ -62,7 +62,7 @@ public class RubyClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
typeMapping.put("array", "Array");
|
||||
typeMapping.put("List", "Array");
|
||||
typeMapping.put("map", "Hash");
|
||||
typeMapping.put("object", "Hash");
|
||||
typeMapping.put("object", "Object");
|
||||
|
||||
String baseFolder = "lib" + File.separatorChar + gemName;
|
||||
String swaggerFolder = baseFolder + File.separatorChar + "swagger";
|
||||
|
@ -49,24 +49,31 @@ module {{moduleName}}
|
||||
build_models data, return_type
|
||||
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)
|
||||
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'
|
||||
# primitives, return directly
|
||||
data
|
||||
when 'DateTime'
|
||||
# parse date time (expecting ISO 8601 format)
|
||||
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
|
||||
# models
|
||||
# models, e.g. Pet
|
||||
{{moduleName}}.const_get(return_type).new.tap do |model|
|
||||
model.build_from_hash data
|
||||
end
|
||||
|
@ -49,24 +49,31 @@ module SwaggerClient
|
||||
build_models data, return_type
|
||||
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)
|
||||
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'
|
||||
# primitives, return directly
|
||||
data
|
||||
when 'DateTime'
|
||||
# parse date time (expecting ISO 8601 format)
|
||||
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
|
||||
# models
|
||||
# models, e.g. Pet
|
||||
SwaggerClient.const_get(return_type).new.tap do |model|
|
||||
model.build_from_hash data
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user