Commit cdbca3a8 by andrew morton

Use root consumes/produces if not specified in operation

parent d2c108e3
......@@ -204,11 +204,13 @@ module RSpec
end
def resolve_produces metadata
metadata[:swagger_operation][:produces]
document = resolve_document metadata
metadata[:swagger_operation][:produces] || document[:produces]
end
def resolve_consumes metadata
metadata[:swagger_operation][:consumes]
document = resolve_document metadata
metadata[:swagger_operation][:consumes] || document[:consumes]
end
def resolve_headers metadata
......
......@@ -235,19 +235,38 @@ RSpec.describe RSpec::Swagger::Helpers::Resolver do
end
describe "#resolve_headers", :swagger_object do
context "with consumes set" do
let(:metadata) { {swagger_operation: {consumes: ['application/json']}} }
context "with consumes/produces in the operation" do
let(:metadata) do
{swagger_operation: {consumes: ['application/json'], produces: ['application/xml']}}
end
before do
allow(self).to receive(:resolve_document) { {} }
end
it "sets the Content-Type header" do
expect(resolve_headers(metadata)).to include('CONTENT_TYPE' => 'application/json')
end
it "sets the Accepts header" do
expect(resolve_headers(metadata)).to include('HTTP_ACCEPT' => 'application/xml')
end
end
context "with produces set" do
let(:metadata) { {swagger_operation: {produces: ['application/xml']}} }
context "with consumes/produces in the document" do
let(:metadata) { {swagger_document: 'test.json', swagger_operation: {}} }
before do
allow(self).to receive(:resolve_document) do
{ consumes: ['text/plain; charset=utf-8'],
produces: ['application/vnd.github.v3.raw+json']}
end
end
it "sets the Content-Type header" do
expect(resolve_headers(metadata)).to include('CONTENT_TYPE' => 'text/plain; charset=utf-8')
end
it "sets the Accepts header" do
expect(resolve_headers(metadata)).to include('HTTP_ACCEPT' => 'application/xml')
expect(resolve_headers(metadata)).to include('HTTP_ACCEPT' => 'application/vnd.github.v3.raw+json')
end
end
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment