Skip to content

Commit 3c0bdad

Browse files
Validate Avro schema before encoding
1 parent 6cd65da commit 3c0bdad

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

lib/streamy/serializers/avro_serializer.rb

+4-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@ def self.clear_messaging_cache
2020
end
2121

2222
def self.encode(payload, schema_namespace: nil)
23-
messaging.encode(payload.deep_stringify_keys, schema_name: payload[:type], namespace: schema_namespace)
23+
messaging.encode(payload.deep_stringify_keys,
24+
schema_name: payload[:type],
25+
namespace: schema_namespace,
26+
validate: true)
2427
end
2528
end
2629
end

test/avro_event_test.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ def test_helpful_error_message_on_incorrect_attribute_type
8888
exception = assert_raises Streamy::PublicationFailedError do
8989
IncorrectAttributeEvent.publish
9090
end
91-
assert_match("Avro::IO::AvroTypeError", exception.message)
91+
assert_match("Avro::SchemaValidator::ValidationError", exception.message)
9292
end
9393

9494
def test_helpful_error_message_on_event_with_no_schema

0 commit comments

Comments
 (0)