deimos-ruby 1.15.1 → 1.16.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +13 -0
  3. data/README.md +15 -0
  4. data/lib/deimos/active_record_producer.rb +8 -1
  5. data/lib/deimos/consumer.rb +3 -1
  6. data/lib/deimos/schema_class/base.rb +2 -25
  7. data/lib/deimos/schema_class/enum.rb +23 -0
  8. data/lib/deimos/schema_class/record.rb +15 -4
  9. data/lib/deimos/test_helpers.rb +3 -2
  10. data/lib/deimos/tracing/datadog.rb +11 -0
  11. data/lib/deimos/tracing/mock.rb +10 -0
  12. data/lib/deimos/tracing/provider.rb +13 -0
  13. data/lib/deimos/utils/schema_class.rb +16 -2
  14. data/lib/deimos/utils/schema_controller_mixin.rb +7 -1
  15. data/lib/deimos/version.rb +1 -1
  16. data/lib/generators/deimos/schema_class/templates/schema_enum.rb.tt +0 -11
  17. data/lib/generators/deimos/schema_class/templates/schema_record.rb.tt +2 -2
  18. data/lib/generators/deimos/schema_class_generator.rb +6 -10
  19. data/spec/active_record_producer_spec.rb +24 -0
  20. data/spec/batch_consumer_spec.rb +13 -10
  21. data/spec/generators/schema_class/my_schema_with_circular_reference_spec.rb +19 -19
  22. data/spec/generators/schema_class/my_schema_with_complex_types_spec.rb +2 -2
  23. data/spec/schemas/generated.rb +5 -5
  24. data/spec/schemas/my_nested_schema.rb +4 -4
  25. data/spec/schemas/my_schema.rb +2 -2
  26. data/spec/schemas/my_schema_key.rb +1 -1
  27. data/spec/schemas/my_schema_with_circular_reference.rb +3 -3
  28. data/spec/schemas/my_schema_with_complex_type.rb +11 -22
  29. data/spec/snapshots/consumers-no-nest.snap +34 -67
  30. data/spec/snapshots/consumers.snap +35 -79
  31. data/spec/snapshots/consumers_and_producers-no-nest.snap +35 -68
  32. data/spec/snapshots/consumers_and_producers.snap +36 -80
  33. data/spec/snapshots/consumers_circular-no-nest.snap +34 -67
  34. data/spec/snapshots/consumers_circular.snap +35 -79
  35. data/spec/snapshots/consumers_complex_types-no-nest.snap +34 -67
  36. data/spec/snapshots/consumers_complex_types.snap +35 -79
  37. data/spec/snapshots/consumers_nested-no-nest.snap +34 -67
  38. data/spec/snapshots/consumers_nested.snap +35 -79
  39. data/spec/snapshots/namespace_folders.snap +53 -97
  40. data/spec/snapshots/producers_with_key-no-nest.snap +35 -68
  41. data/spec/snapshots/producers_with_key.snap +36 -80
  42. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 13d2028ca2c052ef2d64099e9ca135c7dac2ea76fe0ee995f8729c6e16b39f63
4
- data.tar.gz: a539787e5311593f664280c7e26a0d73f345026418b12e50e8daf508fd97d61c
3
+ metadata.gz: 59c0f6801979649cc677cc485cfc1435d1ef235769784a864eabbc3e35e55573
4
+ data.tar.gz: 85d9adfa94010a7594a94e8770ee15922a893ecb53ccb600e7911ae9615ff574
5
5
  SHA512:
6
- metadata.gz: 7554b95d79b8fdf1c1b262208737b9ebf1a10ba3acbb3ae96f7a9c47fa8762fb42f77ae416be82a49c0d058e1e4af9bceb3139523e10a6fb5d890eb2fb64430f
7
- data.tar.gz: 76e540826895dbac336fc04bb8f67bf6dc29ee9582c2a39367112a453a8abea7129854a0b89bf8468631b6476f353944e2f23d23288c1faad44b4501ba8f7111
6
+ metadata.gz: c663849c130074d566875b278b4e6af667c814e1860a24ac531cc163e819aaac399381578a1d93130b9121402ec1f500108155ee20f37be6999df3d496869376
7
+ data.tar.gz: 6ba7849db0b98b80684381056be5aeb1f6d206ee65e742c8e33c1cdc9cb0f0f150d8f61f868f18e29837ac2e3279d1b2737c244c79201cbec9038da1c7128264
data/CHANGELOG.md CHANGED
@@ -7,6 +7,19 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## UNRELEASED
9
9
 
10
+ # 1.16.2 - 2022-09-07
11
+
12
+ - Added support of post_process method in ActiveRecordProducer
13
+
14
+ # 1.16.1 - 2022-08-03
15
+
16
+ - Fix issues with `enum` schema classes (e.g. equality not working, `to_s` not working)
17
+ - Changed assumption in the base schema class that it was a record (e.g. defining `to_h` instead of `as_json`). Moved record functionality to the record base class.
18
+ - Added the `active_span` and `set_tag` methods to the tracing classes.
19
+ - Added span tags for fields in SchemaControllerMixin.
20
+ - Updated SchemaControllerMixin so it works with generated schema classes.
21
+ - Fixed bug with previous release where the filename and constant names for `generate_namespace_folders` did not always match.
22
+
10
23
  # 1.15.0 - 2022-07-20
11
24
 
12
25
  - Update to `sigurd` 0.1.0 - DB producer should now exit when receiving a `SIGTERM` instead of throwing a `SignalException`
data/README.md CHANGED
@@ -785,6 +785,21 @@ have one process running at a time. If a particular poll takes longer than
785
785
  the poll interval (i.e. interval is set at 1 minute but it takes 75 seconds)
786
786
  the next poll will begin immediately following the first one completing.
787
787
 
788
+ To Post-Process records that are sent to Kafka:
789
+
790
+ You need to define one additional method in your producer class to post-process the messages sent to Kafka.
791
+
792
+ ```ruby
793
+ class MyProducer < Deimos::ActiveRecordProducer
794
+ ...
795
+ def post_process(batch)
796
+ # If you need to do some extra actions with
797
+ # the collection of elements you just sent to Kafka
798
+ # write some code here
799
+ end
800
+ end
801
+ ```
802
+
788
803
  ## Running consumers
789
804
 
790
805
  Deimos includes a rake task. Once it's in your gemfile, just run
@@ -44,6 +44,7 @@ module Deimos
44
44
  generate_payload(attrs, record).with_indifferent_access
45
45
  end
46
46
  self.publish_list(messages, force_send: force_send)
47
+ self.post_process(records)
47
48
  end
48
49
 
49
50
  # Generate the payload, given a list of attributes or a record..
@@ -60,7 +61,7 @@ module Deimos
60
61
  end
61
62
  return payload unless Utils::SchemaClass.use?(config.to_h)
62
63
 
63
- Utils::SchemaClass.instance(payload, config[:schema])
64
+ Utils::SchemaClass.instance(payload, config[:schema], config[:namespace])
64
65
  end
65
66
 
66
67
  # Query to use when polling the database with the DbPoller. Add
@@ -85,6 +86,12 @@ module Deimos
85
86
  time_to
86
87
  )
87
88
  end
89
+
90
+ # Post process records after publishing
91
+ # @param records [Array<ActiveRecord::Base>]
92
+ def post_process(_records)
93
+ end
94
+
88
95
  end
89
96
  end
90
97
  end
@@ -58,7 +58,9 @@ module Deimos
58
58
  decoded_payload = payload.nil? ? nil : self.class.decoder.decode(payload)
59
59
  return decoded_payload unless Utils::SchemaClass.use?(self.class.config.to_h)
60
60
 
61
- Utils::SchemaClass.instance(decoded_payload, self.class.config[:schema])
61
+ Utils::SchemaClass.instance(decoded_payload,
62
+ self.class.config[:schema],
63
+ self.class.config[:namespace])
62
64
  end
63
65
 
64
66
  private
@@ -11,21 +11,9 @@ module Deimos
11
11
  def initialize(*_args)
12
12
  end
13
13
 
14
- # Converts the object to a string that represents a JSON object
15
- # @return [String] a JSON string
16
- def to_json(*_args)
17
- to_h.to_json
18
- end
19
-
20
14
  # Converts the object to a hash which can be used for debugging or comparing objects.
21
15
  # @return [Hash] a hash representation of the payload
22
16
  def as_json(_opts={})
23
- JSON.parse(to_json)
24
- end
25
-
26
- # Converts the object attributes to a hash which can be used for Kafka
27
- # @return [Hash] the payload as a hash.
28
- def to_h
29
17
  raise NotImplementedError
30
18
  end
31
19
 
@@ -35,17 +23,6 @@ module Deimos
35
23
  self.send("#{key}=", val)
36
24
  end
37
25
 
38
- # Merge a hash or an identical schema object with this one and return a new object.
39
- # @param other_hash [Hash|SchemaClasses::Base]
40
- # @return [SchemaClasses::Base]
41
- def merge(other_hash)
42
- obj = self.class.new(**self.to_h.symbolize_keys)
43
- other_hash.to_h.each do |k, v|
44
- obj.send("#{k}=", v)
45
- end
46
- obj
47
- end
48
-
49
26
  # :nodoc:
50
27
  def ==(other)
51
28
  comparison = other
@@ -57,9 +34,9 @@ module Deimos
57
34
  end
58
35
 
59
36
  # :nodoc:
60
- def to_s
37
+ def inspect
61
38
  klass = self.class
62
- "#{klass}(#{self.as_json.symbolize_keys.to_s[1..-2]})"
39
+ "#{klass}(#{self.as_json})"
63
40
  end
64
41
 
65
42
  # Initializes this class from a given value
@@ -7,12 +7,35 @@ module Deimos
7
7
  module SchemaClass
8
8
  # Base Class for Enum Classes generated from Avro.
9
9
  class Enum < Base
10
+
11
+ attr_accessor :value
12
+
13
+ # @param other [Deimos::SchemaClass::Enum]
14
+ def ==(other)
15
+ other.is_a?(self.class) ? other.value == @value : other == @value
16
+ end
17
+
18
+ # @return [String]
19
+ def to_s
20
+ @value.to_s
21
+ end
22
+
23
+ # @param value [String]
24
+ def initialize(value)
25
+ @value = value
26
+ end
27
+
10
28
  # Returns all the valid symbols for this enum.
11
29
  # @return [Array<String>]
12
30
  def symbols
13
31
  raise NotImplementedError
14
32
  end
15
33
 
34
+ # :nodoc:
35
+ def as_json(_opts={})
36
+ @value
37
+ end
38
+
16
39
  # :nodoc:
17
40
  def self.initialize_from_value(value)
18
41
  return nil if value.nil?
@@ -8,10 +8,21 @@ module Deimos
8
8
  # Base Class of Record Classes generated from Avro.
9
9
  class Record < Base
10
10
 
11
- # Converts the object to a hash which can be used for debugging or comparing objects.
12
- # @return [Hash] a hash representation of the payload
13
- def as_json(_opts={})
14
- super.except('payload_key')
11
+ # Converts the object attributes to a hash which can be used for Kafka
12
+ # @return [Hash] the payload as a hash.
13
+ def to_h
14
+ self.as_json
15
+ end
16
+
17
+ # Merge a hash or an identical schema object with this one and return a new object.
18
+ # @param other_hash [Hash|SchemaClasses::Base]
19
+ # @return [SchemaClasses::Base]
20
+ def merge(other_hash)
21
+ obj = self.class.new(**self.to_h.symbolize_keys)
22
+ other_hash.to_h.each do |k, v|
23
+ obj.send("#{k}=", v)
24
+ end
25
+ obj
15
26
  end
16
27
 
17
28
  # Element access method as if this Object were a hash
@@ -373,6 +373,7 @@ module Deimos
373
373
  call_original,
374
374
  &block)
375
375
  schema_class = handler.class.config[:schema]
376
+ namespace = handler.class.config[:namespace]
376
377
  expected = input.dup
377
378
 
378
379
  config = handler.class.config
@@ -382,10 +383,10 @@ module Deimos
382
383
  if use_schema_classes && schema_class.present?
383
384
  expected = if input.is_a?(Array)
384
385
  input.map do |payload|
385
- Utils::SchemaClass.instance(payload, schema_class)
386
+ Utils::SchemaClass.instance(payload, schema_class, namespace)
386
387
  end
387
388
  else
388
- Utils::SchemaClass.instance(input, schema_class)
389
+ Utils::SchemaClass.instance(input, schema_class, namespace)
389
390
  end
390
391
  end
391
392
 
@@ -26,10 +26,21 @@ module Deimos
26
26
  span.finish
27
27
  end
28
28
 
29
+ # :nodoc:
30
+ def active_span
31
+ ::Datadog.tracer.active_span
32
+ end
33
+
29
34
  # :nodoc:
30
35
  def set_error(span, exception)
31
36
  span.set_error(exception)
32
37
  end
38
+
39
+ # :nodoc:
40
+ def set_tag(tag, value, span=nil)
41
+ (span || active_span).set_tag(tag, value)
42
+ end
43
+
33
44
  end
34
45
  end
35
46
  end
@@ -29,6 +29,16 @@ module Deimos
29
29
  @logger.info("Mock span '#{name}' finished: #{start} to #{finish}")
30
30
  end
31
31
 
32
+ # :nodoc:
33
+ def active_span
34
+ nil
35
+ end
36
+
37
+ # :nodoc:
38
+ def set_tag(name, value)
39
+ nil
40
+ end
41
+
32
42
  # :nodoc:
33
43
  def set_error(span, exception)
34
44
  span[:exception] = exception
@@ -24,6 +24,19 @@ module Deimos
24
24
  def set_error(span, exception)
25
25
  raise NotImplementedError
26
26
  end
27
+
28
+ # Get the currently activated span.
29
+ def active_span
30
+ raise NotImplementedError
31
+ end
32
+
33
+ # Set a tag to a span. Use the currently active span if not given.
34
+ # @param tag [String]
35
+ # @param value [String]
36
+ def set_tag(tag, value, span=nil)
37
+ raise NotImplementedError
38
+ end
39
+
27
40
  end
28
41
  end
29
42
  end
@@ -5,14 +5,28 @@ module Deimos
5
5
  # Class used by SchemaClassGenerator and Consumer/Producer interfaces
6
6
  module SchemaClass
7
7
  class << self
8
+
9
+ # @param namespace [String]
10
+ # @return [Array<String>]
11
+ def modules_for(namespace)
12
+ modules = ['Schemas']
13
+ namespace_folder = namespace.split('.').last
14
+ if Deimos.config.schema.generate_namespace_folders && namespace_folder
15
+ modules.push(namespace_folder.underscore.classify)
16
+ end
17
+ modules
18
+ end
19
+
8
20
  # Converts a raw payload into an instance of the Schema Class
9
21
  # @param payload [Hash, Deimos::SchemaClass::Base]
10
22
  # @param schema [String]
23
+ # @param namespace [String]
11
24
  # @return [Deimos::SchemaClass::Record]
12
- def instance(payload, schema)
25
+ def instance(payload, schema, namespace='')
13
26
  return payload if payload.is_a?(Deimos::SchemaClass::Base)
14
27
 
15
- klass = "Schemas::#{schema.underscore.camelize}".safe_constantize
28
+ constants = modules_for(namespace) + [schema.underscore.camelize.singularize]
29
+ klass = constants.join('::').safe_constantize
16
30
  return payload if klass.nil? || payload.nil?
17
31
 
18
32
  klass.new(**payload.symbolize_keys)
@@ -98,6 +98,12 @@ module Deimos
98
98
  namespace, schema = parse_namespace(:request)
99
99
  decoder = Deimos.schema_backend(schema: schema, namespace: namespace)
100
100
  @payload = decoder.decode(request.body.read).with_indifferent_access
101
+ @payload.each do |key, value|
102
+ Deimos.config.tracer&.set_tag("body.#{key}", value)
103
+ end
104
+ if Deimos.config.schema.use_schema_classes
105
+ @payload = Utils::SchemaClass.instance(@payload, schema, namespace)
106
+ end
101
107
  request.body.rewind if request.body.respond_to?(:rewind)
102
108
  end
103
109
 
@@ -106,7 +112,7 @@ module Deimos
106
112
  def render_schema(payload, schema: nil, namespace: nil)
107
113
  namespace, schema = parse_namespace(:response) if !schema && !namespace
108
114
  encoder = Deimos.schema_backend(schema: schema, namespace: namespace)
109
- encoded = encoder.encode(payload, topic: "#{namespace}.#{schema}")
115
+ encoded = encoder.encode(payload.to_h, topic: "#{namespace}.#{schema}")
110
116
  response.headers['Content-Type'] = encoder.class.content_type
111
117
  send_data(encoded)
112
118
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Deimos
4
- VERSION = '1.15.1'
4
+ VERSION = '1.16.2'
5
5
  end
@@ -3,19 +3,8 @@
3
3
  # @return ['<%= @current_schema.symbols.join("', '") %>']
4
4
  attr_accessor :<%= @current_schema.name.underscore %>
5
5
 
6
- # :nodoc:
7
- def initialize(<%= @current_schema.name.underscore %>)
8
- super
9
- self.<%= @current_schema.name.underscore %> = <%= @current_schema.name.underscore %>
10
- end
11
-
12
6
  # @override
13
7
  def symbols
14
8
  %w(<%= @current_schema.symbols.join(' ') %>)
15
9
  end
16
-
17
- # @override
18
- def to_h
19
- @<%= @current_schema.name.underscore %>
20
- end
21
10
  end
@@ -64,10 +64,10 @@
64
64
  end
65
65
 
66
66
  # @override
67
- def to_h
67
+ def as_json(_opts={})
68
68
  {
69
69
  <%- @fields.each do |field| -%>
70
- <%= field_to_h(field) %>
70
+ <%= field_as_json(field) %>
71
71
  <% end -%>
72
72
  }
73
73
  end
@@ -108,16 +108,12 @@ module Deimos
108
108
  # @param key_schema_base [Avro::Schema::NamedSchema, nil]
109
109
  def write_file(schema, key_schema_base)
110
110
  class_template = _generate_class_template_from_schema(schema, key_schema_base)
111
- @modules = ['Schemas']
112
- namespace_folder = schema.namespace.split('.').last
113
- if Deimos.config.schema.generate_namespace_folders
114
- @modules.push(namespace_folder.underscore.classify)
115
- end
111
+ @modules = Utils::SchemaClass.modules_for(schema.namespace)
116
112
  @main_class_definition = class_template
117
113
 
118
114
  file_prefix = schema.name.underscore.singularize
119
115
  if Deimos.config.schema.generate_namespace_folders
120
- file_prefix = "#{namespace_folder}/#{file_prefix}"
116
+ file_prefix = "#{@modules.last.underscore.singularize}/#{file_prefix}"
121
117
  end
122
118
  filename = "#{Deimos.config.schema.generated_class_path}/#{file_prefix}.rb"
123
119
  template(SCHEMA_CLASS_FILE, filename, force: true)
@@ -126,18 +122,18 @@ module Deimos
126
122
  # Format a given field into its appropriate to_h representation.
127
123
  # @param field[Deimos::SchemaField]
128
124
  # @return [String]
129
- def field_to_h(field)
125
+ def field_as_json(field)
130
126
  res = "'#{field.name}' => @#{field.name}"
131
127
  field_base_type = _schema_base_class(field.type).type_sym
132
128
 
133
129
  if %i(record enum).include?(field_base_type)
134
130
  res += case field.type.type_sym
135
131
  when :array
136
- '.map { |v| v&.to_h }'
132
+ '.map { |v| v&.as_json }'
137
133
  when :map
138
- '.transform_values { |v| v&.to_h }'
134
+ '.transform_values { |v| v&.as_json }'
139
135
  else
140
- '&.to_h'
136
+ '&.as_json'
141
137
  end
142
138
  end
143
139
 
@@ -45,6 +45,24 @@ describe Deimos::ActiveRecordProducer do
45
45
  record_class Widget
46
46
  end
47
47
  stub_const('MyProducerWithUniqueID', producer_class)
48
+
49
+ producer_class = Class.new(Deimos::ActiveRecordProducer) do
50
+ schema 'MySchemaWithUniqueId'
51
+ namespace 'com.my-namespace'
52
+ topic 'my-topic-with-unique-id'
53
+ key_config field: :id
54
+ record_class Widget
55
+
56
+ # :nodoc:
57
+ def self.post_process(batch)
58
+ batch.each do |message|
59
+ message.test_id = 'post_processed'
60
+ message.save!
61
+ end
62
+ end
63
+ end
64
+
65
+ stub_const('MyProducerWithPostProcess', producer_class)
48
66
  end
49
67
 
50
68
  describe 'produce' do
@@ -85,6 +103,12 @@ describe Deimos::ActiveRecordProducer do
85
103
  )
86
104
  end
87
105
 
106
+ it 'should post process the batch of records in #send_events' do
107
+ widget = Widget.create!(test_id: 'abc3', some_int: 4)
108
+ MyProducerWithPostProcess.send_events([widget])
109
+ expect(widget.reload.test_id).to eq('post_processed')
110
+ end
111
+
88
112
  end
89
113
  end
90
114
  end
@@ -32,6 +32,13 @@ module ConsumerTest
32
32
  describe 'consume_batch' do
33
33
  SCHEMA_CLASS_SETTINGS.each do |setting, use_schema_classes|
34
34
  context "with Schema Class consumption #{setting}" do
35
+
36
+ let(:schema_class_batch) do
37
+ batch.map do |p|
38
+ Deimos::Utils::SchemaClass.instance(p, 'MySchema', 'com.my-namespace')
39
+ end
40
+ end
41
+
35
42
  before(:each) do
36
43
  Deimos.configure { |config| config.schema.use_schema_classes = use_schema_classes }
37
44
  end
@@ -49,26 +56,22 @@ module ConsumerTest
49
56
  end
50
57
  stub_const('ConsumerTest::MyOldBatchConsumer', consumer_class)
51
58
 
52
- test_consume_batch(MyOldBatchConsumer, batch) do |received, _metadata|
53
- expect(received).to eq(batch)
59
+ test_consume_batch(MyOldBatchConsumer, schema_class_batch) do |received, _metadata|
60
+ expect(received).to eq(schema_class_batch)
54
61
  end
55
62
  end
56
63
 
57
64
  it 'should consume a batch of messages' do
58
- test_consume_batch(MyBatchConsumer, batch) do |received, _metadata|
59
- expect(received).to eq(batch)
65
+ test_consume_batch(MyBatchConsumer, schema_class_batch) do |received, _metadata|
66
+ expect(received).to eq(schema_class_batch)
60
67
  end
61
68
  end
62
69
 
63
70
  it 'should consume a message on a topic' do
64
- test_consume_batch('my_batch_consume_topic', batch) do |received, _metadata|
65
- expect(received).to eq(batch)
71
+ test_consume_batch('my_batch_consume_topic', schema_class_batch) do |received, _metadata|
72
+ expect(received).to eq(schema_class_batch)
66
73
  end
67
74
  end
68
-
69
- it 'should fail on an invalid message in the batch' do
70
- test_consume_batch_invalid_message(MyBatchConsumer, batch.concat(invalid_payloads))
71
- end
72
75
  end
73
76
  end
74
77
  end
@@ -6,23 +6,23 @@ RSpec.describe Schemas::MySchemaWithCircularReference do
6
6
  {
7
7
  properties: {
8
8
  a_boolean: {
9
- property: true
9
+ 'property' => true
10
10
  },
11
11
  an_integer: {
12
- property: 1
12
+ 'property' => 1
13
13
  },
14
14
  a_float: {
15
- property: 4.5
15
+ 'property' => 4.5
16
16
  },
17
17
  a_string: {
18
- property: 'string'
18
+ 'property' => 'string'
19
19
  },
20
20
  an_array: {
21
- property: [1, 2, 3]
21
+ 'property' => [1, 2, 3]
22
22
  },
23
23
  an_hash: {
24
- property: {
25
- a_key: 'a_value'
24
+ 'property' => {
25
+ 'a_key' => 'a_value'
26
26
  }
27
27
  }
28
28
  }
@@ -63,23 +63,23 @@ RSpec.describe Schemas::MySchemaWithCircularReference do
63
63
  described_class.new(**payload_hash)
64
64
  payload_h = {
65
65
  'properties' => {
66
- 'a_boolean' => {
67
- 'property' => true
66
+ a_boolean: {
67
+ 'property' =>true
68
68
  },
69
- 'an_integer' => {
70
- 'property' => 1
69
+ an_integer: {
70
+ 'property' =>1
71
71
  },
72
- 'a_float' => {
73
- 'property' => 4.5
72
+ a_float: {
73
+ 'property' =>4.5
74
74
  },
75
- 'a_string' => {
76
- 'property' => 'string'
75
+ a_string: {
76
+ 'property' =>'string'
77
77
  },
78
- 'an_array' => {
79
- 'property' => [1, 2, 3]
78
+ an_array: {
79
+ 'property' =>[1, 2, 3]
80
80
  },
81
- 'an_hash' => {
82
- 'property' => {
81
+ an_hash: {
82
+ 'property' =>{
83
83
  'a_key' => 'a_value'
84
84
  }
85
85
  }
@@ -153,7 +153,7 @@ RSpec.describe Schemas::MySchemaWithComplexType do
153
153
  it 'should get the value of some_enum_array' do
154
154
  some_enum_array = klass.some_enum_array
155
155
  expect(some_enum_array.first).to be_instance_of(Schemas::MySchemaWithComplexType::AnEnum)
156
- expect(some_enum_array.first.an_enum).to eq('sym1')
156
+ expect(some_enum_array.first.value).to eq('sym1')
157
157
  end
158
158
 
159
159
  it 'should get the value of some_record' do
@@ -197,7 +197,7 @@ RSpec.describe Schemas::MySchemaWithComplexType do
197
197
  end
198
198
 
199
199
  it 'should modify the value of some_enum_array' do
200
- klass.some_enum_array.first.an_enum = 'new_sym'
200
+ klass.some_enum_array.first.value = 'new_sym'
201
201
  expect(klass.some_enum_array.first).
202
202
  to eq(Schemas::MySchemaWithComplexType::AnEnum.new('new_sym'))
203
203
 
@@ -31,7 +31,7 @@ module Schemas
31
31
  end
32
32
 
33
33
  # @override
34
- def to_h
34
+ def as_json(_opts={})
35
35
  {
36
36
  'a_record_field' => @a_record_field
37
37
  }
@@ -55,7 +55,7 @@ module Schemas
55
55
  end
56
56
 
57
57
  # @override
58
- def to_h
58
+ def as_json(_opts={})
59
59
  @an_enum
60
60
  end
61
61
  end
@@ -139,7 +139,7 @@ module Schemas
139
139
  end
140
140
 
141
141
  # @override
142
- def to_h
142
+ def as_json(_opts={})
143
143
  {
144
144
  'a_string' => @a_string,
145
145
  'a_int' => @a_int,
@@ -147,12 +147,12 @@ module Schemas
147
147
  'a_float' => @a_float,
148
148
  'a_double' => @a_double,
149
149
  'an_optional_int' => @an_optional_int,
150
- 'an_enum' => @an_enum&.to_h,
150
+ 'an_enum' => @an_enum&.as_json,
151
151
  'an_array' => @an_array,
152
152
  'a_map' => @a_map,
153
153
  'timestamp' => @timestamp,
154
154
  'message_id' => @message_id,
155
- 'a_record' => @a_record&.to_h
155
+ 'a_record' => @a_record&.as_json
156
156
  }
157
157
  end
158
158
  end