protected void addValidatorsForProperties( Document parent,
Path parentPath,
Problems problems,
CompositeValidator validators ) {
Document properties = parent.getDocument("properties");
Set<String> propertiesWithSchemas = new HashSet<String>();
if (properties != null && properties.size() != 0) {
for (Field field : properties.fields()) {
String name = field.getName();
Object value = field.getValue();
Path path = Paths.path(parentPath, "properties", name);
if (!(value instanceof Document)) {
problems.recordError(path, "Expected a nested object");
}
Document propertySchema = (Document)value;
Validator propertyValidator = create(propertySchema, path);
if (propertyValidator != null) {
validators.add(new PropertyValidator(name, propertyValidator));
}
propertiesWithSchemas.add(name);
}
}
// Check the additional properties ...
boolean additionalPropertiesAllowed = parent.getBoolean("additionalProperties", true);
if (!additionalPropertiesAllowed) {
validators.add(new NoOtherAllowedPropertiesValidator(propertiesWithSchemas));
} else {
Document additionalSchema = parent.getDocument("additionalProperties");
if (additionalSchema != null) {
Path path = parentPath.with("additionalProperties");
Validator additionalValidator = create(additionalSchema, path);
if (additionalValidator != null) {
validators.add(new AllowedPropertiesValidator(propertiesWithSchemas, additionalValidator));