Skip to content

Commit

Permalink
Merge pull request #203 from piotaixr/debug/load-nested-schemas
Browse files Browse the repository at this point in the history
Use default namespace to load nested schemas from the correct namespace
  • Loading branch information
dasch authored Oct 4, 2023
2 parents a8b0ba4 + e5fe647 commit 0f43ee0
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 3 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## Unreleased

- Use `default_namespace` from exception to load nested schemas from the correct namespace. (#203)
- Bump minimum avro version to 1.11.3

## v1.14.0

- Add `resolv_resolver` parameter to `AvroTurf::Messaging` to make use of custom domain name resolvers and their options, for example `nameserver` and `timeouts` (#202)
Expand Down
2 changes: 1 addition & 1 deletion avro_turf.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Gem::Specification.new do |spec|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
spec.require_paths = ["lib"]

spec.add_dependency "avro", ">= 1.8.0", "< 1.12"
spec.add_dependency "avro", ">= 1.11.3", "< 1.12"
spec.add_dependency "excon", "~> 0.104"

spec.add_development_dependency "bundler", "~> 2.0"
Expand Down
2 changes: 1 addition & 1 deletion lib/avro_turf/schema_store.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def load_schema!(fullname, local_schemas_cache = {})
# Try to first resolve a referenced schema from disk.
# If this is successful, the Avro gem will have mutated the
# local_schemas_cache, adding all the new schemas it found.
load_schema!(e.type_name, local_schemas_cache)
load_schema!(::Avro::Name.make_fullname(e.type_name, e.default_namespace), local_schemas_cache)

# Attempt to re-parse the original schema now that the dependency
# has been resolved and use the now-updated local_schemas_cache to
Expand Down
29 changes: 29 additions & 0 deletions spec/schema_store_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,35 @@
expect(schema.fullname).to eq "message"
end

it 'searches for nested types with the correct namespace' do
define_schema "foo/bar.avsc", <<-AVSC
{
"type": "record",
"namespace": "foo",
"name": "bar",
"fields": [
{
"name": "another",
"type": "another_schema"
}
]
}
AVSC

define_schema "foo/another_schema.avsc", <<-AVSC
{
"namespace": "foo",
"name": "another_schema",
"type": "record",
"fields": [ { "name": "str", "type": "string" } ]
}
AVSC

schema = store.find('foo.bar')
expect(schema.fullname).to eq "foo.bar"
expect(schema.fields.first.type.fullname).to eq "foo.another_schema"
end

it "resolves missing references when nested schema is not a named type" do
define_schema "root.avsc", <<-AVSC
{
Expand Down
5 changes: 4 additions & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@

module Helpers
def define_schema(path, content)
File.open(File.join("spec/schemas", path), "w") do |f|
file = File.join("spec/schemas", path)
dir = File.dirname(file)
FileUtils.mkdir_p(dir)
File.open(file, "w") do |f|
f.write(content)
end
end
Expand Down

0 comments on commit 0f43ee0

Please sign in to comment.