use of org.zalando.nakadi.validation.schema.diff.SchemaDiff in project nakadi by zalando.
the class ValidatorConfig method schemaEvolutionService.
@Bean
public SchemaEvolutionService schemaEvolutionService() throws IOException {
final JSONObject metaSchemaJson = new JSONObject(Resources.toString(Resources.getResource("schema.json"), Charsets.UTF_8));
final Schema metaSchema = SchemaLoader.load(metaSchemaJson);
final List<SchemaEvolutionConstraint> schemaEvolutionConstraints = Lists.newArrayList(new CategoryChangeConstraint(), new CompatibilityModeChangeConstraint(), new PartitionKeyFieldsConstraint(), new PartitionStrategyConstraint(), new EnrichmentStrategyConstraint());
final Map<SchemaChange.Type, Version.Level> compatibleChanges = new HashMap<>();
compatibleChanges.put(DESCRIPTION_CHANGED, PATCH);
compatibleChanges.put(TITLE_CHANGED, PATCH);
compatibleChanges.put(PROPERTIES_ADDED, MINOR);
compatibleChanges.put(ID_CHANGED, MAJOR);
compatibleChanges.put(SCHEMA_REMOVED, MAJOR);
compatibleChanges.put(TYPE_CHANGED, MAJOR);
compatibleChanges.put(NUMBER_OF_ITEMS_CHANGED, MAJOR);
compatibleChanges.put(PROPERTY_REMOVED, MAJOR);
compatibleChanges.put(DEPENDENCY_ARRAY_CHANGED, MAJOR);
compatibleChanges.put(DEPENDENCY_SCHEMA_CHANGED, MAJOR);
compatibleChanges.put(COMPOSITION_METHOD_CHANGED, MAJOR);
compatibleChanges.put(ATTRIBUTE_VALUE_CHANGED, MAJOR);
compatibleChanges.put(ENUM_ARRAY_CHANGED, MAJOR);
compatibleChanges.put(SUB_SCHEMA_CHANGED, MAJOR);
compatibleChanges.put(DEPENDENCY_SCHEMA_REMOVED, MAJOR);
compatibleChanges.put(REQUIRED_ARRAY_CHANGED, MAJOR);
compatibleChanges.put(REQUIRED_ARRAY_EXTENDED, MAJOR);
compatibleChanges.put(ADDITIONAL_PROPERTIES_CHANGED, MAJOR);
compatibleChanges.put(ADDITIONAL_ITEMS_CHANGED, MAJOR);
final Map<SchemaChange.Type, Version.Level> forwardChanges = new HashMap<>();
forwardChanges.put(DESCRIPTION_CHANGED, PATCH);
forwardChanges.put(TITLE_CHANGED, PATCH);
forwardChanges.put(PROPERTIES_ADDED, MINOR);
forwardChanges.put(REQUIRED_ARRAY_EXTENDED, MINOR);
forwardChanges.put(ID_CHANGED, MAJOR);
forwardChanges.put(SCHEMA_REMOVED, MAJOR);
forwardChanges.put(TYPE_CHANGED, MAJOR);
forwardChanges.put(NUMBER_OF_ITEMS_CHANGED, MAJOR);
forwardChanges.put(PROPERTY_REMOVED, MAJOR);
forwardChanges.put(DEPENDENCY_ARRAY_CHANGED, MAJOR);
forwardChanges.put(DEPENDENCY_SCHEMA_CHANGED, MAJOR);
forwardChanges.put(COMPOSITION_METHOD_CHANGED, MAJOR);
forwardChanges.put(ATTRIBUTE_VALUE_CHANGED, MAJOR);
forwardChanges.put(ENUM_ARRAY_CHANGED, MAJOR);
forwardChanges.put(SUB_SCHEMA_CHANGED, MAJOR);
forwardChanges.put(DEPENDENCY_SCHEMA_REMOVED, MAJOR);
forwardChanges.put(REQUIRED_ARRAY_CHANGED, MAJOR);
forwardChanges.put(ADDITIONAL_PROPERTIES_CHANGED, MAJOR);
forwardChanges.put(ADDITIONAL_PROPERTIES_NARROWED, MINOR);
forwardChanges.put(ADDITIONAL_ITEMS_CHANGED, MAJOR);
final Map<SchemaChange.Type, String> errorMessage = new HashMap<>();
errorMessage.put(SCHEMA_REMOVED, "change not allowed");
errorMessage.put(TYPE_CHANGED, "schema types must be the same");
errorMessage.put(NUMBER_OF_ITEMS_CHANGED, "the number of schema items cannot be changed");
errorMessage.put(PROPERTY_REMOVED, "schema properties cannot be removed");
errorMessage.put(DEPENDENCY_ARRAY_CHANGED, "schema dependencies array cannot be changed");
errorMessage.put(DEPENDENCY_SCHEMA_CHANGED, "schema dependencies cannot be changed");
errorMessage.put(COMPOSITION_METHOD_CHANGED, "schema composition method changed");
errorMessage.put(ATTRIBUTE_VALUE_CHANGED, "change to attribute value not allowed");
errorMessage.put(ENUM_ARRAY_CHANGED, "enum array changed");
errorMessage.put(SUB_SCHEMA_CHANGED, "sub schema changed");
errorMessage.put(DEPENDENCY_SCHEMA_REMOVED, "dependency schema removed");
errorMessage.put(REQUIRED_ARRAY_CHANGED, "required array changed");
errorMessage.put(REQUIRED_ARRAY_EXTENDED, "required array changed");
errorMessage.put(ADDITIONAL_PROPERTIES_CHANGED, "change not allowed");
errorMessage.put(ADDITIONAL_PROPERTIES_NARROWED, "change not allowed");
errorMessage.put(ADDITIONAL_ITEMS_CHANGED, "change not allowed");
final SchemaDiff diff = new SchemaDiff();
return new SchemaEvolutionService(metaSchema, schemaEvolutionConstraints, diff, compatibleChanges, forwardChanges, errorMessage);
}
Aggregations