use of io.apicurio.registry.rules.UnprocessableSchemaException in project apicurio-registry by Apicurio.
the class AvroCompatibilityChecker method testCompatibility.
/**
* @see CompatibilityChecker#testCompatibility(io.apicurio.registry.rules.compatibility.CompatibilityLevel, java.util.List, java.lang.String)
*/
@Override
public CompatibilityExecutionResult testCompatibility(CompatibilityLevel compatibilityLevel, List<String> existingSchemaStrings, String proposedSchemaString) {
requireNonNull(compatibilityLevel, "compatibilityLevel MUST NOT be null");
requireNonNull(existingSchemaStrings, "existingSchemaStrings MUST NOT be null");
requireNonNull(proposedSchemaString, "proposedSchemaString MUST NOT be null");
SchemaValidator schemaValidator = validatorFor(compatibilityLevel);
if (schemaValidator == null) {
return CompatibilityExecutionResult.compatible();
}
try {
List<Schema> existingSchemas = existingSchemaStrings.stream().map(s -> new Schema.Parser().parse(s)).collect(Collectors.toList());
// the most recent must come first, i.e. reverse-chronological.
Collections.reverse(existingSchemas);
Schema toValidate = new Schema.Parser().parse(proposedSchemaString);
schemaValidator.validate(toValidate, existingSchemas);
return CompatibilityExecutionResult.compatible();
} catch (SchemaValidationException e) {
return CompatibilityExecutionResult.incompatible(e);
} catch (SchemaParseException | AvroTypeException e) {
throw new UnprocessableSchemaException(e.getMessage());
}
}
Aggregations