Skip to content

Commit 4ee22a7

Browse files
committed
refactor: extract schema building method from build_response_for_type_parameter
1 parent 232baa5 commit 4ee22a7

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

lib/grape-swagger/endpoint.rb

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -311,15 +311,24 @@ def build_memo_schema(memo, route, value, response_model, options)
311311
end
312312

313313
def build_response_for_type_parameter(memo, _route, value, _options)
314-
type, format = prepare_type_and_format(value)
314+
schema = build_response_schema(value)
315315

316316
if memo[value[:code]].include?(:schema) && value.include?(:as)
317-
memo[value[:code]][:schema][:properties].merge!(value[:as] => { type: type, format: format }.compact)
317+
memo[value[:code]][:schema][:properties].merge!(schema)
318318
elsif value.include?(:as)
319-
memo[value[:code]][:schema] =
320-
{ type: :object, properties: { value[:as] => { type: type, format: format }.compact } }
319+
memo[value[:code]][:schema] = { type: :object, properties: schema }
320+
else
321+
memo[value[:code]][:schema] = schema
322+
end
323+
end
324+
325+
def build_response_schema(value)
326+
type, format = prepare_type_and_format(value)
327+
328+
if value.include?(:as)
329+
return { value[:as] => { type: type, format: format }.compact }
321330
else
322-
memo[value[:code]][:schema] = { type: type }
331+
return { type: type }
323332
end
324333
end
325334

0 commit comments

Comments
 (0)