Skip to content

Commit

Permalink
Make content_type case insensitive (#178)
Browse files Browse the repository at this point in the history
  • Loading branch information
gjkliewer authored Nov 21, 2024
1 parent b88556b commit 32514e7
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/openapi_parser/request_operation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
21 changes: 21 additions & 0 deletions spec/openapi_parser/request_operation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 32514e7

Please sign in to comment.