ruby-grape / ruby-grape/grape

declared(params) - "no implicit conversion of Symbol into Integer" when receiving blank array

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

  1. I have an optional array parameter. In some cases I want it to be blank, but if the items are passed, they must match the schema inside.
params do
  optional :outline, type: Array do
    requires :x
    requires :y
  end
end
  1. I do a PATCH request and send {"outline": []} payload.
  2. Received params =>{ "outline"=>[""] } - here is the first question - why an empty string inside an array? I have a feeling that I've struggled with that a few years back, but don't remember what was the cause.
  3. declared(params) raises no implicit conversion of Symbol into Integer

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 PATCH request with the declared optional array schema and an empty outline payload, then trace the declared(params) handling that produces the empty string and Symbol-to-Integer error. Done means the empty array is handled without the exception and the expected behavior for items inside the array is covered by a regression test.

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
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.