docs(mqtt_bridge): add API examples

This commit is contained in:
Thales Macedo Garitezi 2024-01-16 10:24:19 -03:00
parent 60fab6ee45
commit a8f9e5676f
3 changed files with 56 additions and 7 deletions

View File

@ -49,6 +49,9 @@
-export([lookup_from_local_node/2]). -export([lookup_from_local_node/2]).
-export([get_metrics_from_local_node/2]). -export([get_metrics_from_local_node/2]).
%% used by actions/sources schema
-export([mqtt_v1_example/1]).
%% only for testing/mocking %% only for testing/mocking
-export([supported_versions/1]). -export([supported_versions/1]).
@ -181,7 +184,7 @@ bridge_info_examples(Method) ->
}, },
<<"mqtt_example">> => #{ <<"mqtt_example">> => #{
summary => <<"MQTT Bridge">>, summary => <<"MQTT Bridge">>,
value => info_example(mqtt, Method) value => mqtt_v1_example(Method)
} }
}, },
emqx_enterprise_bridge_examples(Method) emqx_enterprise_bridge_examples(Method)
@ -194,6 +197,9 @@ emqx_enterprise_bridge_examples(Method) ->
emqx_enterprise_bridge_examples(_Method) -> #{}. emqx_enterprise_bridge_examples(_Method) -> #{}.
-endif. -endif.
mqtt_v1_example(Method) ->
info_example(mqtt, Method).
info_example(Type, Method) -> info_example(Type, Method) ->
maps:merge( maps:merge(
info_example_basic(Type), info_example_basic(Type),

View File

@ -176,7 +176,7 @@ source_values(Method, SourceType, ConnectorType, SourceValues) ->
description => <<"My example ", SourceTypeBin/binary, " source">>, description => <<"My example ", SourceTypeBin/binary, " source">>,
connector => <<ConnectorTypeBin/binary, "_connector">>, connector => <<ConnectorTypeBin/binary, "_connector">>,
resource_opts => #{ resource_opts => #{
health_check_interval => "30s" health_check_interval => <<"30s">>
} }
}, },
[ [
@ -192,7 +192,7 @@ sources_examples(Method) ->
end, end,
Fun = Fun =
fun(Module, Examples) -> fun(Module, Examples) ->
ConnectorExamples = erlang:apply(Module, bridge_v2_examples, [Method]), ConnectorExamples = erlang:apply(Module, source_examples, [Method]),
lists:foldl(MergeFun, Examples, ConnectorExamples) lists:foldl(MergeFun, Examples, ConnectorExamples)
end, end,
SchemaModules = [Mod || {_, Mod} <- emqx_action_info:registered_schema_modules_sources()], SchemaModules = [Mod || {_, Mod} <- emqx_action_info:registered_schema_modules_sources()],

View File

@ -24,6 +24,7 @@
-export([ -export([
bridge_v2_examples/1, bridge_v2_examples/1,
source_examples/1,
conn_bridge_examples/1 conn_bridge_examples/1
]). ]).
@ -148,12 +149,54 @@ desc("mqtt_subscriber_source") ->
desc(_) -> desc(_) ->
undefined. undefined.
bridge_v2_examples(_Method) -> bridge_v2_examples(Method) ->
[ [
#{} #{
<<"mqtt">> => #{
summary => <<"MQTT Producer Action">>,
value => emqx_bridge_v2_schema:action_values(
Method,
_ActionType = mqtt,
_ConnectorType = mqtt,
#{
parameters => #{
topic => <<"remote/topic">>,
qos => 2,
retain => false,
payload => <<"${.payload}">>
}
}
)
}
}
]. ].
conn_bridge_examples(_Method) -> source_examples(Method) ->
[ [
#{} #{
<<"mqtt">> => #{
summary => <<"MQTT Subscriber Source">>,
value => emqx_bridge_v2_schema:source_values(
Method,
_SourceType = mqtt,
_ConnectorType = mqtt,
#{
parameters => #{
topic => <<"remote/topic">>,
qos => 2
}
}
)
}
}
].
conn_bridge_examples(Method) ->
[
#{
<<"mqtt">> => #{
summary => <<"MQTT Producer Action">>,
value => emqx_bridge_api:mqtt_v1_example(Method)
}
}
]. ].