-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Bugfix: Correctly handle given
in Array params
#1625
Bugfix: Correctly handle given
in Array params
#1625
Conversation
Build needs to be fixed please. |
3d125cb
to
44913f7
Compare
@rnubel Including an extra test to check for each element being independently validated fails. Given your test, removing
results in
|
I'll wait for @rnubel to comment on the above before merging. Code looks OK to me otherwise. |
Array parameters are handled as a parameter that opens a scope with `type: Array`; `given` opens up a new scope, but was always setting the type to Hash. This patch fixes that, as well as correctly labeling the error messages associated with array fields.
44913f7
to
f2c9b95
Compare
Good catch, @timothysu. The problem was that an Array block defines a single scope, for which |
Any update on this? |
Please contribute @avellable. |
Still needs CHANGELOG and stuff. |
return true if parent.nil? | ||
parent.should_validate?(parameters) | ||
end | ||
|
||
def meets_dependency?(params) | ||
if @dependent_on |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make this a guard, return unless ...
@avellable appreciate the help. @timothysu would you be able to test this patch to verify it works in real-life usage? I can test it against contrived scenarios, but there's no substitute for a real app. |
@rnubel Thanks! Sorry I forgot to add your name in the CHANGELOG of my changes. I'll close my PR now. |
@rnubel It doesn't seem to solve real-life usage issues, during a quick test. I'll double check and follow up with more actionable info when I get a chance. |
I am going to merge this since it fixes at least one problem (per spec), @timothysu add anything on top that's failing in a new issue/spec please. |
use correct params class in declared add changelog entry add tests for declared class fix rubocop make changelog entry better remove puts in tests one more puts change test names conform changelog entry return dynamic class name parse response instead remove params Instrument validators with ActiveSupport::Notifications Suppress `warning: method redefined` Bugfix: Correctly handle `given` in Array params (ruby-grape#1625) * Bugfix: Correctly handle `given` in Array params Array parameters are handled as a parameter that opens a scope with `type: Array`; `given` opens up a new scope, but was always setting the type to Hash. This patch fixes that, as well as correctly labeling the error messages associated with array fields. * Code review fix * Add CHANGELOG entry Add ability to include an array of modules as helpers Changing helpers DSL to allow the inclusion of many modules. This attemps to bring a better readability, since it seems to be more intuitive to send a list of modules when the message in question is called helpers. ensure we return a string from test return json in tests Update README according to new `helpers` macro interface Silence warnings (ruby-grape#1632) * silence warnings initialize vars in initializers subclass hashie mash to silence warnings rubocop fixes add changelog entry Revert "use correct params class in declared" This reverts commit 61f0c8e. fix tests * remove disable_warnings in hashie mash * make rubocop happy * fix hashie tests
Multi-param and default validators, all of which implemented their own `validate!` method, were not respecting the `given` dependency as expected. This change copies the check into all those validators. The bug was likely introduced by ruby-grape#1625, which required that the dependency check be moved out of the scope itself and into the validators. Rolling back that change would require fundamentally re-architecting how array parameters are validated (possibly with a new kind of scope).
Multi-param and default validators, all of which implemented their own `validate!` method, were not respecting the `given` dependency as expected. This change copies the check into all those validators. The bug was likely introduced by ruby-grape#1625, which required that the dependency check be moved out of the scope itself and into the validators. Rolling back that change would require fundamentally re-architecting how array parameters are validated (possibly with a new kind of scope).
Multi-param and default validators, all of which implemented their own `validate!` method, were not respecting the `given` dependency as expected. This change copies the check into all those validators. The bug was likely introduced by ruby-grape#1625, which required that the dependency check be moved out of the scope itself and into the validators. Rolling back that change would require fundamentally re-architecting how array parameters are validated (possibly with a new kind of scope).
* Bugfix: Correctly handle `given` in Array params Array parameters are handled as a parameter that opens a scope with `type: Array`; `given` opens up a new scope, but was always setting the type to Hash. This patch fixes that, as well as correctly labeling the error messages associated with array fields. * Code review fix * Add CHANGELOG entry
* Bugfix: Correctly handle `given` in Array params Array parameters are handled as a parameter that opens a scope with `type: Array`; `given` opens up a new scope, but was always setting the type to Hash. This patch fixes that, as well as correctly labeling the error messages associated with array fields. * Code review fix * Add CHANGELOG entry
* Bugfix: Correctly handle `given` in Array params Array parameters are handled as a parameter that opens a scope with `type: Array`; `given` opens up a new scope, but was always setting the type to Hash. This patch fixes that, as well as correctly labeling the error messages associated with array fields. * Code review fix * Add CHANGELOG entry
Addresses #1600 and #1602.
Array parameters are handled as a parameter that opens a scope with
type: Array
;given
opens up a new scope, but was always setting the type to Hash. This patch fixes that, as well as correctly labeling the error messages associated with array fields.