Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

## 3.2.1

- Don't raise `UnknownQueryParameterError` if request is ignored in tests. Fixes [#441](https://github.com/ahx/openapi_first/issues/441).

## 3.2.0

### Changed
Expand Down
110 changes: 55 additions & 55 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
openapi_first (3.2.0)
openapi_first (3.2.1)
drb (~> 2.0)
hana (~> 1.3)
json_schemer (>= 2.1, < 3.0)
Expand All @@ -13,66 +13,66 @@ GEM
specs:
action_text-trix (2.1.16)
railties
actioncable (8.1.1)
actionpack (= 8.1.1)
activesupport (= 8.1.1)
actioncable (8.1.2)
actionpack (= 8.1.2)
activesupport (= 8.1.2)
nio4r (~> 2.0)
websocket-driver (>= 0.6.1)
zeitwerk (~> 2.6)
actionmailbox (8.1.1)
actionpack (= 8.1.1)
activejob (= 8.1.1)
activerecord (= 8.1.1)
activestorage (= 8.1.1)
activesupport (= 8.1.1)
actionmailbox (8.1.2)
actionpack (= 8.1.2)
activejob (= 8.1.2)
activerecord (= 8.1.2)
activestorage (= 8.1.2)
activesupport (= 8.1.2)
mail (>= 2.8.0)
actionmailer (8.1.1)
actionpack (= 8.1.1)
actionview (= 8.1.1)
activejob (= 8.1.1)
activesupport (= 8.1.1)
actionmailer (8.1.2)
actionpack (= 8.1.2)
actionview (= 8.1.2)
activejob (= 8.1.2)
activesupport (= 8.1.2)
mail (>= 2.8.0)
rails-dom-testing (~> 2.2)
actionpack (8.1.1)
actionview (= 8.1.1)
activesupport (= 8.1.1)
actionpack (8.1.2)
actionview (= 8.1.2)
activesupport (= 8.1.2)
nokogiri (>= 1.8.5)
rack (>= 2.2.4)
rack-session (>= 1.0.1)
rack-test (>= 0.6.3)
rails-dom-testing (~> 2.2)
rails-html-sanitizer (~> 1.6)
useragent (~> 0.16)
actiontext (8.1.1)
actiontext (8.1.2)
action_text-trix (~> 2.1.15)
actionpack (= 8.1.1)
activerecord (= 8.1.1)
activestorage (= 8.1.1)
activesupport (= 8.1.1)
actionpack (= 8.1.2)
activerecord (= 8.1.2)
activestorage (= 8.1.2)
activesupport (= 8.1.2)
globalid (>= 0.6.0)
nokogiri (>= 1.8.5)
actionview (8.1.1)
activesupport (= 8.1.1)
actionview (8.1.2)
activesupport (= 8.1.2)
builder (~> 3.1)
erubi (~> 1.11)
rails-dom-testing (~> 2.2)
rails-html-sanitizer (~> 1.6)
activejob (8.1.1)
activesupport (= 8.1.1)
activejob (8.1.2)
activesupport (= 8.1.2)
globalid (>= 0.3.6)
activemodel (8.1.1)
activesupport (= 8.1.1)
activerecord (8.1.1)
activemodel (= 8.1.1)
activesupport (= 8.1.1)
activemodel (8.1.2)
activesupport (= 8.1.2)
activerecord (8.1.2)
activemodel (= 8.1.2)
activesupport (= 8.1.2)
timeout (>= 0.4.0)
activestorage (8.1.1)
actionpack (= 8.1.1)
activejob (= 8.1.1)
activerecord (= 8.1.1)
activesupport (= 8.1.1)
activestorage (8.1.2)
actionpack (= 8.1.2)
activejob (= 8.1.2)
activerecord (= 8.1.2)
activesupport (= 8.1.2)
marcel (~> 1.0)
activesupport (8.1.1)
activesupport (8.1.2)
base64
bigdecimal
concurrent-ruby (~> 1.0, >= 1.3.1)
Expand Down Expand Up @@ -185,30 +185,30 @@ GEM
rack (>= 1.3)
rackup (2.3.1)
rack (>= 3)
rails (8.1.1)
actioncable (= 8.1.1)
actionmailbox (= 8.1.1)
actionmailer (= 8.1.1)
actionpack (= 8.1.1)
actiontext (= 8.1.1)
actionview (= 8.1.1)
activejob (= 8.1.1)
activemodel (= 8.1.1)
activerecord (= 8.1.1)
activestorage (= 8.1.1)
activesupport (= 8.1.1)
rails (8.1.2)
actioncable (= 8.1.2)
actionmailbox (= 8.1.2)
actionmailer (= 8.1.2)
actionpack (= 8.1.2)
actiontext (= 8.1.2)
actionview (= 8.1.2)
activejob (= 8.1.2)
activemodel (= 8.1.2)
activerecord (= 8.1.2)
activestorage (= 8.1.2)
activesupport (= 8.1.2)
bundler (>= 1.15.0)
railties (= 8.1.1)
railties (= 8.1.2)
rails-dom-testing (2.3.0)
activesupport (>= 5.0.0)
minitest
nokogiri (>= 1.6)
rails-html-sanitizer (1.6.2)
loofah (~> 2.21)
nokogiri (>= 1.15.7, != 1.16.7, != 1.16.6, != 1.16.5, != 1.16.4, != 1.16.3, != 1.16.2, != 1.16.1, != 1.16.0.rc1, != 1.16.0)
railties (8.1.1)
actionpack (= 8.1.1)
activesupport (= 8.1.1)
railties (8.1.2)
actionpack (= 8.1.2)
activesupport (= 8.1.2)
irb (~> 1.13)
rackup (>= 1.0.0)
rake (>= 12.2)
Expand Down Expand Up @@ -274,7 +274,7 @@ GEM
tilt (~> 2.0)
stringio (3.2.0)
thor (1.5.0)
tilt (2.6.1)
tilt (2.7.0)
timeout (0.6.0)
tsort (0.2.0)
tzinfo (2.0.6)
Expand Down
4 changes: 2 additions & 2 deletions benchmarks/Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: ..
specs:
openapi_first (3.2.0)
openapi_first (3.2.1)
drb (~> 2.0)
hana (~> 1.3)
json_schemer (>= 2.1, < 3.0)
Expand Down Expand Up @@ -61,7 +61,7 @@ GEM
rack-protection (= 4.2.1)
rack-session (>= 2.0.0, < 3)
tilt (~> 2.0)
tilt (2.6.1)
tilt (2.7.0)
vernier (1.9.0)
webrick (1.9.2)

Expand Down
13 changes: 5 additions & 8 deletions lib/openapi_first/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,12 @@ def self.install
OpenapiFirst.configure do |config|
@after_request_validation = config.after_request_validation do |validated_request, oad|
next unless registered?(oad)
raise validated_request.error.exception if raise_request_error?(validated_request)

check_unknown_query_parameters(validated_request)
if configuration.raise_request_error?(validated_request)
raise validated_request.error.exception if validated_request.unknown?

check_unknown_query_parameters(validated_request)
end

Coverage.track_request(validated_request, oad)
end
Expand Down Expand Up @@ -152,12 +155,6 @@ def unknown_parameters_message(unknown_parameters, validated_request)
"Unknown query parameter#{s} #{list} for #{validated_request.fullpath}"
end

def raise_request_error?(validated_request)
return false if validated_request.valid?

configuration.raise_request_error?(validated_request)
end

def many?(array) = array.length > 1

def raise_response_error?(validated_response, rack_request)
Expand Down
2 changes: 1 addition & 1 deletion lib/openapi_first/test/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def raise_request_error?(validated_request)
return false if @ignore_request_error&.call(validated_request)
return false if ignore_unknown_requests? && validated_request.unknown?

validated_request.unknown?
true
end

def raise_response_error?(validated_response, rack_request)
Expand Down
1 change: 1 addition & 0 deletions lib/openapi_first/validated_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ def initialize(original_request, error:, parsed_request: nil, request_definition
def_delegator :request_definition, :operation

# @return [Hash] Query parameters and values that are not defined in the OpenAPI spec.
# FIXME: Optimize this so it does not have to parse the query string a second time to find unknown parameters
def unknown_query_parameters
@query_parser&.unknown_values(query_string)
end
Expand Down
2 changes: 1 addition & 1 deletion lib/openapi_first/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module OpenapiFirst
VERSION = '3.2.0'
VERSION = '3.2.1'
end
17 changes: 17 additions & 0 deletions spec/test_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -694,6 +694,23 @@ def call(_env)
app.call(Rack::MockRequest.env_for('/unknown?unknown=12'))
end.to raise_error OpenapiFirst::NotFoundError
end

context 'when request is ignored' do
before(:each) do
described_class.uninstall
described_class.setup do |test|
test.register(definition)
test.report_coverage = false
test.ignore_request_error { |req| req.path == '/stuff' }
end
end

it 'raises no error' do
expect do
app.call(Rack::MockRequest.env_for('/stuff?color=red&unknown=12'))
end.not_to raise_error
end
end
end

describe 'handling invalid responses' do
Expand Down
Loading