File tree Expand file tree Collapse file tree 2 files changed +15
-2
lines changed
main/java/com/networknt/schema
test/java/com/networknt/schema Expand file tree Collapse file tree 2 files changed +15
-2
lines changed Original file line number Diff line number Diff line change @@ -47,6 +47,7 @@ public class JsonSchema extends BaseJsonValidator {
4747 private final String idKeyword ;
4848 private final ValidationContext validationContext ;
4949 private WalkListenerRunner keywordWalkListenerRunner ;
50+ private boolean validatorsLoaded = false ;
5051
5152 /**
5253 * This is the current uri of this schema. This uri could refer to the uri of this schema's file
@@ -423,8 +424,11 @@ public Map<String, JsonValidator> getValidators() {
423424 * instances of the validators.</p>
424425 */
425426 public void initializeValidators () {
426- for (final JsonValidator validator : getValidators ().values ()) {
427- validator .preloadJsonSchema ();
427+ if (!validatorsLoaded ) {
428+ validatorsLoaded = true ;
429+ for (final JsonValidator validator : getValidators ().values ()) {
430+ validator .preloadJsonSchema ();
431+ }
428432 }
429433 }
430434}
Original file line number Diff line number Diff line change 99
1010public class Issue406Test {
1111 protected static final String INVALID_$REF_SCHEMA = "{\" $ref\" :\" urn:unresolved\" }" ;
12+ protected static final String CIRCULAR_$REF_SCHEMA = "{\" $ref\" :\" #/nestedSchema\" ,"
13+ + "\" nestedSchema\" :{\" $ref\" :\" #/nestedSchema\" }}" ;
1214
1315 @ Test
1416 public void testPreloadingNotHappening () {
@@ -31,4 +33,11 @@ public void run() {
3133 }
3234 });
3335 }
36+
37+ @ Test
38+ public void testPreloadingHappeningForCircularDependency () {
39+ final JsonSchemaFactory factory = JsonSchemaFactory .getInstance (SpecVersion .VersionFlag .V7 );
40+ final JsonSchema schema = factory .getSchema (CIRCULAR_$REF_SCHEMA );
41+ schema .initializeValidators ();
42+ }
3443}
You can’t perform that action at this time.
0 commit comments