ruby-grape / ruby-grape/grape

Add support for exclusive parameter groups (e.g. exactly_one_of)

Open
#2,418 2 comments 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

grape 2.0.0

Having an issue when using nested params with exactly_one_of, here is my current setup

params :required_date do
  optional :date
  use :date_range
  exactly_one_of :date, :date_range
end

params :date_range do
  requires :start_date
  requires :end_date
  valid_interval :start_date, :end_date
end

On my endpoint I'm using the required_date param

when I run the following:
/example_endpoint?start_date=2024-03-11&end_date=2024-03-12
It returns:
{"error":"parameter validation failed","parameters":["date","date_range"],"values":[null,null],"reason":"are missing, exactly one parameter must be provided: date, date_range"}

Any way that grape will check the nested params(start_date and end_date) instead of looking for date_range?

Thanks!

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

Reproduce the issue at the example endpoint using the required_date and date_range parameter definitions shown in the report. Start by tracing validation for exactly_one_of with nested params; done means start_date and end_date satisfy the date_range alternative instead of being reported as missing, while the exclusivity rule still works.

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.