Class LocalSchemaCompatibility

java.lang.Object
io.krabka.streams.schema.LocalSchemaCompatibility

public final class LocalSchemaCompatibility extends Object
Pairwise, network-free schema compatibility checks.

Checks one candidate schema against one previous schema without contacting a registry, which makes the checks usable in unit tests and CI gates. Avro uses the reference SchemaCompatibility rules; JSON Schema checks type narrowing, newly required properties, and disallowed properties; Protobuf checks field wire types, cardinality, and required-field presence by field number.

Example

var result = LocalSchemaCompatibility.avro(
    previousSchemaJson, candidateSchemaJson, LocalSchemaCompatibility.Mode.BACKWARD);
if (!result.compatible()) {
    result.incompatibilities().forEach(System.err::println);
}
  • Method Details

    • avro

      public static LocalSchemaCompatibility.Result avro(String previousSchema, String candidateSchema, LocalSchemaCompatibility.Mode mode)
      Checks two Avro schemas for compatibility.
      Parameters:
      previousSchema - the currently registered schema as JSON text
      candidateSchema - the proposed schema as JSON text
      mode - the direction to check
      Returns:
      the check result with one message per incompatibility
      Throws:
      org.apache.avro.SchemaParseException - if either schema is not valid Avro
    • json

      public static LocalSchemaCompatibility.Result json(String previousSchema, String candidateSchema, LocalSchemaCompatibility.Mode mode)
      Checks two JSON Schemas for compatibility.

      The check walks object properties recursively and reports type narrowing, properties that became required, and properties rejected by additionalProperties: false.

      Parameters:
      previousSchema - the currently registered schema as JSON text
      candidateSchema - the proposed schema as JSON text
      mode - the direction to check
      Returns:
      the check result with one message per incompatibility
      Throws:
      IllegalArgumentException - if either document is not valid JSON
    • protobuf

      public static LocalSchemaCompatibility.Result protobuf(com.google.protobuf.Descriptors.FileDescriptor previous, com.google.protobuf.Descriptors.FileDescriptor candidate, LocalSchemaCompatibility.Mode mode)
      Checks two Protobuf file descriptors for compatibility.

      Messages are matched by full name and fields by number. A field whose wire type or cardinality changed, and a required reader field that the writer never wrote, are reported as incompatibilities.

      Parameters:
      previous - the currently registered schema's file descriptor
      candidate - the proposed schema's file descriptor
      mode - the direction to check
      Returns:
      the check result with one message per incompatibility