lib/grape-swagger/endpoint.rb in grape-swagger-0.22.0 vs lib/grape-swagger/endpoint.rb in grape-swagger-0.23.0
- old
+ new
@@ -166,15 +166,13 @@
parameters
end
def response_object(route, markdown)
- 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)
+ codes = (route.http_codes || route.options[:failure] || [])
+ codes = apply_defaults(route, codes) if route.options[:ignore_defaults].nil?
- codes = [default_code] + (route.http_codes || route.options[:failure] || [])
codes.map! { |x| x.is_a?(Array) ? { code: x[0], message: x[1], model: x[2] } : x }
codes.each_with_object({}) do |value, memo|
memo[value[:code]] = { description: value[:message] }
@@ -198,10 +196,17 @@
{ '$ref' => "#/definitions/#{response_model}" }
end
end
end
+ def apply_defaults(route, codes)
+ 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)
+ [default_code] + codes
+ end
+
def tag_object(route)
Array(route.path.split('{')[0].split('/').reject(&:empty?).delete_if { |i| ((i == route.prefix.to_s) || (i == route.version)) }.first)
end
private
@@ -229,12 +234,14 @@
def parse_request_params(params)
array_key = nil
params.select { |param| public_parameter?(param) }.each_with_object({}) do |param, memo|
name, options = *param
- array_key = name.to_s if param_type_is_array?(options[:type])
+ param_type = options[:type]
+ param_type = param_type.to_s unless param_type.nil?
+ array_key = name.to_s if param_type_is_array?(param_type)
options[:is_array] = true if array_key && name.start_with?(array_key)
- memo[param.first] = options unless (options[:type] == 'Hash' || options[:type] == 'Array') && !options.key?(:documentation)
+ memo[name] = options unless %w(Hash Array).include?(param_type) && !options.key?(:documentation)
end
end
def param_type_is_array?(param_type)
return false unless param_type