ruby-grape / ruby-grape/grape

exactly_one_of seems not work for nested parameters

Open
#1,288 10 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

Hello,

I'm currently creating an API with the latest version(0.14.0) but exactly_one_of doesn't work as expected for nested parameters.

Here is the sample.

params do
  optional :additionalFacets, type: Hash do
    requires: label, type: String
    requires: facet, type: Hash do
      requires :field, type: String
      requires :type, type: String

      optional :limit, type: Integer
      optional :start, type: Integer

      exactly_one_of :limit, :start
    end
  end
end

In this case I meant the validation of exactly_one_of works only when additionalFacets are given.
But it works when it is not given as well.

Can you help check 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 with Grape 0.14.0 and trace the exactly_one_of validation entry point. Done means exactly_one_of is enforced when additionalFacets is supplied, but is not triggered when that optional parent parameter is absent; add a regression test for both cases.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.