grape
grape copied to clipboard
Parameter defaults ignored when nested inside hash
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
Does setting default on :filter change anything?
Does setting default on
:filterchange anything?
It does not help. Adding default: {} to the parent results in:
{ "filter": {} }
Looks like a bug. PRs welcome.
@dblock I would like to create a fix for this this, can you please point me to the right direction?
@sekmo Start by writing a failing RSpec test?
@dblock I mean can you point me to the part in the codebase where we deal with this logic?
Most parameter logic lives around https://github.com/ruby-grape/grape/blob/master/lib/grape/validations/params_scope.rb, but I don't have anything more specific to point you to, sorry.
Thank you, I'll check it out as soon as I have some time :)