diff --git a/lib/rspec_api_documentation/dsl/endpoint.rb b/lib/rspec_api_documentation/dsl/endpoint.rb index 64f939ee..9dc91222 100644 --- a/lib/rspec_api_documentation/dsl/endpoint.rb +++ b/lib/rspec_api_documentation/dsl/endpoint.rb @@ -38,13 +38,13 @@ def do_request(extra_params = {}) if method == :get && !query_string.blank? path_or_query += "?#{query_string}" else - if respond_to?(:raw_post) + if respond_to?(:raw_post) params_or_body = raw_post else formatter = RspecApiDocumentation.configuration.post_body_formatter case formatter when :json - params_or_body = params.to_json + params_or_body = params.empty? ? nil : params.to_json when :xml params_or_body = params.to_xml when Proc diff --git a/spec/dsl_spec.rb b/spec/dsl_spec.rb index a5509c86..b1c5ffa3 100644 --- a/spec/dsl_spec.rb +++ b/spec/dsl_spec.rb @@ -477,6 +477,18 @@ RspecApiDocumentation.instance_variable_set(:@configuration, RspecApiDocumentation::Configuration.new) end + get "/orders" do + specify "formatting by json without parameters" do + RspecApiDocumentation.configure do |config| + config.post_body_formatter = :json + end + + expect(client).to receive(method).with(path, nil, nil) + + do_request + end + end + post "/orders" do parameter :page, "Page to view"