Skip to content

Commit 2f35d85

Browse files
author
Craig S. Cottingham
committed
Add #is_primitive? and #generate_typeref
1 parent d205202 commit 2f35d85

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

lib/grape-swagger.rb

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,8 +322,10 @@ def parse_entity_models(models)
322322
end
323323

324324
if p.delete(:is_array)
325-
p[:items] = {"$ref" => p[:type]}
325+
p[:items] = generate_typeref(p[:type])
326326
p[:type] = "array"
327+
else
328+
p.merge! generate_typeref(p.delete(:type))
327329
end
328330

329331
# rename Grape Entity's "desc" to "description"
@@ -344,6 +346,18 @@ def parse_entity_models(models)
344346
result
345347
end
346348

349+
def is_primitive?(type)
350+
%w(integer long float double string byte boolean date dateTime).include? type
351+
end
352+
353+
def generate_typeref(type)
354+
if is_primitive? type
355+
{ "type" => type }
356+
else
357+
{ "$ref" => type }
358+
end
359+
end
360+
347361
def parse_http_codes codes
348362
codes ||= {}
349363
codes.map do |k, v|

0 commit comments

Comments
 (0)