ruby-grape / ruby-grape/grape

Nested Param Helpers - using *:use* inside a Grape::API::Helper

Open
#1,391 4 comments 6 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Hello guys,

I'm trying to reuse param definition in my helpers but the use :param method doesn't seem to work inside Grape::API::Helpers.

The use case is I have two different models that include a third model like this:

module Animal
  extend Grape::API::Helpers

  params :animal do
    requires :mammal, Boolean
    requires :other_fields, String
  end
end

module Dog
  extend Grape::API::Helpers

  params :dog do
    requires :breed, String
    requires :animal do
      use :animal
    end
  end
end

Unfortunately inside Dog grape complains that it cannot find params for :animal. I've tried extending and including the Animal module with no success.

Also the helpers method is not included by Grape::API::Helpers.

Is there any way I can do this?

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

Start by reproducing the nested parameter example from the issue, focusing on Grape::API::Helpers and the use :animal call inside Dog. Trace how parameter definitions are registered and resolved for helpers, then verify that the nested call finds Animal's definition and that the existing parameter behavior remains intact.

Written by the indexing model from the issue text.

Assessment

Tech stack
ruby
Domain
api
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.