From c531c9af2a91080b5e0d4b5bd6028e0345a57469 Mon Sep 17 00:00:00 2001 From: Josh Lane Date: Wed, 23 Sep 2015 09:49:55 -0700 Subject: [PATCH] infer response_field description from name + scope --- lib/rspec_api_documentation/dsl/resource.rb | 16 ++++++++++------ spec/dsl_spec.rb | 2 ++ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/lib/rspec_api_documentation/dsl/resource.rb b/lib/rspec_api_documentation/dsl/resource.rb index 98db83e7..4da33e53 100644 --- a/lib/rspec_api_documentation/dsl/resource.rb +++ b/lib/rspec_api_documentation/dsl/resource.rb @@ -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) @@ -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]) diff --git a/spec/dsl_spec.rb b/spec/dsl_spec.rb index a03ed1c4..fde7f2c4 100644 --- a/spec/dsl_spec.rb +++ b/spec/dsl_spec.rb @@ -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" } @@ -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" }, ] )