Add #is_primitive? and #generate_typeref

This commit is contained in:
Craig S. Cottingham 2014-05-28 15:09:06 -05:00
parent d205202ddc
commit 2f35d85bb8
1 changed files with 15 additions and 1 deletions

View File

@ -322,8 +322,10 @@ module Grape
end
if p.delete(:is_array)
p[:items] = {"$ref" => p[:type]}
p[:items] = generate_typeref(p[:type])
p[:type] = "array"
else
p.merge! generate_typeref(p.delete(:type))
end
# rename Grape Entity's "desc" to "description"
@ -344,6 +346,18 @@ module Grape
result
end
def is_primitive?(type)
%w(integer long float double string byte boolean date dateTime).include? type
end
def generate_typeref(type)
if is_primitive? type
{ "type" => type }
else
{ "$ref" => type }
end
end
def parse_http_codes codes
codes ||= {}
codes.map do |k, v|