{"record":{"id":"5a257456302a0956","repo":"ruby-grape/grape","slug":"self-class-name-is-deprecated-use-the-nam","errorCode":null,"errorMessage":"`#{self.class.name}#[]` is deprecated. Use the named accessor `#{key}` instead.","messagePattern":"`#(.+?)#\\[\\]` is deprecated\\. Use the named accessor `#(.+?)` instead\\.","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"lib/grape/middleware/deprecated_options_hash_access.rb","lineNumber":11,"sourceCode":"# frozen_string_literal: true\n\nmodule Grape\n  module Middleware\n    # Mixin for per-middleware +Options+ +Data+ classes that need to keep\n    # accepting legacy +data[:key]+ Hash-style access while nudging callers\n    # toward the named accessor. Emits a +Grape.deprecator+ warning then\n    # forwards to +public_send(key)+.\n    module DeprecatedOptionsHashAccess\n      def [](key)\n        Grape.deprecator.warn(\n          \"`#{self.class.name}#[]` is deprecated. \" \\\n          \"Use the named accessor `#{key}` instead.\"\n        )\n        public_send(key) if members.include?(key)\n      end\n    end\n  end\nend\n","sourceCodeStart":1,"sourceCodeEnd":20,"githubUrl":"https://github.com/ruby-grape/grape/blob/22d7975629846a3c0c7bd2b34e140a7a1b4af8f6/lib/grape/middleware/deprecated_options_hash_access.rb#L1-L20","documentation":"Per-middleware option classes (used by the error, formatter, and versioner middlewares) are now `Data` structs with named accessors instead of Hashes. The `[]` shim kept for legacy `options[:key]` access warns via `Grape.deprecator` and forwards to the named accessor via `public_send`; unknown keys (not in `members`) return nil.","triggerScenarios":"Custom middleware subclassing a Grape middleware and reading `options[:some_key]` instead of `options.some_key`; code reaching into middleware option objects with Hash-style access after a Grape upgrade.","commonSituations":"Upgrading Grape where middleware Options classes became Data; shared middleware code written against the old Hash interface.","solutions":["Switch to the named accessor: `options.some_key`","When the key is dynamic, guard on members: `options.public_send(key) if options.members.include?(key)`","Pin the middleware's specs against the new accessor interface so regressions surface in CI"],"exampleFix":"# before\nstatus = options[:default_status]\n\n# after\nstatus = options.default_status","handlingStrategy":"validation","validationCode":"# Prefer named accessors; if the key is dynamic, guard on members:\nvalue = options.public_send(key) if options.members.include?(key)","typeGuard":"def named_option?(options, key)\n  options.respond_to?(:members) && options.members.include?(key)\nend","tryCatchPattern":null,"preventionTips":["Treat middleware options as Data structs: use `options.some_key`, not `options[:some_key]`","In custom middleware specs, exercise the named accessors so Hash-style access never creeps back","During Grape upgrades, grep middleware subclasses for `options[`"],"tags":["grape","middleware","deprecation","options","data-struct"],"backgroundTag":"deprecated-api-usage","analyzedSha":"22d7975629846a3c0c7bd2b34e140a7a1b4af8f6","analyzedAt":"2026-08-21T17:03:54.627Z","schemaVersion":2},"datasetVersion":"2026-08-21T18:17:14.833Z"}