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

  1. Pass keywords: `auth :http_basic, realm: 'API'`
  2. When options are dynamic, double-splat them: `auth(:http_digest, **opts, &block)`
  3. 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

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


AI-assisted analysis of ruby-grape/grape@22d7975629 (2026-08-21). Data as JSON: /api/errors/362f16f076f19fb1. Report an issue: GitHub.