Skip to content
Open
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
* [#2829](https://github.com/ruby-grape/grape/pull/2829): Fix a cascading route handing over only to the last route registered for the path, making a middle version (3+ mounted versions with a catch-all) answer 406 - [@ericproulx](https://github.com/ericproulx).
* [#2826](https://github.com/ruby-grape/grape/pull/2826): Fix `api.version` not being set for the root route of a path-versioned API (`GET /v1`) - [@ericproulx](https://github.com/ericproulx).
* [#2842](https://github.com/ruby-grape/grape/pull/2842): Warn at definition time when a `rescue_from` class is already covered by one registered earlier in the same scope, since the later handler never runs - [@ericproulx](https://github.com/ericproulx).
* [#2852](https://github.com/ruby-grape/grape/pull/2852): Preserve positional options hashes passed to named params - [@cyphercodes](https://github.com/cyphercodes).
* Your contribution here.

### 3.3.5 (2026-07-30)
Expand Down
2 changes: 2 additions & 0 deletions lib/grape/dsl/parameters.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ def build_with(build_with)
# end
# end
def use(*names, **options)
options = names.pop if options.empty? && names.size > 1 && names.last.is_a?(Hash)

named_params = @api.inheritable_setting.named_params || {}
names.each do |name|
params_block = named_params.fetch(name) do
Expand Down
7 changes: 7 additions & 0 deletions spec/grape/dsl/parameters_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,13 @@ def new_group_scope(group)
subject.use :params_group, **options
end

it 'extracts a positional options hash from named params' do
subject.api = Class.new { include Grape::DSL::Settings }.new
subject.api.inheritable_setting.add_named_params(named_params)
expect(subject).to receive(:instance_exec).with(options).and_yield
subject.use :params_group, options
end

it 'raises error when non-existent named param is called' do
subject.api = Class.new { include Grape::DSL::Settings }.new
expect { subject.use :params_group }.to raise_error('Params :params_group not found!')
Expand Down