Skip to content

Commit 5eea5e8

Browse files
FWiesnerFlorian Wiesner
and
Florian Wiesner
authored
Fixes #416 my marking each JsonSchema as being initialized (#417)
Co-authored-by: Florian Wiesner <Florian [email protected]>
1 parent 00923c2 commit 5eea5e8

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

src/main/java/com/networknt/schema/JsonSchema.java

+6-2
Original file line numberDiff line numberDiff 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
}

src/test/java/com/networknt/schema/Issue406Test.java

+9
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
public 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
}

0 commit comments

Comments
 (0)