use of io.confluent.kafka.schemaregistry.exceptions.InvalidSchemaException in project schema-registry by confluentinc.
the class KafkaSchemaRegistry method canonicalizeSchema.
private ParsedSchema canonicalizeSchema(Schema schema, boolean isNew, boolean normalize) throws InvalidSchemaException {
if (schema == null || schema.getSchema() == null || schema.getSchema().trim().isEmpty()) {
log.error("Empty schema");
throw new InvalidSchemaException("Empty schema");
}
ParsedSchema parsedSchema = parseSchema(schema, isNew);
try {
parsedSchema.validate();
} catch (Exception e) {
String errMsg = "Invalid schema " + schema + ", details: " + e.getMessage();
log.error(errMsg, e);
throw new InvalidSchemaException(errMsg, e);
}
if (normalize) {
parsedSchema = parsedSchema.normalize();
}
schema.setSchema(parsedSchema.canonicalString());
schema.setReferences(parsedSchema.references());
return parsedSchema;
}
Aggregations