Skip to content

Commit

Permalink
adding new walk method to start walking from a specific part of a giv…
Browse files Browse the repository at this point in the history
…en schema node (#629)

Co-authored-by: Prashanth Josyula <prashanth.chaitanya@prashan-wsmtedt.internal.salesforce.com>
  • Loading branch information
prashanthjos and prashanthjos committed Dec 19, 2022
1 parent 90275b5 commit f94930c
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/main/java/com/networknt/schema/JsonSchema.java
Expand Up @@ -400,6 +400,14 @@ private ValidationResult validateAndCollect(JsonNode jsonNode, JsonNode rootNode
* @return result of ValidationResult
*/
public ValidationResult walk(JsonNode node, boolean shouldValidateSchema) {
return walkAtNodeInternal(node, node, AT_ROOT, shouldValidateSchema);
}

public ValidationResult walkAtNode(JsonNode node, JsonNode rootNode, String at, boolean shouldValidateSchema) {
return walkAtNodeInternal(node, rootNode, at, shouldValidateSchema);
}

private ValidationResult walkAtNodeInternal(JsonNode node, JsonNode rootNode, String at, boolean shouldValidateSchema) {
try {
// Get the config.
SchemaValidatorsConfig config = validationContext.getConfig();
Expand All @@ -408,7 +416,7 @@ public ValidationResult walk(JsonNode node, boolean shouldValidateSchema) {
// Set the walkEnabled flag in internal validator state.
setValidatorState(true, shouldValidateSchema);
// Walk through the schema.
Set<ValidationMessage> errors = walk(node, node, AT_ROOT, shouldValidateSchema);
Set<ValidationMessage> errors = walk(node, rootNode, at, shouldValidateSchema);
// 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.
if (config.doLoadCollectors()) {
// Load all the data from collectors into the context.
Expand Down

0 comments on commit f94930c

Please sign in to comment.