From a34c931bb6b2f7097340792313d9555a9419e7bd Mon Sep 17 00:00:00 2001 From: mynnx Date: Wed, 3 Mar 2021 16:32:16 -0800 Subject: [PATCH] Show the response body for comparison when schema checks fail --- rswag-specs/lib/rswag/specs/response_validator.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/rswag-specs/lib/rswag/specs/response_validator.rb b/rswag-specs/lib/rswag/specs/response_validator.rb index 2c54874..b09d44a 100644 --- a/rswag-specs/lib/rswag/specs/response_validator.rb +++ b/rswag-specs/lib/rswag/specs/response_validator.rb @@ -50,7 +50,11 @@ module Rswag .merge(schemas) errors = JSON::Validator.fully_validate(validation_schema, body) - raise UnexpectedResponse, "Expected response body to match schema: #{errors[0]}" if errors.any? + return unless errors.any? + + raise UnexpectedResponse, + "Expected response body to match schema: #{errors[0]}\n" \ + "Response body: #{JSON.pretty_generate(JSON.parse(body))}" end def definitions_or_component_schemas(swagger_doc, version)