deimos-ruby 1.13.1 → 1.13.2
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 +3 -3
- data/spec/generators/schema_class/my_schema_with_complex_types_spec.rb +4 -3
- data/spec/schema_classes/generated.rb +22 -22
- data/spec/schema_classes/my_schema_with_complex_types.rb +34 -2
- data/spec/schemas/com/my-namespace/MySchemaWithComplexTypes.avsc +9 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f51b89a9bf8a619db4c9294092b5e7b4f78c075c35f4aa2bc39c547da99ec67c
|
4
|
+
data.tar.gz: e4da7d718fff36bb28ca249a788fbf78ad5f980e9fa32983ecf019cd53cd40b8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7ac325f814c79a29985cba298ef0cde7daa4b0c561ce155eee22dab15470b2c1a933f5baa0181fd9375500062fa89fc846dcb01504d10466645275fa3644ec53
|
7
|
+
data.tar.gz: 021dd749b7040b136f84fcc7142a207847a982e2ab889439486af4b5dc4267ed4eed25f4d71c9a6496c51d8e84f3bedc6220e3dbd1f0a0133bca8c8cc1fe24e5
|
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.2 - 2022-04-07
|
11
|
+
|
12
|
+
- Fix an issue with generating schema classes for schemas containing an enum with default value
|
13
|
+
|
10
14
|
# 1.13.1 - 2022-04-06
|
11
15
|
|
12
16
|
- Fix circular reference schema generation
|
data/lib/deimos/version.rb
CHANGED
@@ -88,7 +88,7 @@ module Deimos
|
|
88
88
|
@discovered_schemas = Set.new
|
89
89
|
schemas = collect_all_schemas(schema_base.schema_store.schemas.values)
|
90
90
|
|
91
|
-
sub_schemas = schemas.reject { |s| s.name == schema_base.schema }
|
91
|
+
sub_schemas = schemas.reject { |s| s.name == schema_base.schema }.sort_by(&:name)
|
92
92
|
@sub_schema_templates = sub_schemas.map do |schema|
|
93
93
|
_generate_class_template_from_schema(schema)
|
94
94
|
end
|
@@ -206,8 +206,8 @@ module Deimos
|
|
206
206
|
return ' nil' if default == :no_default || default.nil? || IGNORE_DEFAULTS.include?(field.name)
|
207
207
|
|
208
208
|
case field.type.type_sym
|
209
|
-
when :string
|
210
|
-
"
|
209
|
+
when :string, :enum
|
210
|
+
" \"#{default}\""
|
211
211
|
when :record
|
212
212
|
schema_name = Deimos::SchemaBackends::AvroBase.schema_classname(field.type)
|
213
213
|
class_instance = Utils::SchemaClass.instance(field.default, schema_name)
|
@@ -57,7 +57,7 @@ RSpec.describe Schemas::MySchemaWithComplexTypes do
|
|
57
57
|
end
|
58
58
|
|
59
59
|
let(:schema_fields) do
|
60
|
-
%w(test_id test_float test_int_array test_optional_int test_string_array some_integer_map some_record some_optional_record some_record_array some_record_map some_enum_array some_optional_enum)
|
60
|
+
%w(test_id test_float test_int_array test_optional_int test_string_array some_integer_map some_record some_optional_record some_record_array some_record_map some_enum_array some_optional_enum some_enum_with_default)
|
61
61
|
end
|
62
62
|
|
63
63
|
it 'should return the name of the schema and namespace' do
|
@@ -90,14 +90,15 @@ RSpec.describe Schemas::MySchemaWithComplexTypes do
|
|
90
90
|
'record_1' => { 'a_record_field' => 'field 5' },
|
91
91
|
'record_2' => { 'a_record_field' => 'field 6' }
|
92
92
|
},
|
93
|
-
'some_enum_array' => %w(sym1 sym2)
|
93
|
+
'some_enum_array' => %w(sym1 sym2),
|
94
|
+
'some_enum_with_default' => 'sym6'
|
94
95
|
}
|
95
96
|
|
96
97
|
expect(klass.as_json).to eq(payload_h)
|
97
98
|
end
|
98
99
|
|
99
100
|
it 'should return a JSON string of the payload' do
|
100
|
-
s = '{"test_id":"test id","test_float":1.2,"test_string_array":["abc","def"],"test_int_array":[123,456],"test_optional_int":123,"some_integer_map":{"int_1":1,"int_2":2},"some_record":{"a_record_field":"field 1"},"some_optional_record":{"a_record_field":"field 2"},"some_record_array":[{"a_record_field":"field 3"},{"a_record_field":"field 4"}],"some_record_map":{"record_1":{"a_record_field":"field 5"},"record_2":{"a_record_field":"field 6"}},"some_enum_array":["sym1","sym2"],"some_optional_enum":null}'
|
101
|
+
s = '{"test_id":"test id","test_float":1.2,"test_string_array":["abc","def"],"test_int_array":[123,456],"test_optional_int":123,"some_integer_map":{"int_1":1,"int_2":2},"some_record":{"a_record_field":"field 1"},"some_optional_record":{"a_record_field":"field 2"},"some_record_array":[{"a_record_field":"field 3"},{"a_record_field":"field 4"}],"some_record_map":{"record_1":{"a_record_field":"field 5"},"record_2":{"a_record_field":"field 6"}},"some_enum_array":["sym1","sym2"],"some_optional_enum":null,"some_enum_with_default":"sym6"}'
|
101
102
|
expect(klass.to_json).to eq(s)
|
102
103
|
end
|
103
104
|
end
|
@@ -3,28 +3,6 @@
|
|
3
3
|
# This file is autogenerated by Deimos, Do NOT modify
|
4
4
|
module Schemas
|
5
5
|
### Secondary Schema Classes ###
|
6
|
-
# Autogenerated Schema for Enum at com.my-namespace.AnEnum
|
7
|
-
class AnEnum < Deimos::SchemaClass::Enum
|
8
|
-
# @return ['sym1', 'sym2']
|
9
|
-
attr_accessor :an_enum
|
10
|
-
|
11
|
-
# :nodoc:
|
12
|
-
def initialize(an_enum)
|
13
|
-
super
|
14
|
-
self.an_enum = an_enum
|
15
|
-
end
|
16
|
-
|
17
|
-
# @override
|
18
|
-
def symbols
|
19
|
-
%w(sym1 sym2)
|
20
|
-
end
|
21
|
-
|
22
|
-
# @override
|
23
|
-
def to_h
|
24
|
-
@an_enum
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
6
|
# Autogenerated Schema for Record at com.my-namespace.ARecord
|
29
7
|
class ARecord < Deimos::SchemaClass::Record
|
30
8
|
### Attribute Accessors ###
|
@@ -55,6 +33,28 @@ module Schemas
|
|
55
33
|
end
|
56
34
|
end
|
57
35
|
|
36
|
+
# Autogenerated Schema for Enum at com.my-namespace.AnEnum
|
37
|
+
class AnEnum < Deimos::SchemaClass::Enum
|
38
|
+
# @return ['sym1', 'sym2']
|
39
|
+
attr_accessor :an_enum
|
40
|
+
|
41
|
+
# :nodoc:
|
42
|
+
def initialize(an_enum)
|
43
|
+
super
|
44
|
+
self.an_enum = an_enum
|
45
|
+
end
|
46
|
+
|
47
|
+
# @override
|
48
|
+
def symbols
|
49
|
+
%w(sym1 sym2)
|
50
|
+
end
|
51
|
+
|
52
|
+
# @override
|
53
|
+
def to_h
|
54
|
+
@an_enum
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
58
|
### Primary Schema Class ###
|
59
59
|
# Autogenerated Schema for Record at com.my-namespace.Generated
|
60
60
|
class Generated < Deimos::SchemaClass::Record
|
@@ -77,6 +77,28 @@ module Schemas
|
|
77
77
|
end
|
78
78
|
end
|
79
79
|
|
80
|
+
# Autogenerated Schema for Enum at com.my-namespace.YetAnotherEnum
|
81
|
+
class YetAnotherEnum < Deimos::SchemaClass::Enum
|
82
|
+
# @return ['sym5', 'sym6']
|
83
|
+
attr_accessor :yet_another_enum
|
84
|
+
|
85
|
+
# :nodoc:
|
86
|
+
def initialize(yet_another_enum)
|
87
|
+
super
|
88
|
+
self.yet_another_enum = yet_another_enum
|
89
|
+
end
|
90
|
+
|
91
|
+
# @override
|
92
|
+
def symbols
|
93
|
+
%w(sym5 sym6)
|
94
|
+
end
|
95
|
+
|
96
|
+
# @override
|
97
|
+
def to_h
|
98
|
+
@yet_another_enum
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
80
102
|
### Primary Schema Class ###
|
81
103
|
# Autogenerated Schema for Record at com.my-namespace.MySchemaWithComplexTypes
|
82
104
|
class MySchemaWithComplexTypes < Deimos::SchemaClass::Record
|
@@ -93,6 +115,8 @@ module Schemas
|
|
93
115
|
attr_reader :some_enum_array
|
94
116
|
# @return [nil, AnotherEnum]
|
95
117
|
attr_reader :some_optional_enum
|
118
|
+
# @return [YetAnotherEnum]
|
119
|
+
attr_reader :some_enum_with_default
|
96
120
|
|
97
121
|
### Attribute Accessors ###
|
98
122
|
# @param value [String]
|
@@ -145,6 +169,11 @@ module Schemas
|
|
145
169
|
@some_optional_enum = AnotherEnum.initialize_from_value(value)
|
146
170
|
end
|
147
171
|
|
172
|
+
# @param value [YetAnotherEnum]
|
173
|
+
def some_enum_with_default=(value)
|
174
|
+
@some_enum_with_default = YetAnotherEnum.initialize_from_value(value)
|
175
|
+
end
|
176
|
+
|
148
177
|
# @override
|
149
178
|
def initialize(test_id: nil,
|
150
179
|
test_float: nil,
|
@@ -157,7 +186,8 @@ module Schemas
|
|
157
186
|
some_record_array: nil,
|
158
187
|
some_record_map: nil,
|
159
188
|
some_enum_array: nil,
|
160
|
-
some_optional_enum: nil
|
189
|
+
some_optional_enum: nil,
|
190
|
+
some_enum_with_default: "sym6")
|
161
191
|
super
|
162
192
|
self.test_id = test_id
|
163
193
|
self.test_float = test_float
|
@@ -171,6 +201,7 @@ module Schemas
|
|
171
201
|
self.some_record_map = some_record_map
|
172
202
|
self.some_enum_array = some_enum_array
|
173
203
|
self.some_optional_enum = some_optional_enum
|
204
|
+
self.some_enum_with_default = some_enum_with_default
|
174
205
|
end
|
175
206
|
|
176
207
|
# @override
|
@@ -197,7 +228,8 @@ module Schemas
|
|
197
228
|
'some_record_array' => @some_record_array.map { |v| v&.to_h },
|
198
229
|
'some_record_map' => @some_record_map.transform_values { |v| v&.to_h },
|
199
230
|
'some_enum_array' => @some_enum_array.map { |v| v&.to_h },
|
200
|
-
'some_optional_enum' => @some_optional_enum&.to_h
|
231
|
+
'some_optional_enum' => @some_optional_enum&.to_h,
|
232
|
+
'some_enum_with_default' => @some_enum_with_default&.to_h
|
201
233
|
}
|
202
234
|
end
|
203
235
|
end
|
@@ -101,6 +101,15 @@
|
|
101
101
|
"symbols": ["sym3", "sym4"]
|
102
102
|
}
|
103
103
|
]
|
104
|
+
},
|
105
|
+
{
|
106
|
+
"name": "some_enum_with_default",
|
107
|
+
"default": "sym6",
|
108
|
+
"type": {
|
109
|
+
"type": "enum",
|
110
|
+
"name": "YetAnotherEnum",
|
111
|
+
"symbols": ["sym5", "sym6"]
|
112
|
+
}
|
104
113
|
}
|
105
114
|
]
|
106
115
|
}
|
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.2
|
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-04-
|
11
|
+
date: 2022-04-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: avro_turf
|