use of oap.json.schema.JsonValidatorProperties in project oap by oaplatform.
the class DictionaryJsonValidator method validate.
private Result<List<Dictionary>, List<String>> validate(JsonValidatorProperties properties, Optional<DictionarySchemaAST> schemaOpt, List<Dictionary> dictionaries) {
if (!schemaOpt.isPresent())
return Result.success(dictionaries);
final DictionarySchemaAST schema = schemaOpt.get();
final Result<List<Dictionary>, List<String>> cd = validate(properties, schema.parent, dictionaries);
if (!cd.isSuccess())
return cd;
final JsonPath jsonPath = new JsonPath(rightTrimItems(schema.path), properties.path);
List<Object> parentValues = jsonPath.traverse(properties.rootJson);
if (parentValues.isEmpty()) {
final String fixedPath = jsonPath.getFixedPath();
if (!schema.common.required.orElse(BooleanReference.FALSE).apply(properties.rootJson, properties.rootJson, Optional.of(fixedPath), properties.prefixPath))
// return Result.failure( Lists.of( properties.error( fixedPath, "required property is missing" ) ) );
// else
parentValues = cd.successValue.stream().flatMap(d -> d.getValues().stream().map(Dictionary::getId)).collect(toList());
}
final ArrayList<Dictionary> cDict = new ArrayList<>();
for (Object parentValue : parentValues) {
List<Dictionary> children = cd.successValue.stream().map(d -> d.getValueOpt(parentValue.toString())).filter(Optional::isPresent).map(Optional::get).collect(toList());
if (children.isEmpty())
return Result.failure(Lists.of(properties.error("instance does not match any member resolve the enumeration " + printIds(cd.successValue))));
cDict.addAll(children);
}
return Result.success(cDict);
}
Aggregations