18
18
19
19
import com .fasterxml .jackson .databind .JsonNode ;
20
20
import com .fasterxml .jackson .databind .ObjectMapper ;
21
+
21
22
import org .slf4j .Logger ;
22
23
import org .slf4j .LoggerFactory ;
23
24
24
25
import java .util .ArrayList ;
25
26
import java .util .HashSet ;
27
+ import java .util .Iterator ;
26
28
import java .util .List ;
27
29
import java .util .Set ;
28
- import java .util .stream .Collectors ;
29
30
30
31
public class OneOfValidator extends BaseJsonValidator implements JsonValidator {
31
32
private static final Logger logger = LoggerFactory .getLogger (RequiredValidator .class );
@@ -46,13 +47,13 @@ public Set<ValidationMessage> validate(JsonNode node, JsonNode rootNode, String
46
47
debug (logger , node , rootNode , at );
47
48
48
49
int numberOfValidSchema = 0 ;
49
- Set <ValidationMessage > errors = new HashSet <>();
50
+ Set <ValidationMessage > errors = new HashSet <ValidationMessage >();
50
51
51
52
for (JsonSchema schema : schemas ) {
52
53
Set <ValidationMessage > schemaErrors = schema .validate (node , rootNode , at );
53
54
if (schemaErrors .isEmpty ()) {
54
55
numberOfValidSchema ++;
55
- errors = new HashSet <>();
56
+ errors = new HashSet <ValidationMessage >();
56
57
}
57
58
if (numberOfValidSchema == 0 ){
58
59
errors .addAll (schemaErrors );
@@ -63,13 +64,17 @@ public Set<ValidationMessage> validate(JsonNode node, JsonNode rootNode, String
63
64
}
64
65
65
66
if (numberOfValidSchema == 0 ) {
66
- errors = errors .stream ()
67
- .filter (msg -> !ValidatorTypeCode .ADDITIONAL_PROPERTIES
68
- .equals (ValidatorTypeCode .fromValue (msg .getType ())))
69
- .collect (Collectors .toSet ());
67
+ for (Iterator <ValidationMessage > it = errors .iterator (); it .hasNext ();) {
68
+ ValidationMessage msg = it .next ();
69
+
70
+ if (ValidatorTypeCode .ADDITIONAL_PROPERTIES .equals (ValidatorTypeCode .fromValue (msg
71
+ .getType ()))) {
72
+ it .remove ();
73
+ }
74
+ }
70
75
}
71
76
if (numberOfValidSchema > 1 ) {
72
- errors = new HashSet <>();
77
+ errors = new HashSet <ValidationMessage >();
73
78
errors .add (buildValidationMessage (at , "" ));
74
79
}
75
80
0 commit comments