diff --git a/lib/openapi_parser/request_operation.rb b/lib/openapi_parser/request_operation.rb index d0312b9..2746ce4 100644 --- a/lib/openapi_parser/request_operation.rb +++ b/lib/openapi_parser/request_operation.rb @@ -78,7 +78,8 @@ def initialize(status_code, response_data, headers) end def content_type - headers['Content-Type'].to_s.split(';').first.to_s + content_type_key = headers.keys.detect { |k| k.casecmp?('Content-Type') } + headers[content_type_key].to_s.split(';').first.to_s end end end diff --git a/spec/openapi_parser/request_operation_spec.rb b/spec/openapi_parser/request_operation_spec.rb index 71de301..28ca6a2 100644 --- a/spec/openapi_parser/request_operation_spec.rb +++ b/spec/openapi_parser/request_operation_spec.rb @@ -216,3 +216,24 @@ end end end + +RSpec.describe OpenAPIParser::RequestOperation::ValidatableResponseBody do + describe '#content_type' do + context 'when key is lowercase' do + let(:headers) { {"content-type" => "application/json"} } + it 'finds the key' do + expect( + OpenAPIParser::RequestOperation::ValidatableResponseBody.new(nil, nil, headers).content_type + ).to eq "application/json" + end + end + context 'when key is mixed case' do + let(:headers) { {"Content-Type" => "application/json"} } + it 'finds the key' do + expect( + OpenAPIParser::RequestOperation::ValidatableResponseBody.new(nil, nil, headers).content_type + ).to eq "application/json" + end + end + end +end