-
Notifications
You must be signed in to change notification settings - Fork 329
Closed
Description
Issue found in version 1.5.8 and likely related to the fix provided in #1169.
Sort of similar to the issue a raised a few days ago #1177 , but now it is the walk
method failing to validate required properties when the validate
function works as expected.
The scenario is a json schema with a required property that is not existent in the json node payload. The validate
function will correctly raise an error message (": required property 'USER_NAME' not found") but the walk
method doesn't find any validation issues.
See sample unit test below:
@Test
fun `test validate vs walk-validate`() {
val simpleSchema = """
{
"properties" : {
"USER_NAME" : {
"description" : "User name",
"type" : "string",
"default" : "JohnDoe"
},
"VALIDATE" : {
"type" : "boolean"
},
"REASON" : {
"oneOf" : [ {
"type" : "object",
"properties" : {
"TEXT" : {
"type" : "string"
}
}
}, {
"type" : "null"
} ]
}
},
"required" : [ "VALIDATE", "USER_NAME" ],
"additionalProperties" : true,
"description" : "Test",
"title": "Test",
"${'$'}defs" : { },
"type" : "object"
}
""".trimIndent()
val simplePayload = """
{
"VALIDATE": true
}
""".trimIndent()
val config = SchemaValidatorsConfig.builder()
.applyDefaultsStrategy(
ApplyDefaultsStrategy(true, true, true)
)
.build()
val schemaFactory = JsonSchemaFactory.getInstance(SpecVersion.VersionFlag.V201909)
val schema = schemaFactory.getSchema(simpleSchema, config)
val objectMapper = ObjectMapper()
val jsonNode = objectMapper.readTree(simplePayload) as ObjectNode
val validationResult = schema.validate(jsonNode)
assertEquals(1, validationResult.size)
assertEquals(": required property 'USER_NAME' not found", validationResult.first().message)// Works as expected and has one error
val walkValidation = schema.walk(jsonNode, true)
assertEquals(1, walkValidation.validationMessages.size) // The walk method now doesn't detect any issues!!!!
}
Metadata
Metadata
Assignees
Labels
No labels