-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Breaking change for nested params in declared
in Grape 1.3.3
#2101
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Ouch, this keeps biting us, cc: @kadotami and @dnesteryuk. Naively reading our own README it feels like if you say |
My interpretation is that you should get the whole (aka declared) structure, and there are certainly benefits to that behavior. The specs before #2043 were ambiguous - there was no spec that definitively asserted or refuted the behavior. If we can get a definitive design decision from the maintainers of Grape one way or the other I would be happy to submit a PR to update the README / code / specs. |
Just for a bit of additional context, we have many use cases that looks something like this: params do
optional :filter, type: Hash do
optional :widgets, type: Hash do
optional :name, type: String
end
optional :gadgets, type: Hash do
optional :name, type: String
end
end
end In the API body, we would be able to go: filter = declared(params)[:filter]
filter_by_widget_name if filter[:widgets][:name].present? In Grape 1.3.2 this would work fine. If we were to preserve the existing behavior, the API code would need to change to something like: filter = declared(params)[:filter]
filter_by_widget_name if filter.dig(:widgets, :name).present? |
I vote for expanding deep as you suggest. If others can add a +1 that'd be great. |
A PR was merged back in April and included in Grape
1.3.3
that has changed the waydeclared
works.#2043
Before this PR was merged, the
declared
helper would guarantee that the entire params structure would be recreated, including deeply nested parameters. Any leaf params not provided would havenil
values.With this merged PR, any missing
Hash
params would be evaluated as{}
, even if they has deeper nested params defined.Here is an example from
endpoint_spec.rb
. Theparams
are defined as:Given a test that calls
get '/declared?first=present'
, the result ofdeclared(params)
would be:In Grape
1.3.2
:In Grape
1.3.3
:It is not clear which of these is the correct behavior. The merged PR #2043 would suggest that the latter is correct, however it is actually very useful to have the previous behavior from 1.3.2.
The README isn't clear about what the behavior should be for deeply nested params.
The text was updated successfully, but these errors were encountered: