-
-
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
declared transforms empty array to hash #1642
Comments
How do you call it? Are you posting JSON with the correct content-type? |
Yes, it's application/json. |
Try to build a spec for this next. |
Unfortunately I'm not able to write a failing test for this. I tried both with master and v0.19.2. |
I am having the same issue after updating Grape to the latest version. params :instance_params do
requires :name, type: String
optional :locations, type: Array do
requires :latitude, type: Float
requires :longitude, type: Float
end
end When sending something without the Sending {
"name": "FooBar",
"locations": []
} Works fine But sending: {
"name": "FooBar"
} Results in the following {
"name" => "FooBar",
"locations" => {
"latitude" => nil,
"longitude" => nil
}
} |
I experienced this issue when attempting to upgrade to 19.2 as well. It looks like there's some spec detailing this functionality for hashes but not for arrays. This looks to have changed here: #1575. There's some brief discussion in this ticket. From the sounds of it, the expectation is that we'd keep the functionality of nested arrays being populated as an array with Here's a diff with a failing spec that demos this issue. I can work on a PR if we confirm the expectation: https://github.com/ruby-grape/grape/compare/master...jeradphelps:jeradphelps/issue-1642?expand=1 |
Spec looks legit, PR with a fix? ;) |
Gentlemen, I wrote the #1710 PR to solve this problem. |
Closed via #1710. |
I am using 0.19.2 and I have the following endpoint:
When I call it with
I get this output:
In other words, for some reason the empty
arr
array has become a hash containingarr
's required fields.The text was updated successfully, but these errors were encountered: