Просмотр исходного кода

docs(mqtt_bridge): add API examples

Thales Macedo Garitezi 2 лет назад
Родитель
Сommit
a8f9e5676f

+ 7 - 1
apps/emqx_bridge/src/emqx_bridge_api.erl

@@ -49,6 +49,9 @@
 -export([lookup_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
 -export([supported_versions/1]).
 
@@ -181,7 +184,7 @@ bridge_info_examples(Method) ->
             },
             <<"mqtt_example">> => #{
                 summary => <<"MQTT Bridge">>,
-                value => info_example(mqtt, Method)
+                value => mqtt_v1_example(Method)
             }
         },
         emqx_enterprise_bridge_examples(Method)
@@ -194,6 +197,9 @@ emqx_enterprise_bridge_examples(Method) ->
 emqx_enterprise_bridge_examples(_Method) -> #{}.
 -endif.
 
+mqtt_v1_example(Method) ->
+    info_example(mqtt, Method).
+
 info_example(Type, Method) ->
     maps:merge(
         info_example_basic(Type),

+ 2 - 2
apps/emqx_bridge/src/schema/emqx_bridge_v2_schema.erl

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

+ 47 - 4
apps/emqx_bridge_mqtt/src/emqx_bridge_mqtt_pubsub_schema.erl

@@ -24,6 +24,7 @@
 
 -export([
     bridge_v2_examples/1,
+    source_examples/1,
     conn_bridge_examples/1
 ]).
 
@@ -148,12 +149,54 @@ desc("mqtt_subscriber_source") ->
 desc(_) ->
     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}">>
+                        }
+                    }
+                )
+            }
+        }
+    ].
+
+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) ->
+conn_bridge_examples(Method) ->
     [
-        #{}
+        #{
+            <<"mqtt">> => #{
+                summary => <<"MQTT Producer Action">>,
+                value => emqx_bridge_api:mqtt_v1_example(Method)
+            }
+        }
     ].