Reuse `at_least_one_of` set of params on multiple named param blocks
Nobody has claimed this yet.
- 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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