Skip to content

Commit

Permalink
Merge pull request #226 from engineyard/infer-simple-parameter-descri…
Browse files Browse the repository at this point in the history
…ptions

infer response_field description from name + scope
  • Loading branch information
oestrich committed Oct 21, 2015
2 parents 2c8f4df + c531c9a commit b3b0eba
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
16 changes: 10 additions & 6 deletions lib/rspec_api_documentation/dsl/resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,11 @@ def callback(*args, &block)
end

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))
parameters.push(field_specification(name, *args))
end

def response_field(name, description, options = {})
response_fields.push(options.merge(:name => name.to_s, :description => description))
def response_field(name, *args)
response_fields.push(field_specification(name, *args))
end

def header(name, value)
Expand All @@ -55,6 +52,13 @@ def header(name, value)

private

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

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

def safe_metadata(field, default)
metadata[field] ||= default
if superclass_metadata && metadata[field].equal?(superclass_metadata[field])
Expand Down
2 changes: 2 additions & 0 deletions spec/dsl_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
response_field :type, "The type of drink you ordered.", :scope => :order
response_field :size, "The size of drink you ordered.", :scope => :order
response_field :note, "Any additional notes about your order.", :scope => :order
response_field :name, :scope => :order
response_field :id, "The order id"

let(:type) { "coffee" }
Expand All @@ -87,6 +88,7 @@
{ :name => "type", :description => "The type of drink you ordered.", :scope => :order },
{ :name => "size", :description => "The size of drink you ordered.", :scope => :order },
{ :name => "note", :description => "Any additional notes about your order.", :scope => :order },
{ :name => "name", :description => "Order name", :scope => :order },
{ :name => "id", :description => "The order id" },
]
)
Expand Down

0 comments on commit b3b0eba

Please sign in to comment.