Whitelisted error messages still appear in Validation Report

Issue #356 new
Former user created an issue

Hi Team,

I have ignored a particular validation using whitelisting as follows:

@Bean
public OpenApiInteractionValidator openApiResponseInteractionValidator() {
    io.swagger.util.Json.mapper().registerModule(new JavaTimeModule());

    return OpenApiInteractionValidator
            .createFor(specLocation)
            .withLevelResolver(
                    // The key here is to use the level resolver to ignore the request validation messages
                    // Without this they would be emitted at ERROR level and cause a validation failure.
                    LevelResolver.create()
                            .withLevel("validation.request", IGNORE)
                            .build()
            )
           ** .withWhitelist(ValidationErrorsWhitelist.create()
                    .withRule(
                            "Ignore null values for string primitive type",
                            messageContainsRegexp(
                                    ".* Instance type \\(null\\) does not match any allowed primitive type \\(allowed\\: \\[\"string\"\\]\\)")
                    )**
            )
            .build();
}

However the error messages still appears in the response as follows:

{
    "key": "validation.response.body.schema.type",
    "level": "IGNORE",
    "message": "[Path '/xx/xxx'] Instance type (null) does not match any allowed primitive type (allowed: [\"string\"])",
    "additionalInfo": [],
    "nestedMessages": [],
    "context": {
        "requestPath": "/xx/xxx",
        "parameter": null,
        "apiRequestContentType": null,
        "responseStatus": null,
        "location": null,
        "pointers": null,
        "requestMethod": "POST",
        "appliedWhitelistRule": {
            "name": "Ignore null values for string primitive type"
        }
    }
}

I want to hide it from the validation report

Comments (2)

  1. James Navin

    This is by design. The philosophy is to include as much information in the validation report as possible, with messages assigned a level that can be used to determine the severity.

    In this case the whitelist rule is marking the message as level: IGNORE.

    You can create a new validation report with filtered messages using something like:

    ValidationReport.from(report.getMessages().stream().filter(m -> m.getLevel() != IGNORE).collect(Collectors.toList()));
    

    If you wanted to expand the ValidationReport interface to support returning a filtered list of message (basically syntactic sugar for ^^) I would happily review a PR.

  2. Log in to comment