Skip to content

infer parameter description from name and scope #225

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

Merged
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
9 changes: 6 additions & 3 deletions lib/rspec_api_documentation/dsl/resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module Resource
module ClassMethods
def self.define_action(method)
define_method method do |*args, &block|
options = if args.last.is_a?(Hash) then args.pop else {} end
options = args.extract_options!
options[:method] = method
options[:route] = args.first
options[:api_doc_dsl] = :endpoint
Expand Down Expand Up @@ -38,7 +38,10 @@ def callback(*args, &block)
context(*args, &block)
end

def parameter(name, description, options = {})
def parameter(name, *args)
options = args.extract_options!
description = args.pop || "#{Array(options[:scope]).join(" ")} #{name}".humanize

parameters.push(options.merge(:name => name.to_s, :description => description))
end

Expand Down Expand Up @@ -89,7 +92,7 @@ def no_doc(&block)
requests = example.metadata[:requests]
example.metadata[:requests] = []

instance_eval &block
instance_eval(&block)

example.metadata[:requests] = requests
end
Expand Down
4 changes: 3 additions & 1 deletion spec/dsl_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
parameter :type, "The type of drink you want.", :required => true
parameter :size, "The size of drink you want.", :required => true
parameter :note, "Any additional notes about your order."
parameter :name, :scope => :order

response_field :type, "The type of drink you ordered.", :scope => :order
response_field :size, "The size of drink you ordered.", :scope => :order
Expand All @@ -74,7 +75,8 @@
[
{ :name => "type", :description => "The type of drink you want.", :required => true },
{ :name => "size", :description => "The size of drink you want.", :required => true },
{ :name => "note", :description => "Any additional notes about your order." }
{ :name => "note", :description => "Any additional notes about your order." },
{ :name => "name", :description => "Order name", :scope => :order},
]
)
end
Expand Down