Skip to content

Commit a03170d

Browse files
authored
#354-fixed OneOf validation error if number of valid schemas is not equal to 1 (#355)
1 parent 13a5f0a commit a03170d

File tree

2 files changed

+7
-21
lines changed

2 files changed

+7
-21
lines changed

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

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -162,31 +162,12 @@ public Set<ValidationMessage> validate(JsonNode node, JsonNode rootNode, String
162162
continue;
163163

164164
numberOfValidSchema++;
165-
errors = new LinkedHashSet<ValidationMessage>();
166-
} else {
167-
errors.addAll(schemaErrors);
168165
}
169166
}
170167

171-
// no valid schema has been found after validating all schema validators
172-
if (numberOfValidSchema == 0) {
173-
for (Iterator<ValidationMessage> it = errors.iterator(); it.hasNext(); ) {
174-
ValidationMessage msg = it.next();
175168

176-
if (ValidatorTypeCode.ADDITIONAL_PROPERTIES.getValue().equals(msg.getType())) {
177-
it.remove();
178-
}
179-
}
180-
if (errors.isEmpty()) {
181-
// ensure there is always an error reported if number of valid schemas is 0
182-
errors.add(buildValidationMessage(at, ""));
183-
}
184-
} else {
185-
errors.clear();
186-
}
187-
188-
// validated upfront
189-
if (numberOfValidSchema > 1) {
169+
// ensure there is always an "OneOf" error reported if number of valid schemas is not equal to 1.
170+
if (numberOfValidSchema != 1) {
190171
errors = Collections.singleton(buildValidationMessage(at, ""));
191172
}
192173

src/test/resources/draft6/oneOf.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,11 @@
189189
"bar": "quux"
190190
},
191191
"valid": false
192+
},
193+
{
194+
"description": "neither oneOf given (complex)",
195+
"data": {},
196+
"valid": false
192197
}
193198
]
194199
},

0 commit comments

Comments
 (0)