Skip to content

Grape deprecates passing a positional options Hash to desc (grape-swagger uses it internally) #977

Description

@ericproulx

Summary

Grape (ruby-grape/grape#2723) is moving Grape::DSL::Desc#desc to keyword arguments. Passing a positional options Hash still works but now emits a deprecation:

Passing a positional options Hash to desc is deprecated. Pass keyword arguments instead.

For apps that configure Grape.deprecator.behavior = :raise (the default in Grape's own test suite, and common in CI), this turns into an ActiveSupport::DeprecationException and add_swagger_documentation raises outright.

Where grape-swagger triggers it

grape-swagger 2.1.4 calls desc with a positional Hash in lib/grape-swagger/doc_methods.rb:

# ~line 96
desc api_doc.delete(:desc), api_doc

# ~line 108
desc specific_api_doc.delete(:desc), { params: specific_api_doc.delete(:params) || {}, **specific_api_doc }

Suggested fix

Double-splat the options Hash so they are passed as keyword arguments (backward compatible with current Grape):

desc api_doc.delete(:desc), **api_doc

desc specific_api_doc.delete(:desc), params: specific_api_doc.delete(:params) || {}, **specific_api_doc

Reproduction

require 'grape'
require 'grape-swagger'

Grape.deprecator.behavior = :raise

Class.new(Grape::API) { add_swagger_documentation }
# => ActiveSupport::DeprecationException: Passing a positional options Hash to `desc` is deprecated.

Tested against grape-swagger 2.1.4 with Grape from ruby-grape/grape#2723. That PR adds a grape-swagger integration job to Grape's CI to catch regressions like this going forward.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions