Whitelisting with allOf seems to fail when there are two errors with same key

Issue #267 resolved
Arho Huttunen created an issue

I am using swagger-request-validator-mockmvc.
You would expect that the following whitelisting rule ignores only additional properties called links in the HTTP respose:

        val whitelist = ValidationErrorsWhitelist.create()
            .withRule(
                "Ignore additional properties for HATEOAS links",
                allOf(
                    messageHasKey("validation.response.body.schema.additionalProperties"),
                    messageContains("[\"links\"]"))
            )
        validator = OpenApiInteractionValidator.createFor("schema.json")
            .withWhitelist(whitelist)
            .build()

However, if there is an additional property called invalidField, the test still passes!

Here is the output of the validation without whitelisting:

com.atlassian.oai.validator.mockmvc.OpenApiMatchers$OpenApiValidationException: {
  "messages" : [ {
    "key" : "validation.response.body.schema.additionalProperties",
    "level" : "ERROR",
    "message" : "Object instance has properties which are not allowed by the schema: [\"links\"]",
    "context" : {
      "requestPath" : "/user",
      "responseStatus" : 200,
      "location" : "RESPONSE",
      "requestMethod" : "GET"
    }
  }, {
    "key" : "validation.response.body.schema.additionalProperties",
    "level" : "ERROR",
    "message" : "[Path '/content/0'] Object instance has properties which are not allowed by the schema: [\"invalidField\",\"links\"]",
    "context" : {
      "requestPath" : "/user",
      "responseStatus" : 200,
      "location" : "RESPONSE",
      "requestMethod" : "GET"
    }
  } ]
}

An actual bug, or is there something to be understood about the whitelisting behavior?

Comments (6)

  1. Arho Huttunen reporter

    Argh, I just realized that the matching is regex based and not just partial string match. The example code for this is a little confusing, because the regex looks very similar to the actual message text. It is accidentally possible to write a regex that matches when it should not! You might want to clarify the example a bit.

  2. James Navin

    I have improved the naming of the whitelist rules and added a basic substring matcher which might be useful to you. They are available in v2.10.1. I will mark this issue as resolved but feel free to re-open (or open a new one) if it does not address your problem.

  3. Log in to comment