Skip to content

Commit c04fbd2

Browse files
authored
Merge pull request #422 from ahx/config-no-clone
Remove Configuration#clone. Use #child instead
2 parents 07f1ac8 + e477486 commit c04fbd2

4 files changed

Lines changed: 11 additions & 4 deletions

File tree

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,12 @@
2222
### Removed
2323
- Removed deprecated methods which produced a warning since 2.0.0.
2424
- Removed internally used `Test::Coverage.current_run, .plans, .install, .uninstall`. If you are using these, use `OpenapiFirst::Test.setup` instead.
25+
- Removed `OpenapiFirst::Configuration#clone`. Use `#child` instead.
26+
- It's not possible to remove locally added hooks. But you can restart with a blank list of hooks by calling `OpenapiFirst.configure`
2527

2628
### Fixed
2729
- Update dependency `openapi_parameters` to >= 0.7.0, because that version supports unpacking parameters the use `style: deepObject` with `explode: true`.
30+
- Make `OpenapiFirst::Test.setup` more robust by adding `OpenapiFirst::Configuration#child` so it does not matter if you load our OAD before callig `OpenapiFirst::Test.setup`.
2831

2932
## 2.11.1
3033

lib/openapi_first/configuration.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,16 @@ def register(path_or_definition, as: :default)
2525
attr_reader :request_validation_error_response, :hooks
2626
attr_accessor :request_validation_raise_error, :response_validation_raise_error, :path
2727

28+
# Return a child configuration that still receives updates of global hooks.
2829
def child
2930
ChildConfiguration.new(parent: self)
3031
end
3132

33+
# @visibility private
34+
def clone
35+
raise NoMethodError, 'OpenapiFirst::Configuration#clone was removed. You want to call #child instead'
36+
end
37+
3238
HOOKS.each do |hook|
3339
define_method(hook) do |&block|
3440
return hooks[hook] if block.nil?

lib/openapi_first/definition.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class Definition
2222
# @param filepath [String] The file path of the OpenAPI document.
2323
def initialize(contents, filepath = nil)
2424
@filepath = filepath
25-
@config = OpenapiFirst.configuration.clone
25+
@config = OpenapiFirst.configuration.child
2626
yield @config if block_given?
2727
@config.freeze
2828
@router = Builder.build_router(contents, filepath:, config:)

spec/hooks_spec.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ def build_request(path, method: 'GET', body: nil)
55
Rack::Request.new(Rack::MockRequest.env_for(path, method:, input: body, 'CONTENT_TYPE' => 'application/json'))
66
end
77

8-
describe 'adding and removing a hook' do
8+
describe 'adding a hook' do
99
specify do
1010
called = []
1111
myproc = proc do |request|
@@ -16,8 +16,6 @@ def build_request(path, method: 'GET', body: nil)
1616
config.after_request_validation(&myproc)
1717
end
1818
definition.validate_request(build_request('/pets?limit=24'))
19-
definition.config.after_request_validation.delete(myproc)
20-
definition.validate_request(build_request('/pets?limit=24'))
2119

2220
expect(called).to eq([['listPets', true]])
2321
end

0 commit comments

Comments
 (0)