Skip to content
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

Prevent In-Place Modification of Parameter Scopes. #498

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions lib/rspec_api_documentation/dsl/endpoint/params.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,18 @@ def extended
p[:value] = SetParam.new(self, nil, p).value
unless p[:value]
cur = extra_params
[*p[:scope]].each { |scope| cur = cur && (cur[scope.to_sym] || cur[scope.to_s]) }

# When the current parameter is an array of objects, we use the
# first one for the value and add a scope indicator. The
# resulting parameter name looks like +props[pictures][][id]+
# this.
if cur.is_a?(Array) && cur.first.is_a?(Hash)
cur = cur.first
param[:scope] << ''

[*p[:scope]].each do |scope|
cur = cur && (cur[scope.to_sym] || cur[scope.to_s])

# When the current parameter is an array of objects, we use the
# first one for the value and add a scope indicator. The
# resulting parameter name looks like +props[pictures][][id]+
# this.
if cur.is_a?(Array) && cur.first.is_a?(Hash)
cur = cur.first
p[:scope] << ''
end
end

p[:value] = cur && (cur[p[:name].to_s] || cur[p[:name].to_sym])
Expand All @@ -49,7 +52,6 @@ def extended
private

attr_reader :extra_params

end
end
end
Expand Down