1 package com.networknt.schema; 2 3 import com.fasterxml.jackson.databind.JsonNode; 4 import com.fasterxml.jackson.databind.ObjectMapper; 5 import com.networknt.schema.walk.JsonSchemaWalkListener; 6 import com.networknt.schema.walk.WalkEvent; 7 import com.networknt.schema.walk.WalkFlow; 8 import org.junit.jupiter.api.Assertions; 9 import org.junit.jupiter.api.Test; 10 11 import java.io.IOException; 12 import java.net.URISyntaxException; 13 import java.util.Set; 14 15 public class Issue461Test { 16 protected ObjectMapper mapper = new ObjectMapper(); 17 getJsonSchemaFromStreamContentV7(SchemaLocation schemaUri)18 protected JsonSchema getJsonSchemaFromStreamContentV7(SchemaLocation schemaUri) { 19 JsonSchemaFactory factory = JsonSchemaFactory.getInstance(SpecVersion.VersionFlag.V7); 20 SchemaValidatorsConfig svc = new SchemaValidatorsConfig(); 21 svc.addKeywordWalkListener(ValidatorTypeCode.PROPERTIES.getValue(), new Walker()); 22 return factory.getSchema(schemaUri, svc); 23 } 24 25 @Test shouldWalkWithValidation()26 public void shouldWalkWithValidation() throws URISyntaxException, IOException { 27 JsonSchema schema = getJsonSchemaFromStreamContentV7(SchemaLocation.of("resource:/draft-07/schema#")); 28 JsonNode data = mapper.readTree(Issue461Test.class.getResource("/data/issue461-v7.json")); 29 ValidationResult result = schema.walk(data, true); 30 Assertions.assertTrue(result.getValidationMessages().isEmpty()); 31 } 32 33 /** 34 * Example NOP walker 35 */ 36 private static class Walker implements JsonSchemaWalkListener { 37 @Override onWalkStart(final WalkEvent walkEvent)38 public WalkFlow onWalkStart(final WalkEvent walkEvent) { 39 return WalkFlow.CONTINUE; 40 } 41 42 @Override onWalkEnd(final WalkEvent walkEvent, final Set<ValidationMessage> validationMessages)43 public void onWalkEnd(final WalkEvent walkEvent, 44 final Set<ValidationMessage> validationMessages) { 45 } 46 } 47 } 48