Preserve positional options for named params - #2852
Conversation
82550c8 to
8be56b2
Compare
|
Thanks for the quick turnaround on this @cyphercodes! While the
So this PR fixes one instance of the symptom, but the current fix does not fully resolve the problem — the same class of bug is reachable through several other entry points. To recap the case already covered by #2851/this PR: Steps to reproducerequire 'grape'
class API < Grape::API
params do
use :pagination, { max_per_page: 100 }
end
get '/items' do
params
end
endExpected behaviorThe options hash passed positionally is extracted and forwarded to the named param block, same as before #2618. Actual behaviorThe positional hash is treated as another name in Here's a case this PR does not fix, on Steps to reproducerequire 'grape'
class API < Grape::API
get 'version' do
present version: '1.0.0'
end
endExpected behaviorThe response body should be Actual behaviorThe response body is
Given how many call sites share this pattern, it might be worth addressing this class of bug more systematically (e.g. reverting to |
Summary
Grape::DSL::Parameters#usestill accepts keyword options, but Ruby 3 no longer turns a trailing positional Hash into keywords. After #2618, calls likeuse :pagination, { max_per_page: 100 }treated the Hash as another named params key instead of as options.This restores the old
extract_options!behavior for the multi-argument case by extracting a trailing positional Hash when no keyword options were supplied, while preserving single-argument named param lookup.Fixes #2851.
Test plan
use :params_group, options; verified it fails before the fix.bundle exec rspec spec/grape/dsl/parameters_spec.rb(Ruby 3.4 Docker): 24 examples, 0 failures.bundle exec rubocop lib/grape/dsl/parameters.rb spec/grape/dsl/parameters_spec.rb: 2 files inspected, no offenses detected.bundle exec rake(Ruby 3.4 Docker): RuboCop 338 files inspected, no offenses detected; RSpec 2551 examples, 0 failures.🤖 AI-assisted with Hermes Agent; changes were reviewed and verified locally.