ruby-grape/grape · warning
Passing a positional options Hash to `#{method_name}` is dep
Error message
Passing a positional options Hash to `#{method_name}` is deprecated. Pass keyword arguments instead. What it means
The auth DSL (`auth`, `http_basic`, `http_digest`) takes keyword options. A positional Hash (e.g. `http_basic({ realm: 'x' }, &block)`) lands in the legacy splat; `merge_legacy_auth_options` warns via `Grape.deprecator`, merges it with the keyword options, and proceeds with the merged result.
Source
Thrown at lib/grape/middleware/auth/dsl.rb:33
# Add HTTP Basic authorization to the API.
#
# @param options [Hash] a hash of options
# @option options [String] :realm "API Authorization" the HTTP Basic realm
def http_basic(*legacy_options, **options, &)
options = merge_legacy_auth_options(:http_basic, legacy_options, options)
options[:realm] ||= 'API Authorization'
auth(:http_basic, **options, &)
end
private
# @deprecated Passing a positional options Hash is deprecated; pass
# keyword arguments instead. Kept so downstream callers keep working
# through the deprecation cycle.
def merge_legacy_auth_options(method_name, legacy_options, options)
return options if legacy_options.empty?
Grape.deprecator.warn("Passing a positional options Hash to `#{method_name}` is deprecated. Pass keyword arguments instead.")
legacy_options.first.merge(options)
end
end
end
end
end
View on GitHub (pinned to 22d7975629)
Solutions
- Pass keywords: `auth :http_basic, realm: 'API'`
- When options are dynamic, double-splat them: `auth(:http_digest, **opts, &block)`
- Run the suite with `Grape.deprecator.behavior = :raise` to find stragglers
Example fix
# before
http_basic({ realm: 'Restricted' }, &auth_block)
# after
http_basic realm: 'Restricted', &auth_block Defensive patterns
Strategy: validation
Validate before calling
# CI guard: auth DSL positional hashes raise in the test env Grape.deprecator.behavior = :raise if ENV['CI']
Prevention
- Pass auth options as keywords: `http_basic realm: 'Restricted', &block`
- When building auth calls dynamically, double-splat the options hash
- Check mount gems for `auth :http_basic, {`-style calls when upgrading
When it happens
Trigger: `auth :http_basic, { realm: 'API' }`; `http_basic({ realm: 'Restricted' }, &auth_block)`; `http_digest({ realm: 'api' }, &block)` — any auth call whose options Hash is passed as a positional argument.
Common situations: Older samples written before Ruby 3 keyword separation; gems that mount Grape APIs and build auth option hashes programmatically.
Related errors
- Passing a positional options Hash to `desc` is deprecated. P
- Passing a positional options Hash to `#{method_name}` is dep
- rescue_from #{meta_selector.inspect} does not accept additio
- Either contract or block must be provided
- must supply type for coerce_with
AI-assisted analysis of ruby-grape/grape@22d7975629 (2026-08-21).
Data as JSON: /api/errors/362f16f076f19fb1.
Report an issue: GitHub.