-
Notifications
You must be signed in to change notification settings - Fork 340
Walking over JSON Schema and JDK upgradation to 8 or above. #316
Description
We have a requirement where we want to walk through the JSON Schema and corresponding JSON data node properties at the same time the way we do with validator's today.
For example the Validate method on MaxItemsValidator allows us to validate the JSON data node for a specific Schema Node .
public MaxItemsValidator(String schemaPath, JsonNode schemaNode, JsonSchema parentSchema, ValidationContext validationContext) {
super(schemaPath, schemaNode, parentSchema, ValidatorTypeCode.MAX_ITEMS, validationContext);
if (schemaNode.isIntegralNumber()) {
max = schemaNode.intValue();
}
parseErrorCode(getValidatorType().getErrorCodeKey());
}
public Set<ValidationMessage> validate(JsonNode node, JsonNode rootNode, String at) {
debug(logger, node, rootNode, at);
if (node.isArray()) {
if (node.size() > max) {
return Collections.singleton(buildValidationMessage(at, "" + max));
}
} else if (config.isTypeLoose()) {
if (1 > max) {
return Collections.singleton(buildValidationMessage(at, "" + max));
}
}
return Collections.emptySet();
}
Taking this to a more generic level can we have a walk or visit method on the validator's that allows us to do more custom logic's beyond validations.
public void visit(Collection<JsonValidator> visitors, JsonNode node);
While walking through the schema we want to collect different kinds of information co-relating to the localized node and schema data. We use this library for validating our schema's today and I think we should also make the library more robust and useful by introducing the schema walkers or visitors.
There is a library in javascript which does something on these lines.
https://github.com/cloudflare/json-schema-tools/tree/master/workspaces/json-schema-walker
Also can we move this library to JDK 8 or beyond.