confluentinc / schema-registry

Confluent Schema Registry for Kafka
https://docs.confluent.io/current/schema-registry/docs/index.html
Other
2.23k stars 1.11k forks source link

Client method `getSchemas()` does not inform about the version of the returned AVRO schemas #3280

Open fmiguelez opened 1 month ago

fmiguelez commented 1 month ago

Even though REST call to endpoint /schemas returns corresponding version with each schema entry, in the object ParsedSchema (implemented by AvroSchema) is set to null.

The BUG is in this line of AvroSchemaProvider:

https://github.com/confluentinc/schema-registry/blob/9e7ab57e7f1d5664bc08f42ad9678c5b68a769d8/client/src/main/java/io/confluent/kafka/schemaregistry/avro/AvroSchemaProvider.java#L55C11-L55C15

It should set the version that comes in Schema object:

  @Override
  public ParsedSchema parseSchemaOrElseThrow(Schema schema, boolean isNew, boolean normalize) {
    try {
      return new AvroSchema(
          schema.getSchema(),
          schema.getReferences(),
          resolveReferences(schema),
          schema.getMetadata(),
          schema.getRuleSet(),
          schema.getVersion(), // Proposed change
          (validateDefaults || normalize) && isNew
      );
    } catch (Exception e) {
      log.error("Could not parse Avro schema", e);
      throw e;
    }
  }