feat(bridge): add description field to bridge and connector
This commit is contained in:
parent
73dd2f0ffd
commit
afe6f79a66
|
@ -169,7 +169,11 @@
|
||||||
-export([namespace/0, roots/0, roots/1, fields/1, desc/1, tags/0]).
|
-export([namespace/0, roots/0, roots/1, fields/1, desc/1, tags/0]).
|
||||||
-export([conf_get/2, conf_get/3, keys/2, filter/1]).
|
-export([conf_get/2, conf_get/3, keys/2, filter/1]).
|
||||||
-export([
|
-export([
|
||||||
server_ssl_opts_schema/2, client_ssl_opts_schema/1, ciphers_schema/1, tls_versions_schema/1
|
server_ssl_opts_schema/2,
|
||||||
|
client_ssl_opts_schema/1,
|
||||||
|
ciphers_schema/1,
|
||||||
|
tls_versions_schema/1,
|
||||||
|
description_schema/0
|
||||||
]).
|
]).
|
||||||
-export([password_converter/2, bin_str_converter/2]).
|
-export([password_converter/2, bin_str_converter/2]).
|
||||||
-export([authz_fields/0]).
|
-export([authz_fields/0]).
|
||||||
|
@ -3649,3 +3653,14 @@ default_mem_check_interval() ->
|
||||||
true -> <<"60s">>;
|
true -> <<"60s">>;
|
||||||
false -> disabled
|
false -> disabled
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
description_schema() ->
|
||||||
|
sc(
|
||||||
|
string(),
|
||||||
|
#{
|
||||||
|
default => <<"">>,
|
||||||
|
desc => ?DESC(description),
|
||||||
|
required => false,
|
||||||
|
importance => ?IMPORTANCE_LOW
|
||||||
|
}
|
||||||
|
).
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
-include_lib("typerefl/include/types.hrl").
|
-include_lib("typerefl/include/types.hrl").
|
||||||
-include_lib("hocon/include/hoconsc.hrl").
|
-include_lib("hocon/include/hoconsc.hrl").
|
||||||
-include_lib("emqx/include/logger.hrl").
|
-include_lib("emqx/include/logger.hrl").
|
||||||
|
-include_lib("eunit/include/eunit.hrl").
|
||||||
|
|
||||||
-import(hoconsc, [mk/2, ref/2]).
|
-import(hoconsc, [mk/2, ref/2]).
|
||||||
|
|
||||||
|
@ -127,3 +128,45 @@ desc(bridges_v2) ->
|
||||||
?DESC("desc_bridges_v2");
|
?DESC("desc_bridges_v2");
|
||||||
desc(_) ->
|
desc(_) ->
|
||||||
undefined.
|
undefined.
|
||||||
|
|
||||||
|
-ifdef(TEST).
|
||||||
|
-include_lib("hocon/include/hocon_types.hrl").
|
||||||
|
schema_homogeneous_test() ->
|
||||||
|
case
|
||||||
|
lists:filtermap(
|
||||||
|
fun({_Name, Schema}) ->
|
||||||
|
is_bad_schema(Schema)
|
||||||
|
end,
|
||||||
|
fields(bridges_v2)
|
||||||
|
)
|
||||||
|
of
|
||||||
|
[] ->
|
||||||
|
ok;
|
||||||
|
List ->
|
||||||
|
throw(List)
|
||||||
|
end.
|
||||||
|
|
||||||
|
is_bad_schema(#{type := ?MAP(_, ?R_REF(Module, TypeName))}) ->
|
||||||
|
Fields = Module:fields(TypeName),
|
||||||
|
ExpectedFieldNames = common_field_names(),
|
||||||
|
MissingFileds = lists:filter(
|
||||||
|
fun(Name) -> lists:keyfind(Name, 1, Fields) =:= false end, ExpectedFieldNames
|
||||||
|
),
|
||||||
|
case MissingFileds of
|
||||||
|
[] ->
|
||||||
|
false;
|
||||||
|
_ ->
|
||||||
|
{true, #{
|
||||||
|
schema_modle => Module,
|
||||||
|
type_name => TypeName,
|
||||||
|
missing_fields => MissingFileds
|
||||||
|
}}
|
||||||
|
end.
|
||||||
|
|
||||||
|
common_field_names() ->
|
||||||
|
%% TODO: add 'config' to the list
|
||||||
|
[
|
||||||
|
enable, description, local_topic, connector, resource_opts
|
||||||
|
].
|
||||||
|
|
||||||
|
-endif.
|
||||||
|
|
|
@ -125,7 +125,8 @@ fields(bridge_v2) ->
|
||||||
{connector,
|
{connector,
|
||||||
mk(binary(), #{
|
mk(binary(), #{
|
||||||
desc => ?DESC(emqx_connector_schema, "connector_field"), required => true
|
desc => ?DESC(emqx_connector_schema, "connector_field"), required => true
|
||||||
})}
|
})},
|
||||||
|
{description, emqx_schema:description_schema()}
|
||||||
],
|
],
|
||||||
override_documentations(Fields);
|
override_documentations(Fields);
|
||||||
fields(Method) ->
|
fields(Method) ->
|
||||||
|
|
|
@ -266,13 +266,15 @@ fields(kafka_producer_action) ->
|
||||||
{connector,
|
{connector,
|
||||||
mk(binary(), #{
|
mk(binary(), #{
|
||||||
desc => ?DESC(emqx_connector_schema, "connector_field"), required => true
|
desc => ?DESC(emqx_connector_schema, "connector_field"), required => true
|
||||||
})}
|
})},
|
||||||
|
{description, emqx_schema:description_schema()}
|
||||||
] ++ fields(producer_opts);
|
] ++ fields(producer_opts);
|
||||||
fields(kafka_consumer) ->
|
fields(kafka_consumer) ->
|
||||||
fields("config") ++ fields(consumer_opts);
|
fields("config") ++ fields(consumer_opts);
|
||||||
fields("config") ->
|
fields("config") ->
|
||||||
[
|
[
|
||||||
{enable, mk(boolean(), #{desc => ?DESC("config_enable"), default => true})},
|
{enable, mk(boolean(), #{desc => ?DESC("config_enable"), default => true})},
|
||||||
|
{description, emqx_schema:description_schema()},
|
||||||
{bootstrap_hosts,
|
{bootstrap_hosts,
|
||||||
mk(
|
mk(
|
||||||
binary(),
|
binary(),
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
-include_lib("typerefl/include/types.hrl").
|
-include_lib("typerefl/include/types.hrl").
|
||||||
-include_lib("hocon/include/hoconsc.hrl").
|
-include_lib("hocon/include/hoconsc.hrl").
|
||||||
-include_lib("emqx/include/logger.hrl").
|
-include_lib("emqx/include/logger.hrl").
|
||||||
|
-include_lib("eunit/include/eunit.hrl").
|
||||||
|
|
||||||
-import(hoconsc, [mk/2, ref/2]).
|
-import(hoconsc, [mk/2, ref/2]).
|
||||||
|
|
||||||
|
@ -305,3 +306,44 @@ to_bin(Bin) when is_binary(Bin) ->
|
||||||
Bin;
|
Bin;
|
||||||
to_bin(Something) ->
|
to_bin(Something) ->
|
||||||
Something.
|
Something.
|
||||||
|
|
||||||
|
-ifdef(TEST).
|
||||||
|
-include_lib("hocon/include/hocon_types.hrl").
|
||||||
|
schema_homogeneous_test() ->
|
||||||
|
case
|
||||||
|
lists:filtermap(
|
||||||
|
fun({_Name, Schema}) ->
|
||||||
|
is_bad_schema(Schema)
|
||||||
|
end,
|
||||||
|
fields(connectors)
|
||||||
|
)
|
||||||
|
of
|
||||||
|
[] ->
|
||||||
|
ok;
|
||||||
|
List ->
|
||||||
|
throw(List)
|
||||||
|
end.
|
||||||
|
|
||||||
|
is_bad_schema(#{type := ?MAP(_, ?R_REF(Module, TypeName))}) ->
|
||||||
|
Fields = Module:fields(TypeName),
|
||||||
|
ExpectedFieldNames = common_field_names(),
|
||||||
|
MissingFileds = lists:filter(
|
||||||
|
fun(Name) -> lists:keyfind(Name, 1, Fields) =:= false end, ExpectedFieldNames
|
||||||
|
),
|
||||||
|
case MissingFileds of
|
||||||
|
[] ->
|
||||||
|
false;
|
||||||
|
_ ->
|
||||||
|
{true, #{
|
||||||
|
schema_modle => Module,
|
||||||
|
type_name => TypeName,
|
||||||
|
missing_fields => MissingFileds
|
||||||
|
}}
|
||||||
|
end.
|
||||||
|
|
||||||
|
common_field_names() ->
|
||||||
|
[
|
||||||
|
enable, description
|
||||||
|
].
|
||||||
|
|
||||||
|
-endif.
|
||||||
|
|
|
@ -1571,4 +1571,9 @@ the system topic <code>$SYS/sysmon/large_heap</code>."""
|
||||||
sysmon_vm_large_heap.label:
|
sysmon_vm_large_heap.label:
|
||||||
"""Enable Large Heap monitoring."""
|
"""Enable Large Heap monitoring."""
|
||||||
|
|
||||||
|
description.label:
|
||||||
|
"""Description"""
|
||||||
|
description.desc:
|
||||||
|
"""Descriptive text."""
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue