ruby-grape / ruby-grape/grape

Reusable params helpers are not inherited.

Open
#2,113 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug?
Dominant language
Ruby
Stars
10k
Forks
1.2k
Avg merge
14h 38m
Merged PRs (30d)
92

Description

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!

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Use the parent/child API examples in the issue as the reproduction, focusing on the params blocks, reusable :page declaration, and mount Child behavior. Trace how params helpers are resolved across the mounted API boundary and add regression coverage showing the child can use the parent’s :page helper without raising RuntimeError.

Written by the indexing model from the issue text.

Assessment

Tech stack
ruby
Domain
api, backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.