diff --git a/lib/rspec_api_documentation.rb b/lib/rspec_api_documentation.rb index a8a5ce6f..7066409b 100644 --- a/lib/rspec_api_documentation.rb +++ b/lib/rspec_api_documentation.rb @@ -1,6 +1,7 @@ require 'active_support' require 'active_support/inflector' require 'active_support/core_ext/hash/conversions' +require 'active_support/core_ext/hash/deep_merge' require 'cgi' require 'json' diff --git a/lib/rspec_api_documentation/dsl/endpoint.rb b/lib/rspec_api_documentation/dsl/endpoint.rb index 9dc91222..b30365e1 100644 --- a/lib/rspec_api_documentation/dsl/endpoint.rb +++ b/lib/rspec_api_documentation/dsl/endpoint.rb @@ -66,7 +66,7 @@ def params parameters = example.metadata.fetch(:parameters, {}).inject({}) do |hash, param| set_param(hash, param) end - parameters.merge!(extra_params) + parameters.deep_merge!(extra_params) parameters end @@ -128,6 +128,7 @@ def rspec_api_documentation_client def extra_params return {} if @extra_params.nil? @extra_params.inject({}) do |h, (k, v)| + v = v.is_a?(Hash) ? v.stringify_keys : v h[k.to_s] = v h end diff --git a/spec/dsl_spec.rb b/spec/dsl_spec.rb index b1c5ffa3..2cf04ac2 100644 --- a/spec/dsl_spec.rb +++ b/spec/dsl_spec.rb @@ -362,6 +362,9 @@ context "auto request" do post "/orders" do parameter :order_type, "Type of order" + parameter :amount, "Amount of order", scope: :order + parameter :name, "Name of order", scope: :order + context "no extra params" do before do @@ -382,6 +385,17 @@ example_request "should take an optional parameter hash", :order_type => "big" end + + context "extra options for do_request with scoped hash" do + before do + expect(client).to receive(:post).with("/orders", {"order_type" => "big", "order" => {"amount" => "19.99", "name" => "Friday Order"}}, nil) + end + + let(:amount) { '19.99' } + let(:name) { 'Monday Order' } + + example_request "should deep merge the optional parameter hash", {:order_type => 'big', :order => {:name => 'Friday Order'}} + end end end