@@ -134,11 +134,18 @@ public Set<ValidationMessage> validate(JsonNode node, JsonNode rootNode, String
134
134
// this validator considers a missing node as an error
135
135
// set it here to true, however re-set it to its original value upon finishing the validation
136
136
boolean missingNodeAsError = config .isMissingNodeAsError ();
137
- config .setMissingNodeAsError (true );
137
+ config .setMissingNodeAsError (false );
138
138
139
139
int numberOfValidSchema = 0 ;
140
140
Set <ValidationMessage > errors = new LinkedHashSet <ValidationMessage >();
141
141
142
+ // validate that only a single element has been received in the oneOf node
143
+ // validation should not continue, as it contradicts the oneOf requirement of only one
144
+ if (node .isObject () && node .size ()>1 ) {
145
+ errors = Collections .singleton (buildValidationMessage (at , "" ));
146
+ return Collections .unmodifiableSet (errors );
147
+ }
148
+
142
149
for (ShortcutValidator validator : schemas ) {
143
150
if (!validator .allConstantsMatch (node )) {
144
151
// take a shortcut: if there is any constant that does not match,
@@ -150,6 +157,10 @@ public Set<ValidationMessage> validate(JsonNode node, JsonNode rootNode, String
150
157
if (schemaErrors .isEmpty ()) {
151
158
numberOfValidSchema ++;
152
159
errors = new LinkedHashSet <ValidationMessage >();
160
+
161
+ // a valid schema has been identified, and the node was an object, break the loop
162
+ if (node .isObject ())
163
+ break ;
153
164
}
154
165
if (numberOfValidSchema == 0 ){
155
166
errors .addAll (schemaErrors );
@@ -169,6 +180,8 @@ public Set<ValidationMessage> validate(JsonNode node, JsonNode rootNode, String
169
180
errors .add (buildValidationMessage (at , "" ));
170
181
}
171
182
}
183
+
184
+ // validated upfront
172
185
if (numberOfValidSchema > 1 ) {
173
186
errors = Collections .singleton (buildValidationMessage (at , "" ));
174
187
}
0 commit comments