Toggle request and/or response validation

Issue #262 resolved
Former user created an issue

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)

  1. Markus Ratzer

    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 the OpenApiValidationFilter:

    new OpenApiValidationFilter(OpenApiInteractionValidator
            .createFor(API_URL)
            .withLevelResolver(
                    LevelResolver.create()
                            .withLevel("validation.request", ValidationReport.Level.IGNORE)
                            .build())
            .build());
    

    Therefore this ticket can be closed; I’d have deleted it myself if I had created it with a regular account.

  2. James Navin

    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.

  3. testing01210

    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?

  4. Log in to comment