ruby-grape / ruby-grape/grape

Default value in optional param validation

Open
#1,385 3 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

Default value in optional param should not be respected in validation.

Lets see simple example where default is set for 'client' param.

params do
optional :client, type: Integer, default: 20
optional :filter_by_zone, type: Integer
at_least_one_of :client, :filter_by_zone
end

This params set will be valid even if no params passed in request.

Reproduce:
Send web request without params

Actually receiving:
Valid params and executing request

Expected:
Generate error "client, filter_by_zone are missing, at least one parameter must be provided".

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 validation with the optional :client and :filter_by_zone parameters shown in the issue, then inspect the parameter validation entry point that handles defaults and at_least_one_of. Done means a request with neither parameter produces the stated missing-parameter error instead of executing.

Written by the indexing model from the issue text.

Assessment

Tech stack
ruby
Domain
api, backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 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.