Merge pull request #78 from bertha-carl/fully-validate

Can we use JSON::Validator.fully_validate() to get better error messages?
This commit is contained in:
domaindrivendev
2017-07-20 10:09:01 -07:00
committed by GitHub

View File

@@ -40,13 +40,12 @@ module Rswag
response_schema = @api_metadata[:response][:schema] response_schema = @api_metadata[:response][:schema]
return if response_schema.nil? return if response_schema.nil?
begin validation_schema = response_schema
validation_schema = response_schema .merge('$schema' => 'http://tempuri.org/rswag/specs/extended_schema')
.merge('$schema' => 'http://tempuri.org/rswag/specs/extended_schema') .merge(@global_metadata.slice(:definitions))
.merge(@global_metadata.slice(:definitions)) error_messages = JSON::Validator.fully_validate(validation_schema, body)
JSON::Validator.validate!(validation_schema, body) if error_messages.any?
rescue JSON::Schema::ValidationError => ex raise UnexpectedResponse, "Expected response body to match schema: #{error_messages[0]}"
raise UnexpectedResponse, "Expected response body to match schema: #{ex.message}"
end end
end end
end end