Skip to content

Commit

Permalink
Merge pull request #212 from catkins/catkins/verbose-compatibility
Browse files Browse the repository at this point in the history
Add ConfluentSchemaRegistry#compatibility_issues for debugging breaking changes
  • Loading branch information
dasch authored Oct 7, 2024
2 parents 6e15b78 + 5e15cea commit b21dae2
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Unreleased

- Add `compatibility_issues` method to `ConfluentSchemaRegistry` to debug compatibility issues between a schema versions for a given subject (#212)

## v1.17.0

- Add `register_schemas` option to `encode` method [#210](https://github.com/dasch/avro_turf/pull/210)
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,9 @@ registry = AvroTurf::ConfluentSchemaRegistry.new("http://my-registry:8081/")

# Returns true if the schema is compatible, nil if the subject or version is not registered, and false if incompatible.
registry.compatible?("person", schema)

# Returns an array of any breaking changes, nil if the subject or version is not registered
registry.compatibility_issues("person", schema)
```

The ConfluentSchemaRegistry client can also change the global compatibility level or the compatibility level for an individual subject using the [Config API](http://docs.confluent.io/3.1.2/schema-registry/docs/api.html#config):
Expand Down
12 changes: 12 additions & 0 deletions lib/avro_turf/confluent_schema_registry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,18 @@ def compatible?(subject, schema, version = 'latest')
data.fetch('is_compatible', false) unless data.has_key?('error_code')
end

# Check for specific schema compatibility issues
# Returns:
# - nil if the subject or version does not exist
# - a list of compatibility issues
# https://docs.confluent.io/platform/current/schema-registry/develop/api.html#sr-api-compatibility
def compatibility_issues(subject, schema, version = 'latest')
data = post("/compatibility/subjects/#{@schema_context_prefix}#{subject}/versions/#{version}",
expects: [200, 404], body: { schema: schema.to_s }.to_json, query: { verbose: true }, idempotent: true)

data.fetch('messages', []) unless data.has_key?('error_code')
end

# Get global config
def global_config
get("/config", idempotent: true)
Expand Down

0 comments on commit b21dae2

Please sign in to comment.