deimos-ruby 1.15.0 → 1.16.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.
Files changed (42) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +9 -0
  3. data/lib/deimos/active_record_producer.rb +1 -1
  4. data/lib/deimos/consumer.rb +3 -1
  5. data/lib/deimos/schema_class/base.rb +2 -25
  6. data/lib/deimos/schema_class/enum.rb +23 -0
  7. data/lib/deimos/schema_class/record.rb +15 -4
  8. data/lib/deimos/test_helpers.rb +3 -2
  9. data/lib/deimos/tracing/datadog.rb +11 -0
  10. data/lib/deimos/tracing/mock.rb +10 -0
  11. data/lib/deimos/tracing/provider.rb +13 -0
  12. data/lib/deimos/utils/db_poller.rb +1 -2
  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/deimos.rb +1 -2
  17. data/lib/generators/deimos/schema_class/templates/schema_enum.rb.tt +0 -11
  18. data/lib/generators/deimos/schema_class/templates/schema_record.rb.tt +2 -2
  19. data/lib/generators/deimos/schema_class_generator.rb +6 -10
  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 +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0dd1a31f2dd75e160a7d63b4588b9cfc1f489be46650508aae3797f6d032110b
4
- data.tar.gz: 8e1167cd5481a96ce18a53d46a9f153f9266d909bc54a50cc727ffe8d4a86244
3
+ metadata.gz: 4567929aa6bd384c8660dba57a515c4ed3a2cd9ed68538b0ecadac9365a95ff0
4
+ data.tar.gz: a92f990d962472198909ed848edbc2525da9bc20e6cfb62ec10636ca518714ef
5
5
  SHA512:
6
- metadata.gz: cfad01dea7198a9ecf8b063433abc47d81db127beedf54213a82f995713c5b28a706ca43dba9129b28e38cfc8d1e0144f078786507a32e359f822a71ef9c0927
7
- data.tar.gz: 9dc3e5dadac11d3b32a386ebbd938fc128a32bdfb511674489491a266e58c13074708d30fc89f47534e481949e59eeb18cbd4858eff9d27a28946408234c55ed
6
+ metadata.gz: 4db26d8c81d484a1888c26079291d54b410aa71c472780a49ecc0f25bc395c9503c0cdfd53847b9f289b00d1467cea357f8946325e4a22bff4bbcf5658fd12a5
7
+ data.tar.gz: cfb9415e32cfb96447ea95e80e62d1364933de4d0fd436b29056e94455ccafa012de4f07b8e8549e6e759c3ae909873d3b9fe9b70502dc085c3dd3caac4c2393
data/CHANGELOG.md CHANGED
@@ -7,6 +7,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## UNRELEASED
9
9
 
10
+ # 1.16.1 - 2022-08-03
11
+
12
+ - Fix issues with `enum` schema classes (e.g. equality not working, `to_s` not working)
13
+ - 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.
14
+ - Added the `active_span` and `set_tag` methods to the tracing classes.
15
+ - Added span tags for fields in SchemaControllerMixin.
16
+ - Updated SchemaControllerMixin so it works with generated schema classes.
17
+ - Fixed bug with previous release where the filename and constant names for `generate_namespace_folders` did not always match.
18
+
10
19
  # 1.15.0 - 2022-07-20
11
20
 
12
21
  - Update to `sigurd` 0.1.0 - DB producer should now exit when receiving a `SIGTERM` instead of throwing a `SignalException`
@@ -60,7 +60,7 @@ module Deimos
60
60
  end
61
61
  return payload unless Utils::SchemaClass.use?(config.to_h)
62
62
 
63
- Utils::SchemaClass.instance(payload, config[:schema])
63
+ Utils::SchemaClass.instance(payload, config[:schema], config[:namespace])
64
64
  end
65
65
 
66
66
  # Query to use when polling the database with the DbPoller. Add
@@ -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
@@ -1,8 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'deimos/poll_info'
4
- require 'sigurd/executor'
5
- require 'sigurd/signal_handler'
4
+ require 'sigurd'
6
5
 
7
6
  module Deimos
8
7
  module Utils
@@ -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.0'
4
+ VERSION = '1.16.1'
5
5
  end
data/lib/deimos.rb CHANGED
@@ -33,8 +33,7 @@ if defined?(ActiveRecord)
33
33
  require 'deimos/kafka_source'
34
34
  require 'deimos/kafka_topic_info'
35
35
  require 'deimos/backends/db'
36
- require 'sigurd/signal_handler'
37
- require 'sigurd/executor'
36
+ require 'sigurd'
38
37
  require 'deimos/utils/db_producer'
39
38
  require 'deimos/utils/db_poller'
40
39
  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
 
@@ -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
@@ -43,7 +43,7 @@ module Schemas
43
43
  end
44
44
 
45
45
  # @override
46
- def to_h
46
+ def as_json(_opts={})
47
47
  {
48
48
  'some_int' => @some_int,
49
49
  'some_float' => @some_float,
@@ -104,13 +104,13 @@ module Schemas
104
104
  end
105
105
 
106
106
  # @override
107
- def to_h
107
+ def as_json(_opts={})
108
108
  {
109
109
  'test_id' => @test_id,
110
110
  'test_float' => @test_float,
111
111
  'test_array' => @test_array,
112
- 'some_nested_record' => @some_nested_record&.to_h,
113
- 'some_optional_record' => @some_optional_record&.to_h
112
+ 'some_nested_record' => @some_nested_record&.as_json,
113
+ 'some_optional_record' => @some_optional_record&.as_json
114
114
  }
115
115
  end
116
116
  end
@@ -43,11 +43,11 @@ module Schemas
43
43
  end
44
44
 
45
45
  # @override
46
- def to_h
46
+ def as_json(_opts={})
47
47
  {
48
48
  'test_id' => @test_id,
49
49
  'some_int' => @some_int,
50
- 'payload_key' => @payload_key&.to_h
50
+ 'payload_key' => @payload_key&.as_json
51
51
  }
52
52
  end
53
53
  end
@@ -27,7 +27,7 @@ module Schemas
27
27
  end
28
28
 
29
29
  # @override
30
- def to_h
30
+ def as_json(_opts={})
31
31
  {
32
32
  'test_id' => @test_id
33
33
  }
@@ -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
  'property' => @property
37
37
  }
@@ -68,9 +68,9 @@ module Schemas
68
68
  end
69
69
 
70
70
  # @override
71
- def to_h
71
+ def as_json(_opts={})
72
72
  {
73
- 'properties' => @properties.transform_values { |v| v&.to_h }
73
+ 'properties' => @properties.transform_values { |v| v&.as_json }
74
74
  }
75
75
  end
76
76
  end