Skip to content

Commit

Permalink
Validate Avro schema before encoding
Browse files Browse the repository at this point in the history
  • Loading branch information
robertomiranda committed Apr 29, 2024
1 parent 6cd65da commit 3c0bdad
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
5 changes: 4 additions & 1 deletion lib/streamy/serializers/avro_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ def self.clear_messaging_cache
end

def self.encode(payload, schema_namespace: nil)
messaging.encode(payload.deep_stringify_keys, schema_name: payload[:type], namespace: schema_namespace)
messaging.encode(payload.deep_stringify_keys,
schema_name: payload[:type],
namespace: schema_namespace,
validate: true)
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion test/avro_event_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def test_helpful_error_message_on_incorrect_attribute_type
exception = assert_raises Streamy::PublicationFailedError do
IncorrectAttributeEvent.publish
end
assert_match("Avro::IO::AvroTypeError", exception.message)
assert_match("Avro::SchemaValidator::ValidationError", exception.message)
end

def test_helpful_error_message_on_event_with_no_schema
Expand Down

0 comments on commit 3c0bdad

Please sign in to comment.