From 53b563f7f0943fddda6e71af1f140c29034bc026 Mon Sep 17 00:00:00 2001 From: Minty Fresh <7896757+mintyfresh@users.noreply.github.com> Date: Mon, 18 Oct 2021 15:08:39 -0400 Subject: [PATCH 1/2] Prevent in-place modification of parameter scopes. --- lib/rspec_api_documentation/dsl/endpoint/params.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/rspec_api_documentation/dsl/endpoint/params.rb b/lib/rspec_api_documentation/dsl/endpoint/params.rb index 63d7d752..020fbbb2 100644 --- a/lib/rspec_api_documentation/dsl/endpoint/params.rb +++ b/lib/rspec_api_documentation/dsl/endpoint/params.rb @@ -37,7 +37,7 @@ def extended # this. if cur.is_a?(Array) && cur.first.is_a?(Hash) cur = cur.first - param[:scope] << '' + p[:scope] << '' end p[:value] = cur && (cur[p[:name].to_s] || cur[p[:name].to_sym]) From 90e57068b3bfb53bb2723fd2e85ae518e5459509 Mon Sep 17 00:00:00 2001 From: Minty Fresh <7896757+mintyfresh@users.noreply.github.com> Date: Mon, 18 Oct 2021 15:47:10 -0400 Subject: [PATCH 2/2] Handle multiple levels of parameter arrays. --- .../dsl/endpoint/params.rb | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/lib/rspec_api_documentation/dsl/endpoint/params.rb b/lib/rspec_api_documentation/dsl/endpoint/params.rb index 020fbbb2..a5e07bf2 100644 --- a/lib/rspec_api_documentation/dsl/endpoint/params.rb +++ b/lib/rspec_api_documentation/dsl/endpoint/params.rb @@ -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 - p[: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]) @@ -49,7 +52,6 @@ def extended private attr_reader :extra_params - end end end