diff --git a/CHANGELOG.md b/CHANGELOG.md index 23a01a2117..110e13f746 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ #### Fixes +* [#2339](https://github.com/ruby-grape/grape/pull/2339): Documentation and specs for remountable configuration in params - [@myxoh](https://github.com/myxoh). * [#2328](https://github.com/ruby-grape/grape/pull/2328): Don't cache Class.instance_methods - [@byroot](https://github.com/byroot). * [#2337](https://github.com/ruby-grape/grape/pull/2337): Fix: allow custom validators that do not end with _validator - [@ericproulx](https://github.com/ericproulx). * Your contribution here. diff --git a/README.md b/README.md index a334a72a88..b00d2c62b4 100644 --- a/README.md +++ b/README.md @@ -526,15 +526,15 @@ end ```ruby class BasicAPI < Grape::API desc 'Statuses index' do - params: mounted { configuration[:entity] || API::Entities::Status }.documentation + params: (configuration[:entity] || API::Entities::Status).documentation end params do - requires :all, using: mounted { configuration[:entity] || API::Entities::Status }.documentation + requires :all, using: (configuration[:entity] || API::Entities::Status).documentation end get '/statuses' do statuses = Status.all type = current_user.admin? ? :full : :default - present statuses, with: mounted { configuration[:entity] || API::Entities::Status }, type: type + present statuses, with: (configuration[:entity] || API::Entities::Status), type: type end end diff --git a/spec/grape/api_remount_spec.rb b/spec/grape/api_remount_spec.rb index 9fea1c3f04..40b5505157 100644 --- a/spec/grape/api_remount_spec.rb +++ b/spec/grape/api_remount_spec.rb @@ -147,6 +147,42 @@ def app end end + context 'when the params are configured via a configuration' do + subject(:a_remounted_api) do + Class.new(described_class) do + params do + requires configuration[:required_attr_name], type: String + end + + get(mounted { configuration[:endpoint] }) do + status 200 + end + end + end + + context 'when the configured param is my_attr' do + it 'requires the configured params' do + root_api.mount a_remounted_api, with: { + required_attr_name: 'my_attr', + endpoint: 'test' + } + get 'test?another_attr=1' + expect(last_response.status).to eq 400 + get 'test?my_attr=1' + expect(last_response.status).to eq 200 + + root_api.mount a_remounted_api, with: { + required_attr_name: 'another_attr', + endpoint: 'test_b' + } + get 'test_b?another_attr=1' + expect(last_response.status).to eq 200 + get 'test_b?my_attr=1' + expect(last_response.status).to eq 400 + end + end + end + context 'when executing a standard block within a `mounted` block with all dynamic params' do subject(:a_remounted_api) do Class.new(described_class) do