Class LocalSchemaCompatibility
java.lang.Object
io.krabka.streams.schema.LocalSchemaCompatibility
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);
}
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumThe direction of a compatibility check, mirroring registry compatibility levels.static final recordThe outcome of one compatibility check. -
Method Summary
Modifier and TypeMethodDescriptionavro(String previousSchema, String candidateSchema, LocalSchemaCompatibility.Mode mode) Checks two Avro schemas for compatibility.json(String previousSchema, String candidateSchema, LocalSchemaCompatibility.Mode mode) Checks two JSON Schemas for compatibility.protobuf(com.google.protobuf.Descriptors.FileDescriptor previous, com.google.protobuf.Descriptors.FileDescriptor candidate, LocalSchemaCompatibility.Mode mode) Checks two Protobuf file descriptors for compatibility.
-
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 textcandidateSchema- the proposed schema as JSON textmode- 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 textcandidateSchema- the proposed schema as JSON textmode- 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 descriptorcandidate- the proposed schema's file descriptormode- the direction to check- Returns:
- the check result with one message per incompatibility
-