diff --git a/.rubocop.yml b/.rubocop.yml index 400c57f1..45cc3b9a 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,6 +1,7 @@ require: - rubocop-rails - rubocop-rspec + - rubocop-rspec_rails - rubocop-performance inherit_from: .rubocop_todo.yml diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 2c860cb9..a38dfd2e 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1159,7 +1159,7 @@ RSpec/PredicateMatcher: # Offense count: 1 # This cop supports unsafe autocorrection (--autocorrect-all). # Configuration parameters: Inferences. -RSpec/Rails/InferredSpecType: +RSpecRails/InferredSpecType: Exclude: - 'spec/controllers/pets_controller_spec.rb' diff --git a/apipie-rails.gemspec b/apipie-rails.gemspec index cf6ccb07..6063dc63 100644 --- a/apipie-rails.gemspec +++ b/apipie-rails.gemspec @@ -38,6 +38,7 @@ Gem::Specification.new do |s| s.add_development_dependency 'rubocop-rails' s.add_development_dependency 'rubocop-rspec' s.add_development_dependency 'rubocop-performance' + s.add_development_dependency 'rubocop-rspec_rails' if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("2.7") s.add_development_dependency "simplecov" s.add_development_dependency "sqlite3" end diff --git a/lib/apipie/error_description.rb b/lib/apipie/error_description.rb index 4be24cd8..62626e9c 100644 --- a/lib/apipie/error_description.rb +++ b/lib/apipie/error_description.rb @@ -17,9 +17,13 @@ def initialize(code_or_options, desc = nil, options = {}) @metadata = code_or_options[:meta] @description = code_or_options[:desc] || code_or_options[:description] else - @code = + @code = if code_or_options.is_a? Symbol - Rack::Utils::SYMBOL_TO_STATUS_CODE[code_or_options] + begin + Rack::Utils.status_code(code_or_options) + rescue ArgumentError + nil + end else code_or_options end diff --git a/lib/apipie/extractor/recorder.rb b/lib/apipie/extractor/recorder.rb index aaedb9cb..55d3bb99 100644 --- a/lib/apipie/extractor/recorder.rb +++ b/lib/apipie/extractor/recorder.rb @@ -14,12 +14,12 @@ def analyse_env(env) @params = Rack::Utils.parse_nested_query(@query) @params.merge!(env["action_dispatch.request.request_parameters"] || {}) rack_input = env["rack.input"] - if data = parse_data(rack_input.read) + if data = parse_data(rack_input&.read) @request_data = data elsif form_hash = env["rack.request.form_hash"] @request_data = reformat_multipart_data(form_hash) end - rack_input.rewind + rack_input&.rewind end def analyse_controller(controller) diff --git a/lib/apipie/response_description.rb b/lib/apipie/response_description.rb index fd226bfd..d98eb5d4 100644 --- a/lib/apipie/response_description.rb +++ b/lib/apipie/response_description.rb @@ -88,11 +88,16 @@ def initialize(method_description, code, options, scope, block, adapter) @method_description = method_description - if code.is_a? Symbol - @code = Rack::Utils::SYMBOL_TO_STATUS_CODE[code] - else - @code = code - end + @code = + if code.is_a? Symbol + begin + Rack::Utils.status_code(code) + rescue ArgumentError + nil + end + else + code + end @description = options[:desc] if @description.nil? diff --git a/spec/lib/swagger/swagger_dsl_spec.rb b/spec/lib/swagger/swagger_dsl_spec.rb index e234a841..6e6fd45c 100644 --- a/spec/lib/swagger/swagger_dsl_spec.rb +++ b/spec/lib/swagger/swagger_dsl_spec.rb @@ -283,7 +283,7 @@ def have_field?(field, expected_name, breadcrumb) expect(schema).to have_field(:pet_id, 'number', {:description => 'id of pet'}) expect(schema).to have_field(:pet_name, 'string', {:description => 'Name of pet', :required => false}) expect(schema).to have_field(:animal_type, 'string', {:description => 'Type of pet', :enum => %w[dog cat iguana kangaroo]}) - expect(schema).not_to have_field(:partial_match_allowed, 'boolean', {:required => false}) # rubocop:disable Capybara/NegationMatcher + expect(schema).not_to have_field(:partial_match_allowed, 'boolean', {:required => false}) end it "creates a swagger definition with all input parameters" do