Skip to content
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
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