mirror of
https://github.com/ditkrg/rswag.git
synced 2026-01-25 07:16:40 +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:
@@ -28,15 +28,10 @@ module Rswag
|
|||||||
def validate_headers!(headers)
|
def validate_headers!(headers)
|
||||||
header_schema = @api_metadata[:response][:headers]
|
header_schema = @api_metadata[:response][:headers]
|
||||||
return if header_schema.nil?
|
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)
|
header_schema.keys.each do |header_name|
|
||||||
JSON::Validator.validate!(schema.merge(@global_metadata), header_value.to_json)
|
raise UnexpectedResponse, "Expected response header #{header_name} to be present" if headers[header_name.to_s].nil?
|
||||||
rescue JSON::Schema::ValidationError => ex
|
end
|
||||||
raise UnexpectedResponse, "Expected response headers #{header_name} to match schema: #{ex.message}"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def validate_body!(body)
|
def validate_body!(body)
|
||||||
|
|||||||
@@ -96,9 +96,8 @@ module Rswag
|
|||||||
|
|
||||||
context 'response code matches & body does not' do
|
context 'response code matches & body does not' do
|
||||||
let(:response) { OpenStruct.new(code: 200, body: '{}', headers: {
|
let(:response) { OpenStruct.new(code: 200, body: '{}', headers: {
|
||||||
'X-Rate-Limit-Limit' => 'invalid',
|
'X-Rate-Limit-Limit' => 1,
|
||||||
'X-Rate-Limit-Remaining' => 'invalid',
|
'X-Rate-Limit-Remaining' => 1
|
||||||
'X-Rate-Limit-Reset' => 'invalid'
|
|
||||||
}) }
|
}) }
|
||||||
it { expect { call }.to raise_error UnexpectedResponse }
|
it { expect { call }.to raise_error UnexpectedResponse }
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user