22
22
23
23
import java .util .*;
24
24
25
- public class DependentSchemas extends BaseJsonValidator implements JsonValidator {
25
+ public class DependentSchemas extends BaseJsonValidator {
26
26
private static final Logger logger = LoggerFactory .getLogger (DependentSchemas .class );
27
- private final Map <String , JsonSchema > schemaDependencies = new HashMap <String , JsonSchema >();
27
+ private final Map <String , JsonSchema > schemaDependencies = new HashMap <>();
28
28
29
29
public DependentSchemas (String schemaPath , JsonNode schemaNode , JsonSchema parentSchema , ValidationContext validationContext ) {
30
30
@@ -34,21 +34,22 @@ public DependentSchemas(String schemaPath, JsonNode schemaNode, JsonSchema paren
34
34
String pname = it .next ();
35
35
JsonNode pvalue = schemaNode .get (pname );
36
36
if (pvalue .isObject () || pvalue .isBoolean ()) {
37
- schemaDependencies .put (pname , validationContext .newSchema (pname , pvalue , parentSchema ));
37
+ this . schemaDependencies .put (pname , validationContext .newSchema (pname , pvalue , parentSchema ));
38
38
}
39
39
}
40
40
41
41
parseErrorCode (getValidatorType ().getErrorCodeKey ());
42
42
}
43
43
44
+ @ Override
44
45
public Set <ValidationMessage > validate (JsonNode node , JsonNode rootNode , String at ) {
45
46
debug (logger , node , rootNode , at );
46
47
47
- Set <ValidationMessage > errors = new LinkedHashSet <ValidationMessage >();
48
+ Set <ValidationMessage > errors = new LinkedHashSet <>();
48
49
49
50
for (Iterator <String > it = node .fieldNames (); it .hasNext (); ) {
50
51
String pname = it .next ();
51
- JsonSchema schema = schemaDependencies .get (pname );
52
+ JsonSchema schema = this . schemaDependencies .get (pname );
52
53
if (schema != null ) {
53
54
errors .addAll (schema .validate (node , rootNode , at ));
54
55
}
@@ -59,6 +60,18 @@ public Set<ValidationMessage> validate(JsonNode node, JsonNode rootNode, String
59
60
60
61
@ Override
61
62
public void preloadJsonSchema () {
62
- preloadJsonSchemas (schemaDependencies .values ());
63
+ preloadJsonSchemas (this . schemaDependencies .values ());
63
64
}
65
+
66
+ @ Override
67
+ public Set <ValidationMessage > walk (JsonNode node , JsonNode rootNode , String at , boolean shouldValidateSchema ) {
68
+ if (shouldValidateSchema ) {
69
+ return validate (node , rootNode , at );
70
+ }
71
+ for (JsonSchema schema : this .schemaDependencies .values ()) {
72
+ schema .walk (node , rootNode , at , false );
73
+ }
74
+ return Collections .emptySet ();
75
+ }
76
+
64
77
}
0 commit comments