Skip to content

Commit f94930c

Browse files
authored
adding new walk method to start walking from a specific part of a given schema node (#629)
Co-authored-by: Prashanth Josyula <[email protected]>
1 parent 90275b5 commit f94930c

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/main/java/com/networknt/schema/JsonSchema.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,14 @@ private ValidationResult validateAndCollect(JsonNode jsonNode, JsonNode rootNode
400400
* @return result of ValidationResult
401401
*/
402402
public ValidationResult walk(JsonNode node, boolean shouldValidateSchema) {
403+
return walkAtNodeInternal(node, node, AT_ROOT, shouldValidateSchema);
404+
}
405+
406+
public ValidationResult walkAtNode(JsonNode node, JsonNode rootNode, String at, boolean shouldValidateSchema) {
407+
return walkAtNodeInternal(node, rootNode, at, shouldValidateSchema);
408+
}
409+
410+
private ValidationResult walkAtNodeInternal(JsonNode node, JsonNode rootNode, String at, boolean shouldValidateSchema) {
403411
try {
404412
// Get the config.
405413
SchemaValidatorsConfig config = validationContext.getConfig();
@@ -408,7 +416,7 @@ public ValidationResult walk(JsonNode node, boolean shouldValidateSchema) {
408416
// Set the walkEnabled flag in internal validator state.
409417
setValidatorState(true, shouldValidateSchema);
410418
// Walk through the schema.
411-
Set<ValidationMessage> errors = walk(node, node, AT_ROOT, shouldValidateSchema);
419+
Set<ValidationMessage> errors = walk(node, rootNode, at, shouldValidateSchema);
412420
// When walk is called in series of nested call we don't want to load the collectors every time. Leave to the API to decide when to call collectors.
413421
if (config.doLoadCollectors()) {
414422
// Load all the data from collectors into the context.

0 commit comments

Comments
 (0)