-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Handle json array #2538
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
Merged
dblock
merged 5 commits into
ruby-grape:master
from
mohammednasser-32:Handle_json_array
Feb 25, 2025
Merged
Handle json array #2538
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
d3e8de5
Handle json array
mohammednasser-32 a51f779
Fix rubocop offenses
mohammednasser-32 3e2f133
fix index
mohammednasser-32 6921bb4
fix json array with nested json array
mohammednasser-32 ab35c7e
add change to changelog
mohammednasser-32 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,7 +4,7 @@ module Grape | |
| module Validations | ||
| class ParamsScope | ||
| attr_accessor :element, :parent, :index | ||
| attr_reader :type | ||
| attr_reader :type, :params_meeting_dependency | ||
|
|
||
| include Grape::DSL::Parameters | ||
|
|
||
|
|
@@ -67,6 +67,7 @@ def initialize(opts, &block) | |
| @type = opts[:type] | ||
| @group = opts[:group] | ||
| @dependent_on = opts[:dependent_on] | ||
| @params_meeting_dependency = [] | ||
| @declared_params = [] | ||
| @index = nil | ||
|
|
||
|
|
@@ -94,7 +95,11 @@ def should_validate?(parameters) | |
| def meets_dependency?(params, request_params) | ||
| return true unless @dependent_on | ||
| return false if @parent.present? && [email protected]_dependency?(@parent.params(request_params), request_params) | ||
| return params.any? { |param| meets_dependency?(param, request_params) } if params.is_a?(Array) | ||
|
|
||
| if params.is_a?(Array) | ||
| @params_meeting_dependency = params.filter { |param| meets_dependency?(param, request_params) } | ||
| return @params_meeting_dependency.present? | ||
| end | ||
|
|
||
| meets_hash_dependency?(params) | ||
| end | ||
|
|
@@ -127,7 +132,7 @@ def meets_hash_dependency?(params) | |
| def full_name(name, index: nil) | ||
| if nested? | ||
| # Find our containing element's name, and append ours. | ||
| "#{@parent.full_name(@element)}#{brackets(@index || index)}#{brackets(name)}" | ||
| "#{@parent.full_name(@element)}#{brackets(index || @index)}#{brackets(name)}" | ||
| elsif lateral? | ||
| # Find the name of the element as if it was at the same nesting level | ||
| # as our parent. We need to forward our index upward to achieve this. | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
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.
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.
This is memoized, shouldn't it be
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.
It is not really memoized,
@params_meeting_dependencyis initiated as an empty array and we can not memoize it because:so we will not be able to change the value, I guess we don't need to memoize it anyways we only set the value once and read it with
attr_reader, right?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.
I think so. Let’s get rid of the unneeded memorization?
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.
but I think it is already not memorized, you mean this line right?
I am already using
=here, so which memorization you mean?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.
Nevermind, this is fine. I see we need
@params_meeting_dependencylater. I dislike that we have a@in here but it can be called multiple times.