Fix ValuesValidator for params wrapped in with
block
#2382
Merged
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.
This PR fixes a bug #2376 in Grape's
ValuesValidator
, specifically when parameters are nested within awith
block. Previously, the validator did not correctly handle the required validation for nested parameters in this context.Changes:
required_for_root_scope?
method inValuesValidator
has been modified to correctly detect if a parameter is required when it's nested inside awith
block. The fix involves checking the parent scope of the parameter until a non-lateral (non-with
block) scope is found, and then determining if it's the root scope.values_spec.rb
to cover the scenario where a parameter nested within awith
block doesn't meet the validation criteria, ensuring that the correct error response is generated.Impact:
This fix ensures more accurate validation of parameters nested within
with
blocks, and aligns the behavior with the expected norms of Grape's parameter validation. It's an important fix for Grape users who use nested parameter structures, improving the reliability and correctness of the validation logic.I welcome any feedback or suggestions on this fix and look forward to your reviews!