use of io.confluent.kafka.schemaregistry.protobuf.diff.Difference in project schema-registry by confluentinc.
the class ProtobufSchema method isBackwardCompatible.
@Override
public List<String> isBackwardCompatible(ParsedSchema previousSchema) {
if (!schemaType().equals(previousSchema.schemaType())) {
return Collections.singletonList("Incompatible because of different schema type");
}
final List<Difference> differences = SchemaDiff.compare((ProtobufSchema) previousSchema, this);
final List<Difference> incompatibleDiffs = differences.stream().filter(diff -> !SchemaDiff.COMPATIBLE_CHANGES.contains(diff.getType())).collect(Collectors.toList());
boolean isCompatible = incompatibleDiffs.isEmpty();
if (!isCompatible) {
boolean first = true;
List<String> errorMessages = new ArrayList<>();
for (Difference incompatibleDiff : incompatibleDiffs) {
if (first) {
// Log first incompatible change as warning
log.warn("Found incompatible change: {}", incompatibleDiff);
errorMessages.add(String.format("Found incompatible change: %s", incompatibleDiff));
first = false;
} else {
log.debug("Found incompatible change: {}", incompatibleDiff);
errorMessages.add(String.format("Found incompatible change: %s", incompatibleDiff));
}
}
return errorMessages;
} else {
return Collections.emptyList();
}
}
Aggregations