Skip to content

Commit 8f6c458

Browse files
authored
Merge pull request #369 from jsmestad/params-accept-value
Parameters accept a value option for fixed values.
2 parents 4cfef51 + b5fd1f1 commit 8f6c458

File tree

3 files changed

+17
-7
lines changed

3 files changed

+17
-7
lines changed

Gemfile.lock

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,19 +65,19 @@ GEM
6565
sparkr (>= 0.2.0)
6666
term-ansicolor
6767
yard (~> 0.8.7.5)
68-
json (1.8.3)
68+
json (1.8.6)
6969
method_source (0.8.2)
7070
mime-types (3.0)
7171
mime-types-data (~> 3.2015)
7272
mime-types-data (3.2015.1120)
73-
mini_portile2 (2.0.0)
73+
mini_portile2 (2.3.0)
7474
minitest (5.8.4)
7575
multi_json (1.11.2)
7676
multi_test (0.1.2)
7777
multipart-post (2.0.0)
7878
mustache (1.0.3)
79-
nokogiri (1.6.7.2)
80-
mini_portile2 (~> 2.0.0.rc2)
79+
nokogiri (1.8.1)
80+
mini_portile2 (~> 2.3.0)
8181
pry (0.10.3)
8282
coderay (~> 1.1.0)
8383
method_source (~> 0.8.1)
@@ -157,4 +157,4 @@ DEPENDENCIES
157157
webmock (~> 1.7)
158158

159159
BUNDLED WITH
160-
1.15.3
160+
1.16.1

lib/rspec_api_documentation/dsl/endpoint/set_param.rb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ def custom_method_name
3636
param[:method]
3737
end
3838

39+
def set_value
40+
param[:value]
41+
end
42+
3943
def path_name
4044
scoped_key || key
4145
end
@@ -51,11 +55,14 @@ def method_name
5155
scoped_key
5256
elsif key && example_group.respond_to?(key)
5357
key
58+
elsif key && set_value
59+
key
5460
end
5561
end
5662

5763
def build_param_hash(keys)
58-
value = keys[1] ? build_param_hash(keys[1..-1]) : example_group.send(method_name)
64+
value = param[:value] if param.has_key?(:value)
65+
value ||= keys[1] ? build_param_hash(keys[1..-1]) : example_group.send(method_name)
5966
{ keys[0].to_s => value }
6067
end
6168
end

spec/dsl_spec.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
parameter :size, "The size of drink you want.", :required => true
6363
parameter :note, "Any additional notes about your order.", method: :custom_note
6464
parameter :name, :scope => :order, method: :custom_order_name
65+
parameter :quantity, "The quantity of drinks you want.", value: '3'
6566

6667
response_field :type, "The type of drink you ordered.", :scope => :order
6768
response_field :size, "The size of drink you ordered.", :scope => :order
@@ -88,6 +89,7 @@
8889
{ :name => "size", :description => "The size of drink you want.", :required => true },
8990
{ :name => "note", :description => "Any additional notes about your order.", method: :custom_note },
9091
{ :name => "name", :description => "Order name", :scope => :order, method: :custom_order_name },
92+
{ :name => "quantity", :description => "The quantity of drinks you want.", value: '3' }
9193
]
9294
)
9395
end
@@ -114,7 +116,8 @@
114116
"type" => "coffee",
115117
"size" => "medium",
116118
"note" => "Made in India",
117-
"order" => { "name" => "Jakobz" }
119+
"order" => { "name" => "Jakobz" },
120+
"quantity" => "3"
118121
})
119122
end
120123
end

0 commit comments

Comments
 (0)