Skip to content

Commit ced6271

Browse files
committed
Fix discriminator
1 parent 1602b79 commit ced6271

File tree

1 file changed

+18
-18
lines changed

1 file changed

+18
-18
lines changed

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

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -116,28 +116,28 @@ protected void validate(ExecutionContext executionContext, JsonNode node, JsonNo
116116
boolean discriminatorMatchFound = false;
117117
DiscriminatorState discriminator = executionContext.getDiscriminatorMapping().get(instanceLocation);
118118
JsonNode refNode = schema.getSchemaNode().get("$ref");
119-
if (discriminator != null && refNode != null) {
119+
if (discriminator != null && refNode != null && discriminator.hasDiscriminatingValue()) {
120120
discriminatorMatchFound = discriminator.matches(refNode.asText());
121-
}
122-
if (discriminatorMatchFound) {
123-
/*
124-
* Note that discriminator cannot change the outcome of the evaluation but can
125-
* be used to filter off any additional messages
126-
*
127-
* The discriminator will cause all messages other than the one with the //
128-
* matching discriminator to be discarded.
129-
*/
130-
if (!subSchemaErrors.isEmpty()) {
121+
if (discriminatorMatchFound) {
131122
/*
132-
* This means that the discriminated value has errors and doesn't match so these
133-
* errors are the only ones that will be reported *IF* there are no other
134-
* schemas that successfully validate to meet the requirement of anyOf.
123+
* Note that discriminator cannot change the outcome of the evaluation but can
124+
* be used to filter off any additional messages
135125
*
136-
* If there are any successful schemas as per anyOf, all these errors will be
137-
* discarded.
126+
* The discriminator will cause all messages other than the one with the //
127+
* matching discriminator to be discarded.
138128
*/
139-
discriminatorErrors = new ArrayList<>(subSchemaErrors);
140-
allErrors = null; // This is no longer needed
129+
if (!subSchemaErrors.isEmpty()) {
130+
/*
131+
* This means that the discriminated value has errors and doesn't match so these
132+
* errors are the only ones that will be reported *IF* there are no other
133+
* schemas that successfully validate to meet the requirement of anyOf.
134+
*
135+
* If there are any successful schemas as per anyOf, all these errors will be
136+
* discarded.
137+
*/
138+
discriminatorErrors = new ArrayList<>(subSchemaErrors);
139+
allErrors = null; // This is no longer needed
140+
}
141141
}
142142
} else {
143143
// This is the normal handling when discriminators aren't enabled

0 commit comments

Comments
 (0)