ruby-grape / ruby-grape/grape

support array default value

Open
#1,189 5 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

I want to declare default value as an array like below.

optional :numbers, type: Array[Integer], default: [1, 2, 5], values: [1, 2, 3, 5, 8]

But, IncompatibleOptionValues exception raised.

.../gems/grape-0.13.0/lib/grape/validations/params_scope.rb:238:in `check_incompatible_option_values': Grape::Exceptions::IncompatibleOptionValues (Grape::Exceptions::IncompatibleOptionValues)

https://github.com/ruby-grape/grape/blob/master/lib/grape/validations/params_scope.rb#L269
This line seems to be modified to support an array default value.

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 in lib/grape/validations/params_scope.rb around check_incompatible_option_values and the referenced line near 269. Trace how Array[Integer] parameters compare their default and values options, then make the example with default [1, 2, 5] valid while preserving incompatible-option checks.

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
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.