Files
openapi-generator/modules/swagger-codegen/src/main/resources/ruby/model.mustache
2015-06-09 12:33:30 +08:00

41 lines
1.1 KiB
Plaintext

module {{moduleName}}
{{#models}} # {{description}}
{{#model}} class {{classname}} < BaseObject
attr_accessor {{#vars}}:{{{name}}}{{#hasMore}}, {{/hasMore}}{{/vars}}{{newline}}
# attribute mapping from ruby-style variable name to JSON key
def self.attribute_map
{
{{#vars}}
# {{description}}
:'{{{name}}}' => :'{{{baseName}}}'{{#hasMore}},{{/hasMore}}
{{/vars}}
}
end
# attribute type
def self.swagger_types
{
{{#vars}}:'{{{name}}}' => :'{{{datatype}}}'{{#hasMore}},{{/hasMore}}
{{/vars}}
}
end
def initialize(attributes = {})
return if !attributes.is_a?(Hash) || attributes.empty?
# convert string to symbol for hash key
attributes = attributes.inject({}){|memo,(k,v)| memo[k.to_sym] = v; memo}
{{#vars}}
if attributes[:'{{{baseName}}}']
{{#isContainer}}if (value = attributes[:'{{{baseName}}}']).is_a?(Array)
@{{{name}}} = value
end{{/isContainer}}{{^isContainer}}@{{{name}}} = attributes[:'{{{baseName}}}']{{/isContainer}}
end
{{/vars}}
end
end
{{/model}}
{{/models}}
end