deimos-ruby 1.13.0 → 1.13.1
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 +4 -4
- data/CHANGELOG.md +4 -0
- data/lib/deimos/version.rb +1 -1
- data/lib/generators/deimos/schema_class_generator.rb +6 -1
- data/spec/generators/schema_class/my_schema_with_circular_reference_spec.rb +97 -0
- data/spec/generators/schema_class_generator_spec.rb +26 -0
- data/spec/schema_classes/my_schema_with_circular_reference.rb +74 -0
- data/spec/schemas/com/my-namespace/MySchemaWithCircularReference.avsc +39 -0
- metadata +8 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2fe5f643562c8cebecd6991d31222c3809115cee282b2f8fcef0e36b1b19f972
|
4
|
+
data.tar.gz: a9de46de1265d73a7d94e94f24c43a0c210687b93f4862a7a2fefee73c40fb89
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0365bcefe9cd82d91bf9f5eb587f6f72725f0ef981336722571465e8308d615b69fabc7516755761ebdad473ba1b8e0027e1546a81076d1bdf5c9c8cfe5e9d0f
|
7
|
+
data.tar.gz: 5e4f15b372217ac878b9c82ab606c90e16a0a370947956bef2b6aae5ffa4ac8c4739ff74e10d7bf442c29968ee0bba0135624d7be2966d51b85d8c777f2e2573
|
data/CHANGELOG.md
CHANGED
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
7
7
|
|
8
8
|
## UNRELEASED
|
9
9
|
|
10
|
+
# 1.13.1 - 2022-04-06
|
11
|
+
|
12
|
+
- Fix circular reference schema generation
|
13
|
+
|
10
14
|
# 1.13.0 - 2022-03-30
|
11
15
|
|
12
16
|
- Pass the Deimos logger to `AvroTurf::Messaging` for consistent logging
|
data/lib/deimos/version.rb
CHANGED
@@ -63,7 +63,7 @@ module Deimos
|
|
63
63
|
elsif schema.respond_to?(:items)
|
64
64
|
[schema.items]
|
65
65
|
elsif schema.respond_to?(:schemas)
|
66
|
-
schema.schemas
|
66
|
+
schema.schemas.reject { |s| s.class == Avro::Schema::PrimitiveSchema }
|
67
67
|
else
|
68
68
|
[]
|
69
69
|
end
|
@@ -73,14 +73,19 @@ module Deimos
|
|
73
73
|
# @return [Array<Avro::Schema::NamedSchema>]
|
74
74
|
def collect_all_schemas(schemas)
|
75
75
|
schemas.dup.each do |schema|
|
76
|
+
next if @discovered_schemas.include?(schema)
|
77
|
+
|
78
|
+
@discovered_schemas << schema
|
76
79
|
schemas.concat(collect_all_schemas(child_schemas(schema)))
|
77
80
|
end
|
81
|
+
|
78
82
|
schemas.select { |s| s.respond_to?(:name) }.uniq
|
79
83
|
end
|
80
84
|
|
81
85
|
# @param schema_base [Deimos::SchemaBackends::Base]
|
82
86
|
# @param key_schema_base[Avro::Schema::NamedSchema]
|
83
87
|
def generate_class_from_schema_base(schema_base, key_schema_base: nil)
|
88
|
+
@discovered_schemas = Set.new
|
84
89
|
schemas = collect_all_schemas(schema_base.schema_store.schemas.values)
|
85
90
|
|
86
91
|
sub_schemas = schemas.reject { |s| s.name == schema_base.schema }
|
@@ -0,0 +1,97 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# For testing the generated class.
|
4
|
+
RSpec.describe Schemas::MySchemaWithCircularReference do
|
5
|
+
let(:payload_hash) do
|
6
|
+
{
|
7
|
+
properties: {
|
8
|
+
a_boolean: {
|
9
|
+
property: true
|
10
|
+
},
|
11
|
+
an_integer: {
|
12
|
+
property: 1
|
13
|
+
},
|
14
|
+
a_float: {
|
15
|
+
property: 4.5
|
16
|
+
},
|
17
|
+
a_string: {
|
18
|
+
property: 'string'
|
19
|
+
},
|
20
|
+
an_array: {
|
21
|
+
property: [1, 2, 3]
|
22
|
+
},
|
23
|
+
an_hash: {
|
24
|
+
property: {
|
25
|
+
a_key: 'a_value'
|
26
|
+
}
|
27
|
+
}
|
28
|
+
}
|
29
|
+
}
|
30
|
+
end
|
31
|
+
|
32
|
+
describe 'class initialization' do
|
33
|
+
it 'should initialize the class from keyword arguments' do
|
34
|
+
klass = described_class.new(properties: payload_hash[:properties])
|
35
|
+
expect(klass).to be_instance_of(described_class)
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'should initialize the class from a hash with symbols as keys' do
|
39
|
+
klass = described_class.new(**payload_hash)
|
40
|
+
expect(klass).to be_instance_of(described_class)
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'should initialize the class when missing attributes' do
|
44
|
+
payload_hash.delete(:properties)
|
45
|
+
klass = described_class.new(**payload_hash)
|
46
|
+
expect(klass).to be_instance_of(described_class)
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
|
51
|
+
describe 'base class methods' do
|
52
|
+
let(:klass) do
|
53
|
+
described_class.new(**payload_hash)
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'should return the name of the schema and namespace' do
|
57
|
+
expect(klass.schema).to eq('MySchemaWithCircularReference')
|
58
|
+
expect(klass.namespace).to eq('com.my-namespace')
|
59
|
+
expect(klass.full_schema).to eq('com.my-namespace.MySchemaWithCircularReference')
|
60
|
+
end
|
61
|
+
|
62
|
+
it 'should return a json version of the payload' do
|
63
|
+
described_class.new(**payload_hash)
|
64
|
+
payload_h = {
|
65
|
+
'properties' => {
|
66
|
+
'a_boolean' => {
|
67
|
+
'property' => true
|
68
|
+
},
|
69
|
+
'an_integer' => {
|
70
|
+
'property' => 1
|
71
|
+
},
|
72
|
+
'a_float' => {
|
73
|
+
'property' => 4.5
|
74
|
+
},
|
75
|
+
'a_string' => {
|
76
|
+
'property' => 'string'
|
77
|
+
},
|
78
|
+
'an_array' => {
|
79
|
+
'property' => [1, 2, 3]
|
80
|
+
},
|
81
|
+
'an_hash' => {
|
82
|
+
'property' => {
|
83
|
+
'a_key' => 'a_value'
|
84
|
+
}
|
85
|
+
}
|
86
|
+
}
|
87
|
+
}
|
88
|
+
|
89
|
+
expect(klass.as_json).to eq(payload_h)
|
90
|
+
end
|
91
|
+
|
92
|
+
it 'should return a JSON string of the payload' do
|
93
|
+
s = '{"properties":{"a_boolean":{"property":true},"an_integer":{"property":1},"a_float":{"property":4.5},"a_string":{"property":"string"},"an_array":{"property":[1,2,3]},"an_hash":{"property":{"a_key":"a_value"}}}}'
|
94
|
+
expect(klass.to_json).to eq(s)
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
@@ -73,6 +73,32 @@ RSpec.describe Deimos::Generators::SchemaClassGenerator do
|
|
73
73
|
end
|
74
74
|
end
|
75
75
|
|
76
|
+
context 'with a Consumers Schema with a circular reference' do
|
77
|
+
before(:each) do
|
78
|
+
Deimos.configure do
|
79
|
+
consumer do
|
80
|
+
class_name 'ConsumerTest::MyConsumer'
|
81
|
+
topic 'MyTopic'
|
82
|
+
schema 'MySchemaWithCircularReference'
|
83
|
+
namespace 'com.my-namespace'
|
84
|
+
key_config field: :a_string
|
85
|
+
end
|
86
|
+
end
|
87
|
+
described_class.start
|
88
|
+
end
|
89
|
+
|
90
|
+
it 'should generate the correct number of classes' do
|
91
|
+
expect(files.length).to eq(1)
|
92
|
+
end
|
93
|
+
|
94
|
+
it 'should generate a schema class for my_schema_with_circular_reference' do
|
95
|
+
generated_path = files.select { |f| f =~ /my_schema_with_circular_reference/ }.first
|
96
|
+
expected_path = expected_files.select { |f| f =~ /my_schema_with_circular_reference/ }.first
|
97
|
+
|
98
|
+
expect(File.read(generated_path)).to eq(File.read(expected_path))
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
76
102
|
context 'with a Producers Schema and a Key' do
|
77
103
|
before(:each) do
|
78
104
|
Deimos.configure do
|
@@ -0,0 +1,74 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# This file is autogenerated by Deimos, Do NOT modify
|
4
|
+
module Schemas
|
5
|
+
### Secondary Schema Classes ###
|
6
|
+
# Autogenerated Schema for Record at com.my-namespace.Property
|
7
|
+
class Property < Deimos::SchemaClass::Record
|
8
|
+
### Attribute Accessors ###
|
9
|
+
# @param value [Boolean, Integer, Integer, Float, Float, String, Array<Property>, Hash<String, Property>]
|
10
|
+
attr_accessor :property
|
11
|
+
|
12
|
+
# @override
|
13
|
+
def initialize(property: nil)
|
14
|
+
super
|
15
|
+
self.property = property
|
16
|
+
end
|
17
|
+
|
18
|
+
# @override
|
19
|
+
def schema
|
20
|
+
'Property'
|
21
|
+
end
|
22
|
+
|
23
|
+
# @override
|
24
|
+
def namespace
|
25
|
+
'com.my-namespace'
|
26
|
+
end
|
27
|
+
|
28
|
+
# @override
|
29
|
+
def to_h
|
30
|
+
{
|
31
|
+
'property' => @property
|
32
|
+
}
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
### Primary Schema Class ###
|
37
|
+
# Autogenerated Schema for Record at com.my-namespace.MySchemaWithCircularReference
|
38
|
+
class MySchemaWithCircularReference < Deimos::SchemaClass::Record
|
39
|
+
### Attribute Readers ###
|
40
|
+
# @return [Hash<String, Property>]
|
41
|
+
attr_reader :properties
|
42
|
+
|
43
|
+
### Attribute Writers ###
|
44
|
+
# @param values [Hash<String, Property>]
|
45
|
+
def properties=(values)
|
46
|
+
@properties = values.transform_values do |value|
|
47
|
+
Property.initialize_from_value(value)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
# @override
|
52
|
+
def initialize(properties: {})
|
53
|
+
super
|
54
|
+
self.properties = properties
|
55
|
+
end
|
56
|
+
|
57
|
+
# @override
|
58
|
+
def schema
|
59
|
+
'MySchemaWithCircularReference'
|
60
|
+
end
|
61
|
+
|
62
|
+
# @override
|
63
|
+
def namespace
|
64
|
+
'com.my-namespace'
|
65
|
+
end
|
66
|
+
|
67
|
+
# @override
|
68
|
+
def to_h
|
69
|
+
{
|
70
|
+
'properties' => @properties.transform_values { |v| v&.to_h }
|
71
|
+
}
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
{
|
2
|
+
"namespace": "com.my-namespace",
|
3
|
+
"name": "MySchemaWithCircularReference",
|
4
|
+
"type": "record",
|
5
|
+
"fields": [
|
6
|
+
{
|
7
|
+
"default": {},
|
8
|
+
"name": "properties",
|
9
|
+
"type": {
|
10
|
+
"type": "map",
|
11
|
+
"values": {
|
12
|
+
"fields": [
|
13
|
+
{
|
14
|
+
"name": "property",
|
15
|
+
"type": [
|
16
|
+
"boolean",
|
17
|
+
"int",
|
18
|
+
"long",
|
19
|
+
"float",
|
20
|
+
"double",
|
21
|
+
"string",
|
22
|
+
{
|
23
|
+
"items": "Property",
|
24
|
+
"type": "array"
|
25
|
+
},
|
26
|
+
{
|
27
|
+
"type": "map",
|
28
|
+
"values": "Property"
|
29
|
+
}
|
30
|
+
]
|
31
|
+
}
|
32
|
+
],
|
33
|
+
"name": "Property",
|
34
|
+
"type": "record"
|
35
|
+
}
|
36
|
+
}
|
37
|
+
}
|
38
|
+
]
|
39
|
+
}
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: deimos-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.13.
|
4
|
+
version: 1.13.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Orner
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-04-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: avro_turf
|
@@ -463,6 +463,7 @@ files:
|
|
463
463
|
- spec/consumer_spec.rb
|
464
464
|
- spec/deimos_spec.rb
|
465
465
|
- spec/generators/active_record_generator_spec.rb
|
466
|
+
- spec/generators/schema_class/my_schema_with_circular_reference_spec.rb
|
466
467
|
- spec/generators/schema_class/my_schema_with_complex_types_spec.rb
|
467
468
|
- spec/generators/schema_class_generator_spec.rb
|
468
469
|
- spec/handlers/my_batch_consumer.rb
|
@@ -484,12 +485,14 @@ files:
|
|
484
485
|
- spec/schema_classes/my_nested_schema.rb
|
485
486
|
- spec/schema_classes/my_schema.rb
|
486
487
|
- spec/schema_classes/my_schema_key.rb
|
488
|
+
- spec/schema_classes/my_schema_with_circular_reference.rb
|
487
489
|
- spec/schema_classes/my_schema_with_complex_types.rb
|
488
490
|
- spec/schemas/com/my-namespace/Generated.avsc
|
489
491
|
- spec/schemas/com/my-namespace/MyNestedSchema.avsc
|
490
492
|
- spec/schemas/com/my-namespace/MySchema.avsc
|
491
493
|
- spec/schemas/com/my-namespace/MySchemaCompound_key.avsc
|
492
494
|
- spec/schemas/com/my-namespace/MySchemaWithBooleans.avsc
|
495
|
+
- spec/schemas/com/my-namespace/MySchemaWithCircularReference.avsc
|
493
496
|
- spec/schemas/com/my-namespace/MySchemaWithComplexTypes.avsc
|
494
497
|
- spec/schemas/com/my-namespace/MySchemaWithDateTimes.avsc
|
495
498
|
- spec/schemas/com/my-namespace/MySchemaWithId.avsc
|
@@ -554,6 +557,7 @@ test_files:
|
|
554
557
|
- spec/consumer_spec.rb
|
555
558
|
- spec/deimos_spec.rb
|
556
559
|
- spec/generators/active_record_generator_spec.rb
|
560
|
+
- spec/generators/schema_class/my_schema_with_circular_reference_spec.rb
|
557
561
|
- spec/generators/schema_class/my_schema_with_complex_types_spec.rb
|
558
562
|
- spec/generators/schema_class_generator_spec.rb
|
559
563
|
- spec/handlers/my_batch_consumer.rb
|
@@ -575,12 +579,14 @@ test_files:
|
|
575
579
|
- spec/schema_classes/my_nested_schema.rb
|
576
580
|
- spec/schema_classes/my_schema.rb
|
577
581
|
- spec/schema_classes/my_schema_key.rb
|
582
|
+
- spec/schema_classes/my_schema_with_circular_reference.rb
|
578
583
|
- spec/schema_classes/my_schema_with_complex_types.rb
|
579
584
|
- spec/schemas/com/my-namespace/Generated.avsc
|
580
585
|
- spec/schemas/com/my-namespace/MyNestedSchema.avsc
|
581
586
|
- spec/schemas/com/my-namespace/MySchema.avsc
|
582
587
|
- spec/schemas/com/my-namespace/MySchemaCompound_key.avsc
|
583
588
|
- spec/schemas/com/my-namespace/MySchemaWithBooleans.avsc
|
589
|
+
- spec/schemas/com/my-namespace/MySchemaWithCircularReference.avsc
|
584
590
|
- spec/schemas/com/my-namespace/MySchemaWithComplexTypes.avsc
|
585
591
|
- spec/schemas/com/my-namespace/MySchemaWithDateTimes.avsc
|
586
592
|
- spec/schemas/com/my-namespace/MySchemaWithId.avsc
|