Skip to content

Commit dd578a8

Browse files
committed
Forbid use of reserved parameter name
1 parent 3ad1ab7 commit dd578a8

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

lib/rspec_api_documentation/dsl/endpoint/set_param.rb

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,17 @@ module RspecApiDocumentation
22
module DSL
33
module Endpoint
44
class SetParam
5+
RESERVED_WORDS = %w(status)
6+
57
def initialize(parent, hash, param)
68
@parent = parent
79
@hash = hash
810
@param = param
11+
12+
if reserved_word?(key) && !custom_method_name
13+
raise ArgumentError, "Parameter name '#{key}' is reserved. " \
14+
"Please provide `method` argument with custom method name."
15+
end
916
end
1017

1118
def call
@@ -46,12 +53,16 @@ def path_params
4653

4754
def method_name
4855
@method_name ||= begin
49-
[custom_method_name, scoped_key, key].find do |name|
50-
name && example_group.respond_to?(name)
56+
[custom_method_name, scoped_key, key].compact.find do |name|
57+
example_group.respond_to?(name) && !reserved_word?(name)
5158
end
5259
end
5360
end
5461

62+
def reserved_word?(word)
63+
RESERVED_WORDS.include?(word.to_s)
64+
end
65+
5566
def build_param_hash(keys)
5667
value = keys[1] ? build_param_hash(keys[1..-1]) : example_group.send(method_name)
5768
{ keys[0].to_s => value }

0 commit comments

Comments
 (0)