Skip to content

Commit 77cd232

Browse files
fduttonFaron Dutton
andauthored
Makes JsonSchemaFactory solely responsible for creating JsonSchema instances. (#781)
* Adds support for cross-draft validation Resolves #778 * Makes JsonSchemaFactory solely responsible for creating JsonSchema instances. Resolves #780 --------- Co-authored-by: Faron Dutton <[email protected]>
1 parent 3cf9bb6 commit 77cd232

23 files changed

+70
-49
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public AdditionalPropertiesValidator(String schemaPath, JsonNode schemaNode, Jso
4040
additionalPropertiesSchema = null;
4141
} else if (schemaNode.isObject()) {
4242
allowAdditionalProperties = true;
43-
additionalPropertiesSchema = new JsonSchema(validationContext, getValidatorType().getValue(), parentSchema.getCurrentUri(), schemaNode, parentSchema);
43+
additionalPropertiesSchema = validationContext.newSchema(getValidatorType().getValue(), schemaNode, parentSchema);
4444
} else {
4545
allowAdditionalProperties = false;
4646
additionalPropertiesSchema = null;

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,7 @@ public AllOfValidator(String schemaPath, JsonNode schemaNode, JsonSchema parentS
3333
this.validationContext = validationContext;
3434
int size = schemaNode.size();
3535
for (int i = 0; i < size; i++) {
36-
this.schemas.add(new JsonSchema(validationContext,
37-
schemaPath + "/" + i,
38-
parentSchema.getCurrentUri(),
39-
schemaNode.get(i),
40-
parentSchema));
36+
this.schemas.add(validationContext.newSchema(schemaPath + "/" + i, schemaNode.get(i), parentSchema));
4137
}
4238
}
4339

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,7 @@ public AnyOfValidator(String schemaPath, JsonNode schemaNode, JsonSchema parentS
3535
this.validationContext = validationContext;
3636
int size = schemaNode.size();
3737
for (int i = 0; i < size; i++) {
38-
this.schemas.add(new JsonSchema(validationContext,
39-
schemaPath + "/" + i,
40-
parentSchema.getCurrentUri(),
41-
schemaNode.get(i),
42-
parentSchema));
38+
this.schemas.add(validationContext.newSchema(schemaPath + "/" + i, schemaNode.get(i), parentSchema));
4339
}
4440

4541
if (this.validationContext.getConfig().isOpenAPI3StyleDiscriminators()) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public abstract class BaseJsonValidator implements JsonValidator {
3030
protected String schemaPath;
3131
protected JsonNode schemaNode;
3232
protected JsonSchema parentSchema;
33-
private final boolean suppressSubSchemaRetrieval;
33+
protected final boolean suppressSubSchemaRetrieval;
3434
private ValidatorTypeCode validatorType;
3535
private ErrorMessageType errorMessageType;
3636
protected ValidationContext validationContext;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public ContainsValidator(String schemaPath, JsonNode schemaNode, JsonSchema pare
4949
isMinV201909 = MinV201909.getVersions().contains(SpecVersionDetector.detectOptionalVersion(validationContext.getMetaSchema().getUri()).orElse(DEFAULT_VERSION));
5050

5151
if (schemaNode.isObject() || schemaNode.isBoolean()) {
52-
this.schema = new JsonSchema(validationContext, getValidatorType().getValue(), parentSchema.getCurrentUri(), schemaNode, parentSchema);
52+
this.schema = validationContext.newSchema(getValidatorType().getValue(), schemaNode, parentSchema);
5353

5454
JsonNode parentSchemaNode = parentSchema.getSchemaNode();
5555
Optional.ofNullable(parentSchemaNode.get(ValidatorTypeCode.MAX_CONTAINS.getValue()))

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public DependenciesValidator(String schemaPath, JsonNode schemaNode, JsonSchema
4444
depsProps.add(pvalue.get(i).asText());
4545
}
4646
} else if (pvalue.isObject() || pvalue.isBoolean()) {
47-
schemaDeps.put(pname, new JsonSchema(validationContext, pname, parentSchema.getCurrentUri(), pvalue, parentSchema));
47+
schemaDeps.put(pname, validationContext.newSchema(pname, pvalue, parentSchema));
4848
}
4949
}
5050

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public DependentSchemas(String schemaPath, JsonNode schemaNode, JsonSchema paren
3434
String pname = it.next();
3535
JsonNode pvalue = schemaNode.get(pname);
3636
if (pvalue.isObject() || pvalue.isBoolean()) {
37-
schemaDependencies.put(pname, new JsonSchema(validationContext, pname, parentSchema.getCurrentUri(), pvalue, parentSchema));
37+
schemaDependencies.put(pname, validationContext.newSchema(pname, pvalue, parentSchema));
3838
}
3939
}
4040

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,11 @@ public IfValidator(String schemaPath, JsonNode schemaNode, JsonSchema parentSche
4242
final JsonNode node = schemaNode.get(keyword);
4343
final String schemaPathOfSchema = parentSchema.schemaPath + "/" + keyword;
4444
if (keyword.equals("if")) {
45-
foundIfSchema = new JsonSchema(validationContext, schemaPathOfSchema, parentSchema.getCurrentUri(), node, parentSchema);
45+
foundIfSchema = validationContext.newSchema(schemaPathOfSchema, node, parentSchema);
4646
} else if (keyword.equals("then") && node != null) {
47-
foundThenSchema = new JsonSchema(validationContext, schemaPathOfSchema, parentSchema.getCurrentUri(), node, parentSchema);
47+
foundThenSchema = validationContext.newSchema(schemaPathOfSchema, node, parentSchema);
4848
} else if (keyword.equals("else") && node != null) {
49-
foundElseSchema = new JsonSchema(validationContext, schemaPathOfSchema, parentSchema.getCurrentUri(), node, parentSchema);
49+
foundElseSchema = validationContext.newSchema(schemaPathOfSchema, node, parentSchema);
5050
}
5151
}
5252

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,18 +44,18 @@ public ItemsValidator(String schemaPath, JsonNode schemaNode, JsonSchema parentS
4444
JsonSchema foundAdditionalSchema = null;
4545

4646
if (schemaNode.isObject() || schemaNode.isBoolean()) {
47-
foundSchema = new JsonSchema(validationContext, schemaPath, parentSchema.getCurrentUri(), schemaNode, parentSchema);
47+
foundSchema = validationContext.newSchema(schemaPath, schemaNode, parentSchema);
4848
} else {
4949
for (JsonNode s : schemaNode) {
50-
this.tupleSchema.add(new JsonSchema(validationContext, schemaPath, parentSchema.getCurrentUri(), s, parentSchema));
50+
this.tupleSchema.add(validationContext.newSchema(schemaPath, s, parentSchema));
5151
}
5252

5353
JsonNode addItemNode = getParentSchema().getSchemaNode().get(PROPERTY_ADDITIONAL_ITEMS);
5454
if (addItemNode != null) {
5555
if (addItemNode.isBoolean()) {
5656
this.additionalItems = addItemNode.asBoolean();
5757
} else if (addItemNode.isObject()) {
58-
foundAdditionalSchema = new JsonSchema(validationContext, "#", parentSchema.getCurrentUri(), addItemNode, parentSchema);
58+
foundAdditionalSchema = validationContext.newSchema("#", addItemNode, parentSchema);
5959
}
6060
}
6161
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public ItemsValidator202012(String schemaPath, JsonNode schemaNode, JsonSchema p
4646
}
4747

4848
if (schemaNode.isObject() || schemaNode.isBoolean()) {
49-
this.schema = new JsonSchema(validationContext, schemaPath, parentSchema.getCurrentUri(), schemaNode, parentSchema);
49+
this.schema = validationContext.newSchema(schemaPath, schemaNode, parentSchema);
5050
} else {
5151
throw new IllegalArgumentException("The value of 'items' MUST be a valid JSON Schema.");
5252
}

0 commit comments

Comments
 (0)