Skip to content

Commit

Permalink
Merge pull request #369 from jsmestad/params-accept-value
Browse files Browse the repository at this point in the history
Parameters accept a value option for fixed values.
  • Loading branch information
oestrich authored Jan 24, 2018
2 parents 4cfef51 + b5fd1f1 commit 8f6c458
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
10 changes: 5 additions & 5 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -65,19 +65,19 @@ GEM
sparkr (>= 0.2.0)
term-ansicolor
yard (~> 0.8.7.5)
json (1.8.3)
json (1.8.6)
method_source (0.8.2)
mime-types (3.0)
mime-types-data (~> 3.2015)
mime-types-data (3.2015.1120)
mini_portile2 (2.0.0)
mini_portile2 (2.3.0)
minitest (5.8.4)
multi_json (1.11.2)
multi_test (0.1.2)
multipart-post (2.0.0)
mustache (1.0.3)
nokogiri (1.6.7.2)
mini_portile2 (~> 2.0.0.rc2)
nokogiri (1.8.1)
mini_portile2 (~> 2.3.0)
pry (0.10.3)
coderay (~> 1.1.0)
method_source (~> 0.8.1)
Expand Down Expand Up @@ -157,4 +157,4 @@ DEPENDENCIES
webmock (~> 1.7)

BUNDLED WITH
1.15.3
1.16.1
9 changes: 8 additions & 1 deletion lib/rspec_api_documentation/dsl/endpoint/set_param.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ def custom_method_name
param[:method]
end

def set_value
param[:value]
end

def path_name
scoped_key || key
end
Expand All @@ -51,11 +55,14 @@ def method_name
scoped_key
elsif key && example_group.respond_to?(key)
key
elsif key && set_value
key
end
end

def build_param_hash(keys)
value = keys[1] ? build_param_hash(keys[1..-1]) : example_group.send(method_name)
value = param[:value] if param.has_key?(:value)
value ||= keys[1] ? build_param_hash(keys[1..-1]) : example_group.send(method_name)
{ keys[0].to_s => value }
end
end
Expand Down
5 changes: 4 additions & 1 deletion spec/dsl_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
parameter :size, "The size of drink you want.", :required => true
parameter :note, "Any additional notes about your order.", method: :custom_note
parameter :name, :scope => :order, method: :custom_order_name
parameter :quantity, "The quantity of drinks you want.", value: '3'

response_field :type, "The type of drink you ordered.", :scope => :order
response_field :size, "The size of drink you ordered.", :scope => :order
Expand All @@ -88,6 +89,7 @@
{ :name => "size", :description => "The size of drink you want.", :required => true },
{ :name => "note", :description => "Any additional notes about your order.", method: :custom_note },
{ :name => "name", :description => "Order name", :scope => :order, method: :custom_order_name },
{ :name => "quantity", :description => "The quantity of drinks you want.", value: '3' }
]
)
end
Expand All @@ -114,7 +116,8 @@
"type" => "coffee",
"size" => "medium",
"note" => "Made in India",
"order" => { "name" => "Jakobz" }
"order" => { "name" => "Jakobz" },
"quantity" => "3"
})
end
end
Expand Down

0 comments on commit 8f6c458

Please sign in to comment.