Skip to content

Commit 3d32064

Browse files
committed
Merge branch 'master' of github.com:networknt/json-schema-validator
2 parents 37d2d6b + 0eea30b commit 3d32064

File tree

4 files changed

+67
-10
lines changed

4 files changed

+67
-10
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,16 @@ public class JsonSchema extends BaseJsonValidator {
4040
protected final Map<String, JsonValidator> validators;
4141
private final ValidationContext validationContext;
4242

43-
JsonSchema(ValidationContext validationContext, JsonNode schemaNode) {
43+
public JsonSchema(ValidationContext validationContext, JsonNode schemaNode) {
4444
this(validationContext, "#", schemaNode, null);
4545
}
4646

47-
JsonSchema(ValidationContext validationContext, String schemaPath, JsonNode schemaNode,
47+
public JsonSchema(ValidationContext validationContext, String schemaPath, JsonNode schemaNode,
4848
JsonSchema parent) {
4949
this(validationContext, schemaPath, schemaNode, parent, false);
5050
}
5151

52-
JsonSchema(ValidationContext validatorFactory, String schemaPath, JsonNode schemaNode,
52+
public JsonSchema(ValidationContext validatorFactory, String schemaPath, JsonNode schemaNode,
5353
JsonSchema parent, boolean suppressSubSchemaRetrieval) {
5454
super(schemaPath, schemaNode, parent, null, suppressSubSchemaRetrieval);
5555
this.validationContext = validatorFactory;

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -141,14 +141,14 @@ public Set<ValidationMessage> validate(JsonNode node, JsonNode rootNode, String
141141
continue;
142142
}
143143
JsonSchema schema = validator.schema;
144-
Set<ValidationMessage> schemaErrors = schema.validate(node, rootNode, at);
144+
Set<ValidationMessage> schemaErrors = schema.validate(node, rootNode, at);
145145
if (schemaErrors.isEmpty()) {
146146
numberOfValidSchema++;
147147
errors = new LinkedHashSet<ValidationMessage>();
148148
}
149149
if(numberOfValidSchema == 0){
150150
errors.addAll(schemaErrors);
151-
}
151+
}
152152
if (numberOfValidSchema > 1) {
153153
break;
154154
}
@@ -161,10 +161,10 @@ public Set<ValidationMessage> validate(JsonNode node, JsonNode rootNode, String
161161
if (ValidatorTypeCode.ADDITIONAL_PROPERTIES.getValue().equals(msg.getType())) {
162162
it.remove();
163163
}
164-
if (errors.isEmpty()) {
165-
// ensure there is always an error reported if number of valid schemas is 0
166-
errors.add(buildValidationMessage(at, ""));
167-
}
164+
}
165+
if (errors.isEmpty()) {
166+
// ensure there is always an error reported if number of valid schemas is 0
167+
errors.add(buildValidationMessage(at, ""));
168168
}
169169
}
170170
if (numberOfValidSchema > 1) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ public void testNotValidator() throws Exception {
228228
public void testOneOfValidator() throws Exception {
229229
runTestFile("tests/oneOf.json");
230230
}
231-
231+
232232
@Test
233233
public void testPatternValidator() throws Exception {
234234
runTestFile("tests/pattern.json");

src/test/resources/tests/oneOf.json

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,5 +64,62 @@
6464
"valid": false
6565
}
6666
]
67+
},
68+
{
69+
"description": "oneOf with objects and type pattern",
70+
"schema": {
71+
"oneOf": [
72+
{
73+
"type": "object",
74+
"required": [
75+
"type"
76+
],
77+
"properties": {
78+
"type": {
79+
"enum": [
80+
"TYPE_1"
81+
]
82+
}
83+
}
84+
},
85+
{
86+
"type": "object",
87+
"required": [
88+
"type"
89+
],
90+
"properties": {
91+
"type": {
92+
"enum": [
93+
"TYPE_2"
94+
]
95+
}
96+
}
97+
}
98+
99+
]
100+
},
101+
"tests": [
102+
{
103+
"description": "first oneOf valid",
104+
"data": {
105+
"type": "TYPE_1"
106+
},
107+
"valid": true
108+
},
109+
{
110+
"description": "second oneOf valid",
111+
"data": {
112+
"type": "TYPE_2"
113+
},
114+
"valid": true
115+
},
116+
{
117+
"description": "neither oneOf valid",
118+
"data": {
119+
"type": "INVALID_TYPE"
120+
},
121+
"valid": false
122+
}
123+
]
67124
}
68125
]

0 commit comments

Comments
 (0)