lib/grape-swagger/endpoint.rb in grape-swagger-0.26.0 vs lib/grape-swagger/endpoint.rb in grape-swagger-0.26.1
- old
+ new
@@ -6,11 +6,11 @@
def content_types_for(target_class)
content_types = (target_class.content_types || {}).values
if content_types.empty?
formats = [target_class.format, target_class.default_format].compact.uniq
- formats = Grape::Formatter::Base.formatters({}).keys if formats.empty?
+ formats = Grape::Formatter.formatters({}).keys if formats.empty?
content_types = Grape::ContentTypes::CONTENT_TYPES.select do |content_type, _mime_type|
formats.include? content_type
end.values
end
@@ -103,16 +103,16 @@
end
def method_object(route, options, path)
method = {}
method[:summary] = summary_object(route)
- method[:description] = description_object(route, options[:markdown])
+ method[:description] = description_object(route)
method[:produces] = produces_object(route, options[:produces] || options[:format])
method[:consumes] = consumes_object(route, options[:format])
method[:parameters] = params_object(route)
method[:security] = security_object(route)
- method[:responses] = response_object(route, options[:markdown])
+ method[:responses] = response_object(route)
method[:tags] = route.options.fetch(:tags, tag_object(route))
method[:operationId] = GrapeSwagger::DocMethods::OperationId.build(route, path)
method.delete_if { |_, value| value.blank? }
[route.request_method.downcase.to_sym, method]
@@ -128,14 +128,13 @@
summary = route.options[:summary] if route.options.key?(:summary)
summary
end
- def description_object(route, markdown)
+ def description_object(route)
description = route.description if route.description.present?
description = route.options[:detail] if route.options.key?(:detail)
- description = markdown.markdown(description.to_s).chomp if markdown
description
end
def produces_object(route, format)
@@ -176,11 +175,11 @@
end
parameters
end
- def response_object(route, markdown)
+ def response_object(route)
codes = (route.http_codes || route.options[:failure] || [])
codes = apply_success_codes(route) + codes
codes.map! { |x| x.is_a?(Array) ? { code: x[0], message: x[1], model: x[2] } : x }
@@ -194,16 +193,15 @@
memo[204] = memo.delete(200)
value[:code] = 204
end
next if memo.key?(204)
- next unless !response_model.start_with?('Swagger_doc') &&
- ((@definitions[response_model] && value[:code].to_s.start_with?('2')) || value[:model])
+ next unless !response_model.start_with?('Swagger_doc') && (@definitions[response_model] || value[:model])
- @definitions[response_model][:description] = description_object(route, markdown)
+ @definitions[response_model][:description] = description_object(route)
# TODO: proof that the definition exist, if model isn't specified
reference = { '$ref' => "#/definitions/#{response_model}" }
- memo[value[:code]][:schema] = if route.options[:is_array]
+ memo[value[:code]][:schema] = if route.options[:is_array] && value[:code] < 300
{ 'type' => 'array', 'items' => reference }
else
reference
end
end