avro_turf 1.6.0 → 1.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: db17e2aed8677c0288cd1c817b2e4ecae50da47255663c2b0a75d64a43e91152
4
- data.tar.gz: e88f6481337b05b80db9710283daf20818fcad9621c09ca9ebd75e533ca5135c
3
+ metadata.gz: 3eea429db02f7f6eba5f13f46b2bf3e82602371ef9306e374c1102561f508675
4
+ data.tar.gz: d798ef10b0e674f48ffdcc6bd3b87e59d9447c985d539f2ba01164e689fe4f8a
5
5
  SHA512:
6
- metadata.gz: 3c226b186752b4feed4519d329e7789dc02ad29793d3573ca2832a182074010652c16746308f785320018bed528d00b241c9b6354b2a3271a72278812d552d56
7
- data.tar.gz: c07515285fbd182752764d43c350d529f9a60bce1ad7d7aa6992cb1cda9fb958c189092d78a432a6e141eca380c8e9459857b29e2b038f03e32b645f5b4f0461
6
+ metadata.gz: e7cacb60d4e7890a700ebaba9a0cf1d46606fb01157e0746a0d6a6c900895e9ca1268f0a04dd4d03f5d1a9cec9bf6795d9c5d70acb6884965353c72bb1de4095
7
+ data.tar.gz: c4dbd604b66916355a6cba44ec4e7225eb439c2d9bb0682e62414b6ffa3018bb1d2a84b78d943983c99d7af3897a67658db9cb2205f7d92d6c13661ae44ba602
data/CHANGELOG.md CHANGED
@@ -2,6 +2,11 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## v1.7.0
6
+
7
+ - Added extra params for the validation message schem before encode (#169)
8
+ - Fix infinite retry when loading schema with nested primary type in separate file (#165)
9
+
5
10
  ## v1.6.0
6
11
 
7
12
  - Schema registry path prefix (#162)
@@ -88,7 +88,7 @@ class AvroTurf::SchemaStore
88
88
  local_schemas_cache.each do |schema_name, schema|
89
89
  local_schemas_cache.delete(schema_name) unless File.exist?(build_schema_path(schema_name))
90
90
  end
91
- load_schema!(fullname, local_schemas_cache)
91
+ load_schema!(fullname, @schemas.dup)
92
92
  else
93
93
  raise
94
94
  end
@@ -1,3 +1,3 @@
1
1
  class AvroTurf
2
- VERSION = "1.6.0"
2
+ VERSION = "1.7.0"
3
3
  end
data/lib/avro_turf.rb CHANGED
@@ -16,7 +16,9 @@ end
16
16
 
17
17
  class AvroTurf
18
18
  class Error < StandardError; end
19
+
19
20
  class SchemaError < Error; end
21
+
20
22
  class SchemaNotFoundError < Error; end
21
23
 
22
24
  DEFAULT_SCHEMAS_PATH = "./schemas"
@@ -31,7 +33,7 @@ class AvroTurf
31
33
  # Currently, the only valid codec name is `deflate`.
32
34
  def initialize(schemas_path: nil, schema_store: nil, namespace: nil, codec: nil)
33
35
  @namespace = namespace
34
- @schema_store = schema_store ||
36
+ @schema_store = schema_store ||
35
37
  SchemaStore.new(path: schemas_path || DEFAULT_SCHEMAS_PATH)
36
38
  @codec = codec
37
39
  end
@@ -62,14 +64,20 @@ class AvroTurf
62
64
  # validate - The boolean for performing complete data validation before
63
65
  # encoding it, Avro::SchemaValidator::ValidationError with
64
66
  # a descriptive message will be raised in case of invalid message.
67
+ # validate_options - Hash for the Avro::SchemaValidator, default
68
+ # {recursive: true, encoded: false, fail_on_extra_fields: true}
65
69
  #
66
70
  # Returns nothing.
67
- def encode_to_stream(data, schema_name: nil, stream: nil, namespace: @namespace, validate: false)
71
+ def encode_to_stream(data, schema_name: nil, stream: nil, namespace: @namespace,
72
+ validate: false,
73
+ validate_options: { recursive: true,
74
+ encoded: false,
75
+ fail_on_extra_fields: true })
68
76
  schema = @schema_store.find(schema_name, namespace)
69
77
  writer = Avro::IO::DatumWriter.new(schema)
70
78
 
71
79
  if validate
72
- Avro::SchemaValidator.validate!(schema, data, recursive: true, encoded: false, fail_on_extra_fields: true)
80
+ Avro::SchemaValidator.validate!(schema, data, **validate_options)
73
81
  end
74
82
 
75
83
  dw = Avro::DataFile::Writer.new(stream, writer, schema, @codec)
@@ -251,6 +251,31 @@ describe AvroTurf do
251
251
  expect { encode_to_stream }.to raise_error(Avro::SchemaValidator::ValidationError, /extra field 'fulll_name'/)
252
252
  end
253
253
  end
254
+
255
+ context "when the `fail_on_extra_fields` validation option is disabled" do
256
+ let(:message) { { "full_name" => "John Doe", "first_name" => "John", "last_name" => "Doe" } }
257
+ subject(:encode_to_stream) do
258
+ stream = StringIO.new
259
+ avro.encode_to_stream(message, stream: stream, schema_name: "message",
260
+ validate: true,
261
+ validate_options: { recursive: true, encoded: false, fail_on_extra_fields: false }
262
+ )
263
+ end
264
+
265
+ it "should not raise Avro::SchemaValidator::ValidationError with a message about extra field" do
266
+ define_schema "message.avsc", <<-AVSC
267
+ {
268
+ "name": "message",
269
+ "type": "record",
270
+ "fields": [
271
+ { "name": "full_name", "type": "string" }
272
+ ]
273
+ }
274
+ AVSC
275
+
276
+ expect { encode_to_stream }.not_to raise_error
277
+ end
278
+ end
254
279
  end
255
280
  end
256
281
 
@@ -26,6 +26,33 @@ describe AvroTurf::SchemaStore do
26
26
  expect(schema.fullname).to eq "message"
27
27
  end
28
28
 
29
+ it "resolves missing references when nested schema is not a named type" do
30
+ define_schema "root.avsc", <<-AVSC
31
+ {
32
+ "type": "record",
33
+ "name": "root",
34
+ "fields": [
35
+ {
36
+ "type": "nested",
37
+ "name": "nested_value"
38
+ }
39
+ ]
40
+ }
41
+ AVSC
42
+
43
+ define_schema "nested.avsc", <<-AVSC
44
+ {
45
+ "name": "nested",
46
+ "type": "string",
47
+ "logicalType": "uuid"
48
+ }
49
+ AVSC
50
+
51
+ schema = store.find("root")
52
+
53
+ expect(schema.fullname).to eq "root"
54
+ end
55
+
29
56
  it "resolves missing references" do
30
57
  define_schema "person.avsc", <<-AVSC
31
58
  {
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: avro_turf
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.0
4
+ version: 1.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Schierbeck
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-06-24 00:00:00.000000000 Z
11
+ date: 2022-07-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: avro
@@ -156,7 +156,7 @@ dependencies:
156
156
  - - ">="
157
157
  - !ruby/object:Gem::Version
158
158
  version: '0'
159
- description:
159
+ description:
160
160
  email:
161
161
  - dasch@zendesk.com
162
162
  executables: []
@@ -251,8 +251,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
251
251
  - !ruby/object:Gem::Version
252
252
  version: '0'
253
253
  requirements: []
254
- rubygems_version: 3.1.2
255
- signing_key:
254
+ rubygems_version: 3.3.3
255
+ signing_key:
256
256
  specification_version: 4
257
257
  summary: A library that makes it easier to use the Avro serialization format from
258
258
  Ruby