From 5f595966d8e6ef5805a375d0feda9730a63ec014 Mon Sep 17 00:00:00 2001 From: Thales Macedo Garitezi Date: Thu, 11 Jul 2024 12:17:53 -0300 Subject: [PATCH] chore(message transformation): allow empty operation list Fixes https://emqx.atlassian.net/browse/EMQX-12682 --- .../src/emqx_message_transformation_schema.erl | 8 +------- .../test/emqx_message_transformation_tests.erl | 11 +++-------- 2 files changed, 4 insertions(+), 15 deletions(-) diff --git a/apps/emqx_message_transformation/src/emqx_message_transformation_schema.erl b/apps/emqx_message_transformation/src/emqx_message_transformation_schema.erl index 169743e5b..ae1e22245 100644 --- a/apps/emqx_message_transformation/src/emqx_message_transformation_schema.erl +++ b/apps/emqx_message_transformation/src/emqx_message_transformation_schema.erl @@ -108,8 +108,7 @@ fields(transformation) -> hoconsc:array(ref(operation)), #{ desc => ?DESC("operation"), - required => true, - validator => fun validate_operations/1 + default => [] } )} ]; @@ -253,11 +252,6 @@ validate_unique_topics(Topics) -> {error, Msg} end. -validate_operations([]) -> - {error, <<"at least one operation must be defined">>}; -validate_operations([_ | _]) -> - ok. - compile_variform(Expression, #{make_serializable := true}) -> case is_binary(Expression) of true -> diff --git a/apps/emqx_message_transformation/test/emqx_message_transformation_tests.erl b/apps/emqx_message_transformation/test/emqx_message_transformation_tests.erl index 545773c00..6702cd974 100644 --- a/apps/emqx_message_transformation/test/emqx_message_transformation_tests.erl +++ b/apps/emqx_message_transformation/test/emqx_message_transformation_tests.erl @@ -114,14 +114,9 @@ schema_test_() -> transformation(<<"foo">>, [dummy_operation()]) ]) )}, - {"operations must be non-empty", - ?_assertThrow( - {_Schema, [ - #{ - reason := <<"at least one operation must be defined">>, - kind := validation_error - } - ]}, + {"operations may be empty", + ?_assertMatch( + [#{<<"operations">> := []}], parse_and_check([ transformation( <<"foo">>,