Toggle request and/or response validation
I'm writing tests where I also want to verify an API's error responses (with RestAssured). For these scenarios I need to send known but invalid requests (e.g. missing some property) which currently results in OpenApiValidationExceptions for the requests. It'd be nice to have an option to disable request validation in these cases. It might come handy to also be able to toggle response validation, e.g. when testing against ill behaving client mocks or similar.
Comments (4)
-
-
- changed status to resolved
-
Yep - that’s the best way to achieve that. I might add that to the FAQs - seems to be something people have wanted to do a few times.
-
Let me just throw another question here. What if you also want to avoid request body schema validation? I’ve tried several ways and don’t get to do it. If you do like this:
.withLevelResolver( LevelResolver.create() .withLevel("validation.schema", ValidationReport.Level.WARN) .build() )
It will disable both request and response body validation. On the other hand, if you do like this:
.withWhitelist( ValidationErrorsWhitelist.create() .withRule( "Do not consider request schema validation errors as failures", allOf( isRequest(), anyOf( // All validation keywords from JSON schema: messageHasKey("validation.schema.required"), messageHasKey("validation.schema.type"), messageHasKey("validation.schema.enum"), // ... all JSON schema keywords here ... )
It will, again, whitelist both request and response errors.
Is there any way to validate ONLY response body schema?
- Log in to comment
I’ve created this issue (before I had a regular account) but I’ve found out that this can be easily be done by a custom configured
OpenApiInteractionValidator
which can be passed to theOpenApiValidationFilter
:
Therefore this ticket can be closed; I’d have deleted it myself if I had created it with a regular account.