-
-
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
Optional values with multiple types get coerced to an empty Array #2018
Comments
stanhu
added a commit
to stanhu/grape
that referenced
this issue
Mar 17, 2020
If an optional parameter has multiple types (e.g. [File, String]) and a nil parameter is passed, Grape would previously coerce the value to an empty Array. This can break certain APIs that treat nil values differently from an empty Array. Closes ruby-grape#2018
stanhu
added a commit
to stanhu/grape
that referenced
this issue
Mar 17, 2020
If an optional parameter has multiple types (e.g. [File, String]) and a nil parameter is passed, Grape would previously coerce the value to an empty Array. This can break certain APIs that treat nil values differently from an empty Array. Closes ruby-grape#2018
stanhu
added a commit
to stanhu/grape
that referenced
this issue
Mar 17, 2020
If an optional parameter has multiple types (e.g. [File, String]) and a nil parameter is passed, Grape would previously coerce the value to an empty Array. This can break certain APIs that treat nil values differently from an empty Array. Closes ruby-grape#2018
stanhu
added a commit
to stanhu/grape
that referenced
this issue
Mar 17, 2020
If an optional parameter has multiple types (e.g. [File, String]) and a nil parameter is passed, Grape would previously coerce the value to an empty Array. This can break certain APIs that treat nil values differently from an empty Array. Closes ruby-grape#2018
stanhu
added a commit
to stanhu/grape
that referenced
this issue
Mar 17, 2020
If an optional parameter has multiple types (e.g. [File, String]) and a nil parameter is passed, Grape would previously coerce the value to an empty Array. This can break certain APIs that treat nil values differently from an empty Array. Closes ruby-grape#2018
stanhu
added a commit
to stanhu/grape
that referenced
this issue
Mar 17, 2020
If an optional parameter has multiple types (e.g. [File, String]) and a nil parameter is passed, Grape would previously coerce the value to an empty Array. This can break certain APIs that treat nil values differently from an empty Array. To fix this, we refactor the nil handling into a `coerce_nil` method and remove the special case check for handling an Array of types. Closes ruby-grape#2018
stanhu
added a commit
to stanhu/grape
that referenced
this issue
Mar 17, 2020
If an optional parameter has multiple types (e.g. [File, String]) and a nil parameter is passed, Grape would previously coerce the value to an empty Array. This can break certain APIs that treat nil values differently from an empty Array. To fix this, we refactor the nil handling into a `coerce_nil` method and remove the special case check for handling an Array of types. Closes ruby-grape#2018
stanhu
added a commit
to stanhu/grape
that referenced
this issue
Mar 17, 2020
If an optional parameter has multiple types (e.g. [File, String]) and a nil parameter is passed, Grape would previously coerce the value to an empty Array. This can break certain APIs that treat nil values differently from an empty Array. To fix this, we refactor the nil handling into a `coerce_nil` method and remove the special case check for handling an Array of types. Closes ruby-grape#2018
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This breaks certain APIs that expect a parameter passed in with
nil
to remainnil
. To reproduce the problem:This is the test failure:
It looks like this happens because of this code block:
grape/lib/grape/validations/validators/coerce.rb
Lines 68 to 71 in 8deebb5
I'm not quite sure I understand why the
type.is_a?(Array)
check needs to be there. This allows tests to pass:Also, if we need to accept
nil
as a coerced value, there is https://github.com/dry-rb/dry-types/blob/bd75d556e70c2d3bef1f96140a8f33fb44c31f9d/docsite/source/optional-values.html.md.The text was updated successfully, but these errors were encountered: