From 1a0862913e41b33d39728ceba5cd0b39f8b8d136 Mon Sep 17 00:00:00 2001 From: JimMoen Date: Fri, 21 Jan 2022 17:26:54 +0800 Subject: [PATCH] refactor(api): swagger api tag `mqtt` --- apps/emqx_modules/include/emqx_modules.hrl | 18 ++++++++++++++++++ apps/emqx_modules/src/emqx_delayed_api.erl | 11 ++++++----- apps/emqx_modules/src/emqx_rewrite_api.erl | 4 +++- .../src/emqx_topic_metrics_api.erl | 4 +--- 4 files changed, 28 insertions(+), 9 deletions(-) diff --git a/apps/emqx_modules/include/emqx_modules.hrl b/apps/emqx_modules/include/emqx_modules.hrl index 334173015..6bb95eea2 100644 --- a/apps/emqx_modules/include/emqx_modules.hrl +++ b/apps/emqx_modules/include/emqx_modules.hrl @@ -1,5 +1,23 @@ +%%-------------------------------------------------------------------- +%% Copyright (c) 2021-2022 EMQ Technologies Co., Ltd. All Rights Reserved. +%% +%% Licensed under the Apache License, Version 2.0 (the "License"); +%% you may not use this file except in compliance with the License. +%% You may obtain a copy of the License at +%% +%% http://www.apache.org/licenses/LICENSE-2.0 +%% +%% Unless required by applicable law or agreed to in writing, software +%% distributed under the License is distributed on an "AS IS" BASIS, +%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +%% See the License for the specific language governing permissions and +%% limitations under the License. +%%-------------------------------------------------------------------- + %% The destination URL for the telemetry data report -define(TELEMETRY_URL, "https://telemetry.emqx.io/api/telemetry"). %% Interval for reporting telemetry data, Default: 7d -define(REPORT_INTERVAR, 604800). + +-define(API_TAG_MQTT, [<<"mqtt">>]). diff --git a/apps/emqx_modules/src/emqx_delayed_api.erl b/apps/emqx_modules/src/emqx_delayed_api.erl index 56d782580..9a878f7f2 100644 --- a/apps/emqx_modules/src/emqx_delayed_api.erl +++ b/apps/emqx_modules/src/emqx_delayed_api.erl @@ -19,6 +19,7 @@ -behaviour(minirest_api). -include_lib("typerefl/include/types.hrl"). +-include("emqx_modules.hrl"). -import(hoconsc, [mk/2, ref/1, ref/2]). @@ -62,7 +63,7 @@ schema("/mqtt/delayed") -> #{ 'operationId' => status, get => #{ - tags => [<<"mqtt">>], + tags => ?API_TAG_MQTT, description => <<"Get delayed status">>, summary => <<"Get delayed status">>, responses => #{ @@ -70,7 +71,7 @@ schema("/mqtt/delayed") -> } }, put => #{ - tags => [<<"mqtt">>], + tags => ?API_TAG_MQTT, description => <<"Enable or disable delayed, set max delayed messages">>, 'requestBody' => ref(emqx_modules_schema, "delayed"), responses => #{ @@ -85,7 +86,7 @@ schema("/mqtt/delayed") -> schema("/mqtt/delayed/messages/:msgid") -> #{'operationId' => delayed_message, get => #{ - tags => [<<"mqtt">>], + tags => ?API_TAG_MQTT, description => <<"Get delayed message">>, parameters => [{msgid, mk(binary(), #{in => path, desc => <<"delay message ID">>})}], responses => #{ @@ -97,7 +98,7 @@ schema("/mqtt/delayed/messages/:msgid") -> } }, delete => #{ - tags => [<<"mqtt">>], + tags => ?API_TAG_MQTT, description => <<"Delete delayed message">>, parameters => [{msgid, mk(binary(), #{in => path, desc => <<"delay message ID">>})}], responses => #{ @@ -113,7 +114,7 @@ schema("/mqtt/delayed/messages") -> #{ 'operationId' => delayed_messages, get => #{ - tags => [<<"mqtt">>], + tags => ?API_TAG_MQTT, description => <<"List delayed messages">>, parameters => [ref(emqx_dashboard_swagger, page), ref(emqx_dashboard_swagger, limit)], responses => #{ diff --git a/apps/emqx_modules/src/emqx_rewrite_api.erl b/apps/emqx_modules/src/emqx_rewrite_api.erl index 534864c74..6590b2cac 100644 --- a/apps/emqx_modules/src/emqx_rewrite_api.erl +++ b/apps/emqx_modules/src/emqx_rewrite_api.erl @@ -17,6 +17,7 @@ -behaviour(minirest_api). -include_lib("typerefl/include/types.hrl"). +-include("emqx_modules.hrl"). -export([api_spec/0, paths/0, schema/1]). @@ -42,7 +43,7 @@ schema("/mqtt/topic_rewrite") -> #{ operationId => topic_rewrite, get => #{ - tags => [mqtt], + tags => ?API_TAG_MQTT, description => <<"List rewrite topic.">>, responses => #{ 200 => hoconsc:mk(hoconsc:array(hoconsc:ref(emqx_modules_schema, "rewrite")), @@ -51,6 +52,7 @@ schema("/mqtt/topic_rewrite") -> }, put => #{ description => <<"Update rewrite topic">>, + tags => ?API_TAG_MQTT, requestBody => hoconsc:mk(hoconsc:array(hoconsc:ref(emqx_modules_schema, "rewrite")),#{}), responses => #{ 200 => hoconsc:mk(hoconsc:array(hoconsc:ref(emqx_modules_schema, "rewrite")), diff --git a/apps/emqx_modules/src/emqx_topic_metrics_api.erl b/apps/emqx_modules/src/emqx_topic_metrics_api.erl index 76419d4af..9fe583ca3 100644 --- a/apps/emqx_modules/src/emqx_topic_metrics_api.erl +++ b/apps/emqx_modules/src/emqx_topic_metrics_api.erl @@ -19,6 +19,7 @@ -behaviour(minirest_api). -include_lib("typerefl/include/types.hrl"). +-include("emqx_modules.hrl"). -import( hoconsc , [ mk/2 @@ -46,9 +47,6 @@ -define(BAD_RPC, 'BAD_RPC'). -define(BAD_REQUEST, 'BAD_REQUEST'). --define(API_TAG_MQTT, [<<"mqtt">>]). - - api_spec() -> emqx_dashboard_swagger:spec(?MODULE, #{check_schema => true}).