ruby-grape / ruby-grape/grape

Reuse `at_least_one_of` set of params on multiple named param blocks

Open
#1,608 1 comment 0 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

Let's say one would like to "inherit" a declared at_least_one_of set of params on the main params block of an endpoint:

helpers do
  params :x_params do
    at_least_one_of :x
  end
  
  params :y_params do
    at_least_one_of :y
  end
end

params do
  use :x_params
  use :y_params
end

In that case, I'd expect a "merge" between both, generating something like a at_least_one_of :x, :y at the end.

My current practical use case involves much more params, and endpoints, that's why creating multiple constants and manually merging them would not be a elegant solution for reusing.

One thing that came in mind is allowing use method to receive arguments (optional key?) that would set values available only on the scope of, let's say, params :x_params block. But i'm totally unaware if it's feasible.

Would be happy to know alternatives, or even some guidance for a future contribution.

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 tracing the params, use, and at_least_one_of entry points in Grape's parameter DSL and review existing tests for named parameter blocks. Clarify the intended merge behavior and scope of any values passed to use. Done means reusable blocks combine their at_least_one_of declarations correctly without breaking existing parameter definitions.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.