|
|
@@ -1,7 +1,12 @@
|
|
|
package org.leumasjaffe.json.schema.tester;
|
|
|
|
|
|
+import java.util.List;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+import org.leumasjaffe.container.EitherStream;
|
|
|
import org.leumasjaffe.json.JsonHelper;
|
|
|
import org.leumasjaffe.json.schema.Tester;
|
|
|
+import org.leumasjaffe.json.schema.ValidationException;
|
|
|
|
|
|
import com.fasterxml.jackson.databind.JsonNode;
|
|
|
|
|
|
@@ -14,6 +19,18 @@ import lombok.experimental.FieldDefaults;
|
|
|
public class ContainsTester implements Tester {
|
|
|
Tester schema;
|
|
|
|
|
|
+ @Override
|
|
|
+ public void validate(JsonNode node) throws ValidationException {
|
|
|
+ final List<ValidationException> exceptions =
|
|
|
+ EitherStream.from(JsonHelper.toArray(node))
|
|
|
+ .flatMap(schema::validate, ValidationException.class)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ if (exceptions.size() == node.size()) {
|
|
|
+ throw new ValidationException("contains", "No items match contains",
|
|
|
+ exceptions);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public boolean accepts(JsonNode node) {
|
|
|
return JsonHelper.toArray(node).stream().anyMatch(schema::accepts);
|