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

Parameters accept a value option for fixed values. #369

Merged
merged 1 commit into from
Jan 24, 2018
Merged
Show file tree
Hide file tree
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
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