#2073·grape

Parameter defaults ignored when nested inside hash

Author: tlconnorCreated Jun 23, 2020Updated Jun 19, 2024
Labelsbug?

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:

ruby
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:

json
{ "filter": { "status": "new" } }

but instead it will respond with

json
{}

I have a commit with an example failing test case. https://github.com/tlconnor/grape/commit/26beeab