Fix is_array check for non-contiguous sub and parent entities #691
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
While reviewing an API made with Grape, I noticed that an entity created for a POST request param body did not have the correct markings for array and object. In digging into the code, I found that the
parse_request_params
was dependent on the ordering of the params coming in. Specifically, since we initializearray_key
outside the loop, and then set it below, it should exist for elements of an array, but I found that my params were in an order that caused sub elements to not be by their parents. For example (from tests so that I don't have to leak my API internals):would be updated to (notice
'stuffs[owners][id]'
).I updated parse_request_params to keep all array keys and then see if the name of current param matches any of them exactly or matches any of the array keys with a
[
appended which would indicate it is a sub element.