@@ -80,7 +80,7 @@ public JsonSchema(ValidationContext validationContext, URI baseUri, JsonNode sch
80
80
private JsonSchema (ValidationContext validationContext , String schemaPath , URI currentUri , JsonNode schemaNode ,
81
81
JsonSchema parent , boolean suppressSubSchemaRetrieval ) {
82
82
super (schemaPath , schemaNode , parent , null , suppressSubSchemaRetrieval ,
83
- validationContext .getConfig () != null && validationContext .getConfig ().isFailFast ());
83
+ validationContext .getConfig () != null && validationContext .getConfig ().isFailFast ());
84
84
this .validationContext = validationContext ;
85
85
this .idKeyword = validationContext .getMetaSchema ().getIdKeyword ();
86
86
this .currentUri = this .combineCurrentUriWithIds (currentUri , schemaNode );
@@ -109,9 +109,9 @@ private URI combineCurrentUriWithIds(URI currentUri, JsonNode schemaNode) {
109
109
return this .validationContext .getURIFactory ().create (currentUri , id );
110
110
} catch (IllegalArgumentException e ) {
111
111
throw new JsonSchemaException (ValidationMessage .of (ValidatorTypeCode .ID .getValue (),
112
- ValidatorTypeCode .ID ,
113
- id ,
114
- currentUri == null ? "null" : currentUri .toString ()));
112
+ ValidatorTypeCode .ID ,
113
+ id ,
114
+ currentUri == null ? "null" : currentUri .toString ()));
115
115
}
116
116
}
117
117
}
@@ -242,7 +242,7 @@ private Map<String, JsonValidator> read(JsonNode schemaNode) {
242
242
private String getCustomMessage (JsonNode schemaNode , String pname ) {
243
243
final JsonSchema parentSchema = getParentSchema ();
244
244
final JsonNode message = getMessageNode (schemaNode , parentSchema );
245
- if (message != null && message .get (pname ) != null ) {
245
+ if (message != null && message .get (pname ) != null ) {
246
246
return message .get (pname ).asText ();
247
247
}
248
248
return null ;
@@ -251,7 +251,7 @@ private String getCustomMessage(JsonNode schemaNode, String pname) {
251
251
private JsonNode getMessageNode (JsonNode schemaNode , JsonSchema parentSchema ) {
252
252
JsonNode nodeContainingMessage ;
253
253
if (parentSchema == null )
254
- nodeContainingMessage = schemaNode ;
254
+ nodeContainingMessage = schemaNode ;
255
255
else
256
256
nodeContainingMessage = parentSchema .schemaNode ;
257
257
return nodeContainingMessage .get ("message" );
@@ -291,9 +291,9 @@ public Set<ValidationMessage> validate(JsonNode jsonNode, JsonNode rootNode, Str
291
291
final JsonNode discriminatorNode = jsonNode .get (discriminatorPropertyName );
292
292
final String discriminatorPropertyValue = discriminatorNode == null ? null : discriminatorNode .asText ();
293
293
checkDiscriminatorMatch (discriminatorContext ,
294
- discriminatorToUse ,
295
- discriminatorPropertyValue ,
296
- this );
294
+ discriminatorToUse ,
295
+ discriminatorPropertyValue ,
296
+ this );
297
297
}
298
298
}
299
299
}
@@ -316,12 +316,17 @@ public ValidationResult validateAndCollect(JsonNode node) {
316
316
*/
317
317
protected ValidationResult validateAndCollect (JsonNode jsonNode , JsonNode rootNode , String at ) {
318
318
try {
319
+ // Get the config.
320
+ SchemaValidatorsConfig config = validationContext .getConfig ();
319
321
// Get the collector context from the thread local.
320
322
CollectorContext collectorContext = getCollectorContext ();
321
323
// Valdiate.
322
324
Set <ValidationMessage > errors = validate (jsonNode , rootNode , at );
323
- // Load all the data from collectors into the context.
324
- collectorContext .loadCollectors ();
325
+ // 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.
326
+ if (config .doLoadCollectors ()) {
327
+ // Load all the data from collectors into the context.
328
+ collectorContext .loadCollectors ();
329
+ }
325
330
// Collect errors and collector context into validation result.
326
331
ValidationResult validationResult = new ValidationResult (errors , collectorContext );
327
332
return validationResult ;
@@ -336,19 +341,25 @@ protected ValidationResult validateAndCollect(JsonNode jsonNode, JsonNode rootNo
336
341
337
342
/**
338
343
* Walk the JSON node
339
- * @param node JsonNode
344
+ *
345
+ * @param node JsonNode
340
346
* @param shouldValidateSchema indicator on validation
341
347
* @return result of ValidationResult
342
348
*/
343
349
public ValidationResult walk (JsonNode node , boolean shouldValidateSchema ) {
350
+ // Get the config.
351
+ SchemaValidatorsConfig config = validationContext .getConfig ();
344
352
// Get the collector context from the thread local.
345
353
CollectorContext collectorContext = getCollectorContext ();
346
354
// Set the walkEnabled flag in internal validator state.
347
355
setValidatorState (true , shouldValidateSchema );
348
356
// Walk through the schema.
349
357
Set <ValidationMessage > errors = walk (node , node , AT_ROOT , shouldValidateSchema );
350
- // Load all the data from collectors into the context.
351
- collectorContext .loadCollectors ();
358
+ // 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.
359
+ if (config .doLoadCollectors ()) {
360
+ // Load all the data from collectors into the context.
361
+ collectorContext .loadCollectors ();
362
+ }
352
363
// Collect errors and collector context into validation result.
353
364
ValidationResult validationResult = new ValidationResult (errors , collectorContext );
354
365
return validationResult ;
@@ -366,26 +377,28 @@ public Set<ValidationMessage> walk(JsonNode node, JsonNode rootNode, String at,
366
377
// Call all the pre-walk listeners. If atleast one of the pre walk listeners
367
378
// returns SKIP, then skip the walk.
368
379
if (keywordWalkListenerRunner .runPreWalkListeners (schemaPathWithKeyword ,
369
- node ,
370
- rootNode ,
371
- at ,
372
- schemaPath ,
373
- schemaNode ,
374
- parentSchema ,
375
- validationContext .getJsonSchemaFactory ())) {
380
+ node ,
381
+ rootNode ,
382
+ at ,
383
+ schemaPath ,
384
+ schemaNode ,
385
+ parentSchema ,
386
+ validationContext ,
387
+ validationContext .getJsonSchemaFactory ())) {
376
388
validationMessages .addAll (jsonWalker .walk (node , rootNode , at , shouldValidateSchema ));
377
389
}
378
390
} finally {
379
391
// Call all the post-walk listeners.
380
392
keywordWalkListenerRunner .runPostWalkListeners (schemaPathWithKeyword ,
381
- node ,
382
- rootNode ,
383
- at ,
384
- schemaPath ,
385
- schemaNode ,
386
- parentSchema ,
387
- validationContext .getJsonSchemaFactory (),
388
- validationMessages );
393
+ node ,
394
+ rootNode ,
395
+ at ,
396
+ schemaPath ,
397
+ schemaNode ,
398
+ parentSchema ,
399
+ validationContext ,
400
+ validationContext .getJsonSchemaFactory (),
401
+ validationMessages );
389
402
}
390
403
}
391
404
return validationMessages ;
0 commit comments