use of com.linkedin.restli.common.ExtensionSchemaAnnotation in project rest.li by linkedin.
the class ExtensionSchemaValidationCmdLineApp method checkExtensionSchemaFields.
private static void checkExtensionSchemaFields(List<RecordDataSchema.Field> extensionSchemaFields) throws InvalidExtensionSchemaException {
for (RecordDataSchema.Field field : extensionSchemaFields) {
// check extension schema field annotation
Map<String, Object> properties = field.getProperties();
if (properties.isEmpty() || properties.keySet().size() != 1 || !properties.containsKey(EXTENSION_ANNOTATION_NAMESPACE)) {
throw new InvalidExtensionSchemaException("The field : " + field.getName() + " of extension schema must and only be annotated with 'extension'");
}
Object dataElement = properties.get(EXTENSION_ANNOTATION_NAMESPACE);
ValidationOptions validationOptions = new ValidationOptions(RequiredMode.MUST_BE_PRESENT, CoercionMode.STRING_TO_PRIMITIVE, UnrecognizedFieldMode.DISALLOW);
try {
if (!(dataElement instanceof DataMap)) {
throw new InvalidExtensionSchemaException("Extension schema annotation is not a datamap!");
}
DataSchema extensionSchemaAnnotationSchema = new ExtensionSchemaAnnotation().schema();
ValidationResult result = ValidateDataAgainstSchema.validate(dataElement, extensionSchemaAnnotationSchema, validationOptions);
if (!result.isValid()) {
throw new InvalidExtensionSchemaException("Extension schema annotation is not valid: " + result.getMessages());
}
} catch (InvalidExtensionSchemaException e) {
throw e;
} catch (Exception e) {
_logger.error("Error while checking extension schema field annotation: " + e.getMessage());
System.exit(1);
}
checkExtensionSchemaFieldSchema(field.getType(), properties);
}
}
Aggregations