@@ -43,37 +43,28 @@ public AnyOfValidator(String schemaPath, JsonNode schemaNode, JsonSchema parentS
43
43
public Set <ValidationMessage > validate (JsonNode node , JsonNode rootNode , String at ) {
44
44
debug (logger , node , rootNode , at );
45
45
46
+ Set <ValidationMessage > allErrors = new LinkedHashSet <ValidationMessage >();
46
47
String typeValidatorName = "anyOf/type" ;
47
- JsonType nodeType = TypeFactory .getValueNodeType (node );
48
- //If schema has type validator and it doesn't match with node type then ignore it
49
- List <JsonSchema > filteredSchemaList = new ArrayList <JsonSchema >();
50
48
List <String > expectedTypeList = new ArrayList <String >();
49
+
51
50
for (JsonSchema schema : schemas ) {
52
51
if (schema .validators .containsKey (typeValidatorName )) {
53
- JsonType schemaType = ((TypeValidator ) schema .validators .get (typeValidatorName )).getSchemaType ();
54
- if (schemaType == nodeType ) {
55
- filteredSchemaList .add (schema );
52
+ TypeValidator typeValidator = ((TypeValidator ) schema .validators .get (typeValidatorName ));
53
+ //If schema has type validator and node type doesn't match with schemaType then ignore it
54
+ if (!typeValidator .equalsToSchemaType (node )) {
55
+ expectedTypeList .add (typeValidator .getSchemaType ().toString ());
56
+ continue ;
56
57
}
57
- expectedTypeList .add (schemaType .toString ());
58
- }
59
- else {
60
- filteredSchemaList .add (schema );
61
58
}
62
- }
63
- if (!schemas .isEmpty () && filteredSchemaList .isEmpty ()) {
64
- return Collections .singleton (buildValidationMessage (at , StringUtils .join (expectedTypeList )));
65
- }
66
-
67
- Set <ValidationMessage > allErrors = new LinkedHashSet <ValidationMessage >();
68
-
69
- for (JsonSchema schema : filteredSchemaList ) {
70
59
Set <ValidationMessage > errors = schema .validate (node , rootNode , at );
71
60
if (errors .isEmpty ()) {
72
61
return errors ;
73
62
}
74
63
allErrors .addAll (errors );
75
64
}
76
-
65
+ if (!schemas .isEmpty ()) {
66
+ return Collections .singleton (buildValidationMessage (at , StringUtils .join (expectedTypeList )));
67
+ }
77
68
return Collections .unmodifiableSet (allErrors );
78
69
}
79
70
0 commit comments