lib/grape-swagger/endpoint.rb in grape-swagger-0.29.0 vs lib/grape-swagger/endpoint.rb in grape-swagger-0.30.0
- old
+ new
@@ -193,11 +193,11 @@
parameters
end
def response_object(route)
codes = http_codes_from_route(route)
- codes.map! { |x| x.is_a?(Array) ? { code: x[0], message: x[1], model: x[2], examples: x[3] } : x }
+ codes.map! { |x| x.is_a?(Array) ? { code: x[0], message: x[1], model: x[2], examples: x[3], headers: x[4] } : x }
codes.each_with_object({}) do |value, memo|
value[:message] ||= ''
memo[value[:code]] = { description: value[:message] }
next build_file_response(memo[value[:code]]) if file_response?(value[:model])
@@ -208,17 +208,18 @@
if memo.key?(200) && route.request_method == 'DELETE' && value[:model].nil?
memo[204] = memo.delete(200)
value[:code] = 204
end
- next if memo.key?(204)
+ next if value[:code] == 204
next unless !response_model.start_with?('Swagger_doc') && (@definitions[response_model] || value[:model])
@definitions[response_model][:description] = description_object(route)
memo[value[:code]][:schema] = build_reference(route, value, response_model)
memo[value[:code]][:examples] = value[:examples] if value[:examples]
+ memo[value[:code]][:headers] = value[:headers] if value[:headers]
end
end
def success_code?(code)
status = code.is_a?(Array) ? code.first : code[:code]
@@ -238,9 +239,10 @@
if @entity.is_a?(Hash)
default_code[:code] = @entity[:code] if @entity[:code].present?
default_code[:model] = @entity[:model] if @entity[:model].present?
default_code[:message] = @entity[:message] || route.description || default_code[:message].sub('{item}', @item)
default_code[:examples] = @entity[:examples] if @entity[:examples]
+ default_code[:headers] = @entity[:headers] if @entity[:headers]
else
default_code = GrapeSwagger::DocMethods::StatusCodes.get[route.request_method.downcase.to_sym]
default_code[:model] = @entity if @entity
default_code[:message] = route.description || default_code[:message].sub('{item}', @item)
end