@@ -29,21 +29,24 @@ public class ItemsValidator extends BaseJsonValidator implements JsonValidator {
29
29
private static final Logger logger = LoggerFactory .getLogger (ItemsValidator .class );
30
30
private static final String PROPERTY_ADDITIONAL_ITEMS = "additionalItems" ;
31
31
32
- private JsonSchema schema ;
33
- private List <JsonSchema > tupleSchema ;
32
+ private final JsonSchema schema ;
33
+ private final List <JsonSchema > tupleSchema ;
34
34
private boolean additionalItems = true ;
35
- private JsonSchema additionalSchema ;
36
- private WalkListenerRunner arrayItemWalkListenerRunner ;
37
- private ValidationContext validationContext ;
35
+ private final JsonSchema additionalSchema ;
36
+ private final WalkListenerRunner arrayItemWalkListenerRunner ;
37
+ private final ValidationContext validationContext ;
38
38
39
39
public ItemsValidator (String schemaPath , JsonNode schemaNode , JsonSchema parentSchema ,
40
40
ValidationContext validationContext ) {
41
41
super (schemaPath , schemaNode , parentSchema , ValidatorTypeCode .ITEMS , validationContext );
42
+ tupleSchema = new ArrayList <JsonSchema >();
43
+ JsonSchema foundSchema = null ;
44
+ JsonSchema foundAdditionalSchema = null ;
45
+
42
46
if (schemaNode .isObject () || schemaNode .isBoolean ()) {
43
- schema = new JsonSchema (validationContext , schemaPath , parentSchema .getCurrentUri (), schemaNode ,
47
+ foundSchema = new JsonSchema (validationContext , schemaPath , parentSchema .getCurrentUri (), schemaNode ,
44
48
parentSchema );
45
49
} else {
46
- tupleSchema = new ArrayList <JsonSchema >();
47
50
for (JsonNode s : schemaNode ) {
48
51
tupleSchema .add (
49
52
new JsonSchema (validationContext , schemaPath , parentSchema .getCurrentUri (), s , parentSchema ));
@@ -54,7 +57,7 @@ public ItemsValidator(String schemaPath, JsonNode schemaNode, JsonSchema parentS
54
57
if (addItemNode .isBoolean ()) {
55
58
additionalItems = addItemNode .asBoolean ();
56
59
} else if (addItemNode .isObject ()) {
57
- additionalSchema = new JsonSchema (validationContext , parentSchema .getCurrentUri (), addItemNode );
60
+ foundAdditionalSchema = new JsonSchema (validationContext , parentSchema .getCurrentUri (), addItemNode );
58
61
}
59
62
}
60
63
}
@@ -63,6 +66,9 @@ public ItemsValidator(String schemaPath, JsonNode schemaNode, JsonSchema parentS
63
66
this .validationContext = validationContext ;
64
67
65
68
parseErrorCode (getValidatorType ().getErrorCodeKey ());
69
+
70
+ this .schema = foundSchema ;
71
+ this .additionalSchema = foundAdditionalSchema ;
66
72
}
67
73
68
74
public Set <ValidationMessage > validate (JsonNode node , JsonNode rootNode , String at ) {
@@ -168,4 +174,14 @@ public JsonSchema getSchema() {
168
174
return schema ;
169
175
}
170
176
177
+ @ Override
178
+ public void preloadJsonSchema () {
179
+ if (null != schema ) {
180
+ schema .initializeValidators ();
181
+ }
182
+ preloadJsonSchemas (tupleSchema );
183
+ if (null != additionalSchema ) {
184
+ additionalSchema .initializeValidators ();
185
+ }
186
+ }
171
187
}
0 commit comments