Merge pull request #406 from mynnx/specs-print-failed-body

Show the response body for comparison when schema checks fail
This commit is contained in:
Blake Erickson
2021-03-06 09:30:48 -07:00
committed by GitHub

View File

@@ -50,7 +50,11 @@ module Rswag
.merge(schemas) .merge(schemas)
errors = JSON::Validator.fully_validate(validation_schema, body) 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 end
def definitions_or_component_schemas(swagger_doc, version) def definitions_or_component_schemas(swagger_doc, version)