Skip to content

Reusable params helpers are not inherited. #2113

Open
@dim

Description

@dim

If you mount a child API within a parent API, all helper methods are correctly inherited from parent to child, but not params helpers, for example:

class Child < Grape::API
  get '/child' do
    respond_with_ok
  end
end

class Parent < Grape::API
  helpers do
    def respond_with_ok
      { status: 'ok' }
    end
  end

  get '/parent' do
    respond_with_ok
  end

  mount Child
end
$ curl http://127.0.0.1:8080/parent  # => {:status=>"ok"}
$ curl http://127.0.0.1:8080/child    # => {:status=>"ok"}

The same doesn't really work for params, e.g:

class Child < Grape::API
  params do 
    use :page
  end
  get '/child' do
    params
  end
end

class Parent < Grape::API
  helpers do
    params :page do
      optional :page, type: Integer
    end
  end

  params do 
    use :page
  end
  get '/parent' do
    params
  end

  mount Child
end

Results in a:

RuntimeError: Params :page not found!

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions