Whitelisting with allOf seems to fail when there are two errors with same key
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)
-
reporter -
reporter - edited description
-
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.
-
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.
-
- changed status to resolved
-
reporter Great, thank you. It does simplify a few things.
- Log in to comment
I tried adding complete garbage into
messageContains()
and the test still passes.