apicurio-registry
apicurio-registry copied to clipboard
Avro compatibility check does not work correctly for Enum types
Hi,
I was testing the APIcurio registry's capabilities and encountered a bug concerning schema evolution with enum types. When extending an enum type with a new symbol in forward compatibility mode the validation does not fail. Tested versions are 2.2.2, 2.2.3 and 2.2.4. In the test case there are no defaults defined for the enum type, nor for the field.
Version one of the schema:
{
"namespace" : "be.ordina.jworks.contractfirstasyncapi",
"type" : "record",
"name" : "VehicleRefueled",
"fields" : [
{"name":"licensePlate","type":"string", "doc": "The license plate of the vehicle"},
{"name":"fuelType",
"type": {
"type":"enum",
"name": "FuelType",
"symbols": ["GASOLINE","DIESEL","LPG", "CNG", "ELECTRICITY"]
}
},
{"name":"fuelAmount", "type":"double", "default":0.0},
{"name":"fuelUnit",
"javaAnnotation": [ "java.lang.Deprecated(since = \"2\", forRemoval = true)" ],
"type": {
"name": "FuelUnit",
"type":"enum",
"symbols": ["LITER", "KWH"]
}
}
]
}
Version two of the schema that should be invalid because I'm extending the FuelType enum without defaults declared:
{
"namespace" : "be.ordina.jworks.contractfirstasyncapi",
"type" : "record",
"name" : "VehicleRefueled",
"fields" : [
{"name":"licensePlate","type":"string", "doc": "The license plate of the vehicle"},
{"name":"fuelType",
"type": {
"type":"enum",
"name": "FuelType",
"symbols": ["GASOLINE","DIESEL","LPG", "CNG", "ELECTRICITY", "TEST"]
}
},
{"name":"fuelAmount", "type":"double", "default":0.0},
{"name":"fuelUnit",
"javaAnnotation": [ "java.lang.Deprecated(since = \"2\", forRemoval = true)" ],
"type": {
"name": "FuelUnit",
"type":"enum",
"symbols": ["LITER", "KWH"]
}
}
]
}
Interesting use case! There is always a bit of disagreement over whether modifying an enum constitutes a compatibility failure or not.
What I can say is that we're actually just using the default compatibility checking that comes in the Avro library. You can see our implementation here:
https://github.com/Apicurio/apicurio-registry/blob/main/schema-util/avro/src/main/java/io/apicurio/registry/rules/compatibility/AvroCompatibilityChecker.java
Note our use of the Apache Avro library for this. We're very open to suggestions about how to improve things though!