deimos-ruby 1.13.3 → 1.14.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 +4 -4
- data/CHANGELOG.md +7 -0
- data/README.md +6 -0
- data/deimos-ruby.gemspec +1 -0
- data/lib/deimos/config/configuration.rb +4 -0
- data/lib/deimos/schema_backends/avro_base.rb +1 -1
- data/lib/deimos/version.rb +1 -1
- data/lib/generators/deimos/schema_class/templates/schema_class.rb.tt +0 -7
- data/lib/generators/deimos/schema_class/templates/schema_record.rb.tt +10 -1
- data/lib/generators/deimos/schema_class_generator.rb +19 -7
- data/spec/generators/active_record_generator_spec.rb +4 -2
- data/spec/generators/schema_class/my_schema_with_complex_types_spec.rb +37 -24
- data/spec/generators/schema_class_generator_spec.rb +93 -55
- data/spec/producer_spec.rb +1 -1
- data/spec/schemas/generated.rb +159 -0
- data/spec/schemas/my_nested_schema.rb +117 -0
- data/spec/{schema_classes → schemas}/my_schema.rb +1 -0
- data/spec/{schema_classes → schemas}/my_schema_key.rb +1 -0
- data/spec/schemas/my_schema_with_circular_reference.rb +77 -0
- data/spec/schemas/my_schema_with_complex_type.rb +239 -0
- data/spec/{schema_classes/generated.rb → snapshots/consumers-no-nest.snap} +20 -1
- data/spec/snapshots/consumers.snap +161 -0
- data/spec/snapshots/consumers_and_producers-no-nest.snap +397 -0
- data/spec/snapshots/consumers_and_producers.snap +377 -0
- data/spec/{schema_classes/my_schema_with_circular_reference.rb → snapshots/consumers_circular-no-nest.snap} +37 -26
- data/spec/snapshots/consumers_circular.snap +79 -0
- data/spec/{schema_classes/my_schema_with_complex_types.rb → snapshots/consumers_complex_types-no-nest.snap} +57 -22
- data/spec/snapshots/consumers_complex_types.snap +241 -0
- data/spec/{schema_classes/my_nested_schema.rb → snapshots/consumers_nested-no-nest.snap} +12 -1
- data/spec/snapshots/consumers_nested.snap +119 -0
- data/spec/snapshots/producers_with_key-no-nest.snap +95 -0
- data/spec/snapshots/producers_with_key.snap +95 -0
- data/spec/spec_helper.rb +4 -1
- metadata +52 -14
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c810f924fa9af51458b4c30e0d6b9101e05094713b3550190f60d7e088119cf0
|
4
|
+
data.tar.gz: 027e3362abf78a4f60cd2613956b8920e537a28f34fcd3c02f94d48648b85b5b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8b2a64227cf35a8e86f7ad1b142f25bfce7d1c0e9c5e0bded07f6058b811609f4a315c3f48903a672093a1084c0a7c395198e4524d629b9610995a2629959550
|
7
|
+
data.tar.gz: 80ad055761417ad27f5be9c7a6fd2ffdeaed5b3e2aaf7b0d6b6956d4567f60f4f0d7f7dda9e24640ef67d5e3636f7c9ef0b176de342ceb254840b41ce2639ce0
|
data/CHANGELOG.md
CHANGED
@@ -7,6 +7,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
7
7
|
|
8
8
|
## UNRELEASED
|
9
9
|
|
10
|
+
# 1.14.0 - 2022-05-16
|
11
|
+
|
12
|
+
- **Breaking Change**: Nest sub-schemas by default into their parent schemas when generating classes.
|
13
|
+
- Add the `nest_child_schemas` option to essentially bring back the previous behavior in terms of code use (the actual classes will be separated out into different files).
|
14
|
+
|
15
|
+
# 1.13.3 - 2022-05-10
|
16
|
+
|
10
17
|
- Some cleanup on the active_record generator
|
11
18
|
- Fix crash with `test_consume_message` when using schema classes
|
12
19
|
- Add `[]=` and `merge` methods on the base schema class
|
data/README.md
CHANGED
@@ -818,6 +818,12 @@ Add the following configurations to start using generated schema classes in your
|
|
818
818
|
Additionally, you can enable or disable the usage of schema classes for a particular consumer or producer with the
|
819
819
|
`use_schema_classes` config. See [Configuration](./docs/CONFIGURATION.md#defining-producers).
|
820
820
|
|
821
|
+
Note that if you have a schema in your repo but have not configured a producer or consumer, the generator will **not** generate a schema class for it. This is because you need to supply the `key_config` for the generator to know how to handle the schema key.
|
822
|
+
|
823
|
+
One additional configuration option indicates whether nested records should be generated as top-level classes or would remain nested inside the generated class for its parent schema. The default is to nest them, as a flattened structure can have one sub-schema clobber another sub-schema defined in a different top-level schema.
|
824
|
+
|
825
|
+
config.schema.nest_child_schemas = false # Flatten all classes into one directory
|
826
|
+
|
821
827
|
### Consumer
|
822
828
|
|
823
829
|
The consumer interface uses the `decode_message` method to turn JSON hash into the Schemas
|
data/deimos-ruby.gemspec
CHANGED
@@ -39,6 +39,7 @@ Gem::Specification.new do |spec|
|
|
39
39
|
spec.add_development_dependency('rspec', '~> 3')
|
40
40
|
spec.add_development_dependency('rspec_junit_formatter', '~>0.3')
|
41
41
|
spec.add_development_dependency('rspec-rails', '~> 4')
|
42
|
+
spec.add_development_dependency('rspec-snapshot', '~> 2.0')
|
42
43
|
spec.add_development_dependency('rubocop', '0.89.0')
|
43
44
|
spec.add_development_dependency('rubocop-rspec', '1.42.0')
|
44
45
|
spec.add_development_dependency('sqlite3', '~> 1.3')
|
@@ -343,6 +343,10 @@ module Deimos
|
|
343
343
|
# Set to true to use the generated schema classes in your application
|
344
344
|
# @return [Boolean]
|
345
345
|
setting :use_schema_classes, false
|
346
|
+
|
347
|
+
# Set to false to generate child schemas as their own files.
|
348
|
+
# @return [Boolean]
|
349
|
+
setting :nest_child_schemas, true
|
346
350
|
end
|
347
351
|
|
348
352
|
# The configured metrics provider.
|
@@ -96,7 +96,7 @@ module Deimos
|
|
96
96
|
# @param schema [Avro::Schema::NamedSchema] A named schema
|
97
97
|
# @return [String]
|
98
98
|
def self.schema_classname(schema)
|
99
|
-
schema.name.underscore.camelize
|
99
|
+
schema.name.underscore.camelize.singularize
|
100
100
|
end
|
101
101
|
|
102
102
|
# Converts Avro::Schema::NamedSchema's to String form for generated YARD docs.
|
data/lib/deimos/version.rb
CHANGED
@@ -2,13 +2,6 @@
|
|
2
2
|
|
3
3
|
# This file is autogenerated by Deimos, Do NOT modify
|
4
4
|
module Schemas
|
5
|
-
<% if @sub_schema_templates.present? && @sub_schema_templates.any? -%>
|
6
|
-
### Secondary Schema Classes ###
|
7
|
-
<% end -%>
|
8
|
-
<%- @sub_schema_templates.each do |schema_template| -%>
|
9
|
-
<%=- schema_template %>
|
10
|
-
|
11
|
-
<%- end -%>
|
12
5
|
### Primary Schema Class ###
|
13
6
|
<%=- @main_class_definition -%>
|
14
7
|
|
@@ -1,6 +1,15 @@
|
|
1
1
|
# Autogenerated Schema for Record at <%= @current_schema.namespace %>.<%= @current_schema.name %>
|
2
2
|
class <%= Deimos::SchemaBackends::AvroBase.schema_classname(@current_schema) %> < Deimos::SchemaClass::Record
|
3
|
-
|
3
|
+
<% if @sub_schema_templates.present? -%>
|
4
|
+
|
5
|
+
### Secondary Schema Classes ###
|
6
|
+
<%- @sub_schema_templates.each do |schema_template| -%>
|
7
|
+
<%=- schema_template.gsub(/^/, " ") %>
|
8
|
+
|
9
|
+
<%- end -%>
|
10
|
+
<% end -%>
|
11
|
+
|
12
|
+
<%- if @field_assignments.select{ |h| h[:is_schema_class] }.any? -%>
|
4
13
|
### Attribute Readers ###
|
5
14
|
<%- @field_assignments.select{ |h| h[:is_schema_class] }.each do |method_definition| -%>
|
6
15
|
# @return [<%= method_definition[:deimos_type] %>]
|
@@ -86,20 +86,32 @@ module Deimos
|
|
86
86
|
# @param key_schema_base[Avro::Schema::NamedSchema]
|
87
87
|
def generate_class_from_schema_base(schema_base, key_schema_base: nil)
|
88
88
|
@discovered_schemas = Set.new
|
89
|
+
@sub_schema_templates = []
|
89
90
|
schemas = collect_all_schemas(schema_base.schema_store.schemas.values)
|
90
91
|
|
92
|
+
main_schema = schemas.find { |s| s.name == schema_base.schema }
|
91
93
|
sub_schemas = schemas.reject { |s| s.name == schema_base.schema }.sort_by(&:name)
|
92
|
-
|
93
|
-
|
94
|
+
if Deimos.config.schema.nest_child_schemas
|
95
|
+
@sub_schema_templates = sub_schemas.map do |schema|
|
96
|
+
_generate_class_template_from_schema(schema)
|
97
|
+
end
|
98
|
+
write_file(main_schema, key_schema_base)
|
99
|
+
else
|
100
|
+
write_file(main_schema, key_schema_base)
|
101
|
+
sub_schemas.each do |schema|
|
102
|
+
write_file(schema, nil)
|
103
|
+
end
|
94
104
|
end
|
105
|
+
end
|
95
106
|
|
96
|
-
|
97
|
-
|
107
|
+
# @param schema [Avro::Schema::NamedSchema]
|
108
|
+
# @param key_schema_base [Avro::Schema::NamedSchema, nil]
|
109
|
+
def write_file(schema, key_schema_base)
|
110
|
+
class_template = _generate_class_template_from_schema(schema, key_schema_base)
|
98
111
|
@main_class_definition = class_template
|
99
112
|
|
100
|
-
file_prefix =
|
101
|
-
|
102
|
-
filename = "#{Deimos.config.schema.generated_class_path}/#{namespace_path}/#{file_prefix}.rb"
|
113
|
+
file_prefix = schema.name.underscore.singularize
|
114
|
+
filename = "#{Deimos.config.schema.generated_class_path}/#{file_prefix}.rb"
|
103
115
|
template(SCHEMA_CLASS_FILE, filename, force: true)
|
104
116
|
end
|
105
117
|
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
# For testing the generated class.
|
4
|
-
RSpec.describe Schemas::
|
4
|
+
RSpec.describe Schemas::MySchemaWithComplexType do
|
5
5
|
let(:payload_hash) do
|
6
6
|
{
|
7
7
|
test_id: 'test id',
|
@@ -9,16 +9,16 @@ RSpec.describe Schemas::MySchemaWithComplexTypes do
|
|
9
9
|
test_string_array: %w(abc def),
|
10
10
|
test_int_array: [123, 456],
|
11
11
|
some_integer_map: { 'int_1' => 1, 'int_2' => 2 },
|
12
|
-
some_record: Schemas::ARecord.new(a_record_field: 'field 1'),
|
13
|
-
some_optional_record: Schemas::ARecord.new(a_record_field: 'field 2'),
|
14
|
-
some_record_array: [Schemas::ARecord.new(a_record_field: 'field 3'),
|
15
|
-
Schemas::ARecord.new(a_record_field: 'field 4')],
|
12
|
+
some_record: Schemas::MySchemaWithComplexType::ARecord.new(a_record_field: 'field 1'),
|
13
|
+
some_optional_record: Schemas::MySchemaWithComplexType::ARecord.new(a_record_field: 'field 2'),
|
14
|
+
some_record_array: [Schemas::MySchemaWithComplexType::ARecord.new(a_record_field: 'field 3'),
|
15
|
+
Schemas::MySchemaWithComplexType::ARecord.new(a_record_field: 'field 4')],
|
16
16
|
some_record_map: {
|
17
|
-
'record_1' => Schemas::ARecord.new(a_record_field: 'field 5'),
|
18
|
-
'record_2' => Schemas::ARecord.new(a_record_field: 'field 6')
|
17
|
+
'record_1' => Schemas::MySchemaWithComplexType::ARecord.new(a_record_field: 'field 5'),
|
18
|
+
'record_2' => Schemas::MySchemaWithComplexType::ARecord.new(a_record_field: 'field 6')
|
19
19
|
},
|
20
|
-
some_enum_array: [Schemas::AnEnum.new('sym1'),
|
21
|
-
Schemas::AnEnum.new('sym2')]
|
20
|
+
some_enum_array: [Schemas::MySchemaWithComplexType::AnEnum.new('sym1'),
|
21
|
+
Schemas::MySchemaWithComplexType::AnEnum.new('sym2')]
|
22
22
|
}
|
23
23
|
end
|
24
24
|
|
@@ -57,7 +57,9 @@ 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
|
60
|
+
%w(test_id test_float test_int_array test_optional_int test_string_array some_integer_map
|
61
|
+
some_record some_optional_record some_record_array some_record_map some_enum_array
|
62
|
+
some_optional_enum some_enum_with_default)
|
61
63
|
end
|
62
64
|
|
63
65
|
it 'should return the name of the schema and namespace' do
|
@@ -113,7 +115,8 @@ RSpec.describe Schemas::MySchemaWithComplexTypes do
|
|
113
115
|
it 'should set some_record if it is not provided' do
|
114
116
|
payload_hash.delete(:some_record)
|
115
117
|
klass = described_class.new(**payload_hash)
|
116
|
-
expect(klass.some_record).
|
118
|
+
expect(klass.some_record).
|
119
|
+
to eq(Schemas::MySchemaWithComplexType::ARecord.new(a_record_field: 'Test String'))
|
117
120
|
end
|
118
121
|
|
119
122
|
it 'should set some_record to nil' do
|
@@ -136,25 +139,26 @@ RSpec.describe Schemas::MySchemaWithComplexTypes do
|
|
136
139
|
|
137
140
|
it 'should get the value of some_record_array' do
|
138
141
|
some_record_array = klass.some_record_array
|
139
|
-
expect(some_record_array.first).to be_instance_of(Schemas::ARecord)
|
142
|
+
expect(some_record_array.first).to be_instance_of(Schemas::MySchemaWithComplexType::ARecord)
|
140
143
|
expect(some_record_array.first.a_record_field).to eq('field 3')
|
141
144
|
end
|
142
145
|
|
143
146
|
it 'should get the value of some_record_map' do
|
144
147
|
some_record_map = klass.some_record_map
|
145
|
-
expect(some_record_map['record_1']).
|
148
|
+
expect(some_record_map['record_1']).
|
149
|
+
to be_instance_of(Schemas::MySchemaWithComplexType::ARecord)
|
146
150
|
expect(some_record_map['record_1'].a_record_field).to eq('field 5')
|
147
151
|
end
|
148
152
|
|
149
153
|
it 'should get the value of some_enum_array' do
|
150
154
|
some_enum_array = klass.some_enum_array
|
151
|
-
expect(some_enum_array.first).to be_instance_of(Schemas::AnEnum)
|
155
|
+
expect(some_enum_array.first).to be_instance_of(Schemas::MySchemaWithComplexType::AnEnum)
|
152
156
|
expect(some_enum_array.first.an_enum).to eq('sym1')
|
153
157
|
end
|
154
158
|
|
155
159
|
it 'should get the value of some_record' do
|
156
160
|
record = klass.some_record
|
157
|
-
expect(record).to be_instance_of(Schemas::ARecord)
|
161
|
+
expect(record).to be_instance_of(Schemas::MySchemaWithComplexType::ARecord)
|
158
162
|
expect(record.a_record_field).to eq('field 1')
|
159
163
|
expect(record.to_h).to eq({ 'a_record_field' => 'field 1' })
|
160
164
|
end
|
@@ -175,33 +179,42 @@ RSpec.describe Schemas::MySchemaWithComplexTypes do
|
|
175
179
|
end
|
176
180
|
|
177
181
|
it 'should modify the value of some_optional_record' do
|
178
|
-
expect(klass.some_optional_record).
|
179
|
-
|
182
|
+
expect(klass.some_optional_record).
|
183
|
+
to eq(Schemas::MySchemaWithComplexType::ARecord.new(a_record_field: 'field 2'))
|
184
|
+
klass.some_optional_record = Schemas::MySchemaWithComplexType::ARecord.
|
185
|
+
new(a_record_field: 'new field')
|
180
186
|
|
181
|
-
expect(klass.some_optional_record).to eq(Schemas::ARecord.
|
187
|
+
expect(klass.some_optional_record).to eq(Schemas::MySchemaWithComplexType::ARecord.
|
188
|
+
new(a_record_field: 'new field'))
|
182
189
|
expect(klass.some_optional_record.as_json).to eq({ 'a_record_field' => 'new field' })
|
183
190
|
end
|
184
191
|
|
185
192
|
it 'should accept a hash object inner records' do
|
186
193
|
klass.some_optional_record = { a_record_field: 'new field' }
|
187
|
-
expect(klass.some_optional_record).to eq(Schemas::ARecord.
|
194
|
+
expect(klass.some_optional_record).to eq(Schemas::MySchemaWithComplexType::ARecord.
|
195
|
+
new(a_record_field: 'new field'))
|
188
196
|
expect(klass.some_optional_record.as_json).to eq({ 'a_record_field' => 'new field' })
|
189
197
|
end
|
190
198
|
|
191
199
|
it 'should modify the value of some_enum_array' do
|
192
200
|
klass.some_enum_array.first.an_enum = 'new_sym'
|
193
|
-
expect(klass.some_enum_array.first).
|
201
|
+
expect(klass.some_enum_array.first).
|
202
|
+
to eq(Schemas::MySchemaWithComplexType::AnEnum.new('new_sym'))
|
194
203
|
|
195
|
-
klass.some_enum_array.second.an_enum = Schemas::AnEnum.
|
204
|
+
klass.some_enum_array.second.an_enum = Schemas::MySchemaWithComplexType::AnEnum.
|
205
|
+
new('other_sym')
|
196
206
|
expect(klass.some_enum_array.second.an_enum).to eq('other_sym')
|
197
207
|
end
|
198
208
|
|
199
209
|
it 'should modify the value of some_record_map' do
|
200
210
|
klass.some_record_map['record_1'].a_record_field = 'new field'
|
201
|
-
expect(klass.some_record_map['record_1']).to eq(Schemas::ARecord.
|
211
|
+
expect(klass.some_record_map['record_1']).to eq(Schemas::MySchemaWithComplexType::ARecord.
|
212
|
+
new(a_record_field: 'new field'))
|
202
213
|
|
203
|
-
klass.some_record_map['record_2'] = Schemas::ARecord.
|
204
|
-
|
214
|
+
klass.some_record_map['record_2'] = Schemas::MySchemaWithComplexType::ARecord.
|
215
|
+
new(a_record_field: 'other field')
|
216
|
+
expect(klass.some_record_map['record_2']).to eq(Schemas::MySchemaWithComplexType::ARecord.
|
217
|
+
new(a_record_field: 'other field'))
|
205
218
|
end
|
206
219
|
end
|
207
220
|
end
|
@@ -3,22 +3,27 @@
|
|
3
3
|
require 'generators/deimos/schema_class_generator'
|
4
4
|
require 'fileutils'
|
5
5
|
|
6
|
+
class MultiFileSerializer
|
7
|
+
def dump(value)
|
8
|
+
value.keys.sort.map { |k| "#{k}:\n#{value[k]}\n" }.join("\n")
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
6
12
|
RSpec.describe Deimos::Generators::SchemaClassGenerator do
|
7
|
-
let(:schema_class_path) { 'app/lib/schema_classes
|
8
|
-
let(:
|
9
|
-
let(:files) { Dir["#{schema_class_path}/*.rb"] }
|
13
|
+
let(:schema_class_path) { 'spec/app/lib/schema_classes' }
|
14
|
+
let(:files) { Dir["#{schema_class_path}/*.rb"].map { |f| [f, File.read(f)]}.to_h }
|
10
15
|
|
11
16
|
before(:each) do
|
12
17
|
Deimos.config.reset!
|
13
18
|
Deimos.configure do
|
14
19
|
schema.path 'spec/schemas/'
|
15
|
-
schema.generated_class_path 'app/lib/schema_classes'
|
20
|
+
schema.generated_class_path 'spec/app/lib/schema_classes'
|
16
21
|
schema.backend :avro_local
|
17
22
|
end
|
18
23
|
end
|
19
24
|
|
20
25
|
after(:each) do
|
21
|
-
FileUtils.rm_rf(
|
26
|
+
FileUtils.rm_rf('spec/app') if File.exist?('spec/app')
|
22
27
|
end
|
23
28
|
|
24
29
|
context 'with a Consumers Schema' do
|
@@ -32,19 +37,26 @@ RSpec.describe Deimos::Generators::SchemaClassGenerator do
|
|
32
37
|
key_config field: :a_string
|
33
38
|
end
|
34
39
|
end
|
35
|
-
described_class.start
|
36
40
|
end
|
37
41
|
|
38
|
-
|
39
|
-
|
42
|
+
context 'nested true' do
|
43
|
+
it 'should generate the correct classes' do
|
44
|
+
Deimos.with_config('schema.nest_child_schemas' => true) do
|
45
|
+
described_class.start
|
46
|
+
expect(files).to match_snapshot('consumers', snapshot_serializer: MultiFileSerializer)
|
47
|
+
end
|
48
|
+
end
|
40
49
|
end
|
41
50
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
51
|
+
context 'nested false' do
|
52
|
+
it 'should generate the correct classes' do
|
53
|
+
Deimos.with_config('schema.nest_child_schemas' => false) do
|
54
|
+
described_class.start
|
55
|
+
expect(files).to match_snapshot('consumers-no-nest', snapshot_serializer: MultiFileSerializer)
|
56
|
+
end
|
57
|
+
end
|
47
58
|
end
|
59
|
+
|
48
60
|
end
|
49
61
|
|
50
62
|
context 'with a Consumers Schema with Complex types' do
|
@@ -58,18 +70,24 @@ RSpec.describe Deimos::Generators::SchemaClassGenerator do
|
|
58
70
|
key_config field: :a_string
|
59
71
|
end
|
60
72
|
end
|
61
|
-
described_class.start
|
62
73
|
end
|
63
74
|
|
64
|
-
|
65
|
-
|
75
|
+
context 'nested true' do
|
76
|
+
it 'should generate the correct classes' do
|
77
|
+
Deimos.with_config('schema.nest_child_schemas' => true) do
|
78
|
+
described_class.start
|
79
|
+
expect(files).to match_snapshot('consumers_complex_types', snapshot_serializer: MultiFileSerializer)
|
80
|
+
end
|
81
|
+
end
|
66
82
|
end
|
67
83
|
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
84
|
+
context 'nested false' do
|
85
|
+
it 'should generate the correct classes' do
|
86
|
+
Deimos.with_config('schema.nest_child_schemas' => false) do
|
87
|
+
described_class.start
|
88
|
+
expect(files).to match_snapshot('consumers_complex_types-no-nest', snapshot_serializer: MultiFileSerializer)
|
89
|
+
end
|
90
|
+
end
|
73
91
|
end
|
74
92
|
end
|
75
93
|
|
@@ -84,18 +102,24 @@ RSpec.describe Deimos::Generators::SchemaClassGenerator do
|
|
84
102
|
key_config field: :a_string
|
85
103
|
end
|
86
104
|
end
|
87
|
-
described_class.start
|
88
105
|
end
|
89
106
|
|
90
|
-
|
91
|
-
|
107
|
+
context 'nested true' do
|
108
|
+
it 'should generate the correct classes' do
|
109
|
+
Deimos.with_config('schema.nest_child_schemas' => true) do
|
110
|
+
described_class.start
|
111
|
+
expect(files).to match_snapshot('consumers_circular', snapshot_serializer: MultiFileSerializer)
|
112
|
+
end
|
113
|
+
end
|
92
114
|
end
|
93
115
|
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
116
|
+
context 'nested false' do
|
117
|
+
it 'should generate the correct classes' do
|
118
|
+
Deimos.with_config('schema.nest_child_schemas' => false) do
|
119
|
+
described_class.start
|
120
|
+
expect(files).to match_snapshot('consumers_circular-no-nest', snapshot_serializer: MultiFileSerializer)
|
121
|
+
end
|
122
|
+
end
|
99
123
|
end
|
100
124
|
end
|
101
125
|
|
@@ -110,19 +134,23 @@ RSpec.describe Deimos::Generators::SchemaClassGenerator do
|
|
110
134
|
key_config schema: 'MySchema_key'
|
111
135
|
end
|
112
136
|
end
|
113
|
-
described_class.start
|
114
137
|
end
|
115
138
|
|
116
|
-
|
117
|
-
|
139
|
+
context 'nested true' do
|
140
|
+
it 'should generate the correct classes' do
|
141
|
+
Deimos.with_config('schema.nest_child_schemas' => true) do
|
142
|
+
described_class.start
|
143
|
+
expect(files).to match_snapshot('producers_with_key', snapshot_serializer: MultiFileSerializer)
|
144
|
+
end
|
145
|
+
end
|
118
146
|
end
|
119
147
|
|
120
|
-
|
121
|
-
it
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
148
|
+
context 'nested false' do
|
149
|
+
it 'should generate the correct classes' do
|
150
|
+
Deimos.with_config('schema.nest_child_schemas' => false) do
|
151
|
+
described_class.start
|
152
|
+
expect(files).to match_snapshot('producers_with_key-no-nest', snapshot_serializer: MultiFileSerializer)
|
153
|
+
end
|
126
154
|
end
|
127
155
|
end
|
128
156
|
end
|
@@ -138,18 +166,24 @@ RSpec.describe Deimos::Generators::SchemaClassGenerator do
|
|
138
166
|
key_config field: :test_id
|
139
167
|
end
|
140
168
|
end
|
141
|
-
described_class.start
|
142
169
|
end
|
143
170
|
|
144
|
-
|
145
|
-
|
171
|
+
context 'nested true' do
|
172
|
+
it 'should generate the correct classes' do
|
173
|
+
Deimos.with_config('schema.nest_child_schemas' => true) do
|
174
|
+
described_class.start
|
175
|
+
expect(files).to match_snapshot('consumers_nested', snapshot_serializer: MultiFileSerializer)
|
176
|
+
end
|
177
|
+
end
|
146
178
|
end
|
147
179
|
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
180
|
+
context 'nested false' do
|
181
|
+
it 'should generate the correct classes' do
|
182
|
+
Deimos.with_config('schema.nest_child_schemas' => false) do
|
183
|
+
described_class.start
|
184
|
+
expect(files).to match_snapshot('consumers_nested-no-nest', snapshot_serializer: MultiFileSerializer)
|
185
|
+
end
|
186
|
+
end
|
153
187
|
end
|
154
188
|
end
|
155
189
|
|
@@ -180,19 +214,23 @@ RSpec.describe Deimos::Generators::SchemaClassGenerator do
|
|
180
214
|
key_config field: :test_id
|
181
215
|
end
|
182
216
|
end
|
183
|
-
described_class.start
|
184
217
|
end
|
185
218
|
|
186
|
-
|
187
|
-
|
219
|
+
context 'nested true' do
|
220
|
+
it 'should generate the correct classes' do
|
221
|
+
Deimos.with_config('schema.nest_child_schemas' => true) do
|
222
|
+
described_class.start
|
223
|
+
expect(files).to match_snapshot('consumers_and_producers', snapshot_serializer: MultiFileSerializer)
|
224
|
+
end
|
225
|
+
end
|
188
226
|
end
|
189
227
|
|
190
|
-
|
191
|
-
it
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
228
|
+
context 'nested false' do
|
229
|
+
it 'should generate the correct classes' do
|
230
|
+
Deimos.with_config('schema.nest_child_schemas' => false) do
|
231
|
+
described_class.start
|
232
|
+
expect(files).to match_snapshot('consumers_and_producers-no-nest', snapshot_serializer: MultiFileSerializer)
|
233
|
+
end
|
196
234
|
end
|
197
235
|
end
|
198
236
|
end
|
data/spec/producer_spec.rb
CHANGED
@@ -476,7 +476,7 @@ module ProducerTest
|
|
476
476
|
test_id: 'foo',
|
477
477
|
test_float: BigDecimal('123.456'),
|
478
478
|
test_array: ['1'],
|
479
|
-
some_nested_record: Schemas::MyNestedRecord.new(
|
479
|
+
some_nested_record: Schemas::MyNestedSchema::MyNestedRecord.new(
|
480
480
|
some_int: 123,
|
481
481
|
some_float: BigDecimal('456.789'),
|
482
482
|
some_string: '123',
|