diff --git a/apps/emqx_connector/src/emqx_connector_api.erl b/apps/emqx_connector/src/emqx_connector_api.erl index f25fe9b7e..af5721585 100644 --- a/apps/emqx_connector/src/emqx_connector_api.erl +++ b/apps/emqx_connector/src/emqx_connector_api.erl @@ -610,11 +610,12 @@ format_resource( #{ type := Type, name := ConnectorName, - raw_config := RawConf, + raw_config := RawConf0, resource_data := ResourceData }, Node ) -> + RawConf = fill_defaults(Type, RawConf0), redact( maps:merge( RawConf#{ @@ -638,6 +639,20 @@ format_resource_data(added_channels, Channels, Result) -> format_resource_data(K, V, Result) -> Result#{K => V}. +fill_defaults(Type, RawConf) -> + PackedConf = pack_connector_conf(Type, RawConf), + FullConf = emqx_config:fill_defaults(emqx_connector_schema, PackedConf, #{}), + unpack_connector_conf(Type, FullConf). + +pack_connector_conf(Type, RawConf) -> + #{<<"connectors">> => #{bin(Type) => #{<<"foo">> => RawConf}}}. + +unpack_connector_conf(Type, PackedConf) -> + TypeBin = bin(Type), + #{<<"connectors">> := Bridges} = PackedConf, + #{<<"foo">> := RawConf} = maps:get(TypeBin, Bridges), + RawConf. + format_action(ActionId) -> element(2, emqx_bridge_v2:parse_id(ActionId)). diff --git a/apps/emqx_connector/test/emqx_connector_api_SUITE.erl b/apps/emqx_connector/test/emqx_connector_api_SUITE.erl index c020c2504..92fd1de6d 100644 --- a/apps/emqx_connector/test/emqx_connector_api_SUITE.erl +++ b/apps/emqx_connector/test/emqx_connector_api_SUITE.erl @@ -845,6 +845,19 @@ t_fail_delete_with_action(Config) -> ), ok. +t_raw_config_response_defaults(Config) -> + Params = maps:without([<<"enable">>, <<"resource_opts">>], ?KAFKA_CONNECTOR(?CONNECTOR_NAME)), + ?assertMatch( + {ok, 201, #{<<"enable">> := true, <<"resource_opts">> := #{}}}, + request_json( + post, + uri(["connectors"]), + Params, + Config + ) + ), + ok. + %%% helpers listen_on_random_port() -> SockOpts = [binary, {active, false}, {packet, raw}, {reuseaddr, true}, {backlog, 1000}],