Parameter defaults ignored when nested inside hash
Nobody has claimed this yet.
- Dominant language
- Ruby
- Stars
- 10k
- Forks
- 1.2k
- Avg merge
- 14h 38m
- Merged PRs (30d)
- 92
Description
I'm not sure if this is the intended behavior or not, but there appears to be a problem with the :default option on params that are nested inside another param of type Hash.
For example, given this code:
params do
optional :filter, type: Hash do
optional :status, default: 'new'
end
end
get do
params
end
If I call this API, I would expect to get back:
{ "filter": { "status": "new" } }
but instead it will respond with
{}
I have a commit with an example failing test case.
https://github.com/tlconnor/grape/commit/26beeab
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the failing test case in commit 26beeab and trace how the nested Hash parameter is parsed and how default values are applied. Done means the example returns {"filter":{"status":"new"}} when filter is omitted, with the relevant tests passing.
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
- Mostly clear
- Newbie friendliness
- 35/100