mirror of
https://github.com/ditkrg/rswag.git
synced 2026-01-23 06:16:42 +00:00
Simplify response header validation
Change to checks for the presence of required headers instead of using JSON::Validator
This commit is contained in:
parent
9d4069bcfe
commit
64b0de494f
@ -28,15 +28,10 @@ module Rswag
|
||||
def validate_headers!(headers)
|
||||
header_schema = @api_metadata[:response][:headers]
|
||||
return if header_schema.nil?
|
||||
header_schema.each do |header_name, schema|
|
||||
validate_header!(schema, header_name, headers[header_name.to_s])
|
||||
end
|
||||
end
|
||||
|
||||
def validate_header!(schema, header_name, header_value)
|
||||
JSON::Validator.validate!(schema.merge(@global_metadata), header_value.to_json)
|
||||
rescue JSON::Schema::ValidationError => ex
|
||||
raise UnexpectedResponse, "Expected response headers #{header_name} to match schema: #{ex.message}"
|
||||
header_schema.keys.each do |header_name|
|
||||
raise UnexpectedResponse, "Expected response header #{header_name} to be present" if headers[header_name.to_s].nil?
|
||||
end
|
||||
end
|
||||
|
||||
def validate_body!(body)
|
||||
|
||||
@ -96,9 +96,8 @@ module Rswag
|
||||
|
||||
context 'response code matches & body does not' do
|
||||
let(:response) { OpenStruct.new(code: 200, body: '{}', headers: {
|
||||
'X-Rate-Limit-Limit' => 'invalid',
|
||||
'X-Rate-Limit-Remaining' => 'invalid',
|
||||
'X-Rate-Limit-Reset' => 'invalid'
|
||||
'X-Rate-Limit-Limit' => 1,
|
||||
'X-Rate-Limit-Remaining' => 1
|
||||
}) }
|
||||
it { expect { call }.to raise_error UnexpectedResponse }
|
||||
end
|
||||
|
||||
Loading…
Reference in New Issue
Block a user