lib/grape-swagger/endpoint.rb in grape-swagger-0.25.2 vs lib/grape-swagger/endpoint.rb in grape-swagger-0.25.3

- old
+ new

@@ -7,11 +7,13 @@ 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? - content_types = Grape::ContentTypes::CONTENT_TYPES.select { |content_type, _mime_type| formats.include? content_type }.values + content_types = Grape::ContentTypes::CONTENT_TYPES.select do |content_type, _mime_type| + formats.include? content_type + end.values end content_types.uniq end @@ -149,11 +151,13 @@ route_mime_types.present? ? route_mime_types : mime_types end def consumes_object(route, format) method = route.request_method.downcase.to_sym - format = route.settings[:description][:consumes] if route.settings[:description] && route.settings[:description][:consumes] + if route.settings[:description] && route.settings[:description][:consumes] + format = route.settings[:description][:consumes] + end mime_types = GrapeSwagger::DocMethods::ProducesConsumes.call(format) if [:post, :put].include?(method) mime_types end @@ -197,14 +201,15 @@ next unless !response_model.start_with?('Swagger_doc') && ((@definitions[response_model] && value[:code].to_s.start_with?('2')) || value[:model]) @definitions[response_model][:description] = description_object(route, markdown) # 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] - { 'type' => 'array', 'items' => { '$ref' => "#/definitions/#{response_model}" } } + { 'type' => 'array', 'items' => reference } else - { '$ref' => "#/definitions/#{response_model}" } + reference end end end def apply_success_codes(route) @@ -221,11 +226,15 @@ [default_code] 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) + Array( + route.path.split('{')[0].split('/').reject(&:empty?).delete_if do |i| + i == route.prefix.to_s || i == route.version + end.first + ) end private def partition_params(route) @@ -238,11 +247,13 @@ request_params = unless declared_params.nil? && route.headers.nil? parse_request_params(required) end || {} - request_params = route.params.merge(request_params) if route.params.present? && !route.settings[:declared_params].present? + if route.params.present? && !route.settings[:declared_params].present? + request_params = route.params.merge(request_params) + end request_params end def default_type(params) @@ -293,10 +304,13 @@ parser = GrapeSwagger.model_parsers.find(model) raise GrapeSwagger::Errors::UnregisteredParser, "No parser registered for #{model_name}." unless parser properties = parser.new(model, self).call - raise GrapeSwagger::Errors::SwaggerSpec, "Empty model #{model_name}, swagger 2.0 doesn't support empty definitions." unless properties && properties.any? + unless properties && properties.any? + raise GrapeSwagger::Errors::SwaggerSpec, + "Empty model #{model_name}, swagger 2.0 doesn't support empty definitions." + end @definitions[model_name] = GrapeSwagger::DocMethods::BuildModelDefinition.build(model, properties) model_name end