refactor(api): swagger api tag `mqtt`

This commit is contained in:
JimMoen 2022-01-21 17:26:54 +08:00
parent 8ac63f823d
commit 1a0862913e
4 changed files with 28 additions and 9 deletions

View File

@ -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 %% The destination URL for the telemetry data report
-define(TELEMETRY_URL, "https://telemetry.emqx.io/api/telemetry"). -define(TELEMETRY_URL, "https://telemetry.emqx.io/api/telemetry").
%% Interval for reporting telemetry data, Default: 7d %% Interval for reporting telemetry data, Default: 7d
-define(REPORT_INTERVAR, 604800). -define(REPORT_INTERVAR, 604800).
-define(API_TAG_MQTT, [<<"mqtt">>]).

View File

@ -19,6 +19,7 @@
-behaviour(minirest_api). -behaviour(minirest_api).
-include_lib("typerefl/include/types.hrl"). -include_lib("typerefl/include/types.hrl").
-include("emqx_modules.hrl").
-import(hoconsc, [mk/2, ref/1, ref/2]). -import(hoconsc, [mk/2, ref/1, ref/2]).
@ -62,7 +63,7 @@ schema("/mqtt/delayed") ->
#{ #{
'operationId' => status, 'operationId' => status,
get => #{ get => #{
tags => [<<"mqtt">>], tags => ?API_TAG_MQTT,
description => <<"Get delayed status">>, description => <<"Get delayed status">>,
summary => <<"Get delayed status">>, summary => <<"Get delayed status">>,
responses => #{ responses => #{
@ -70,7 +71,7 @@ schema("/mqtt/delayed") ->
} }
}, },
put => #{ put => #{
tags => [<<"mqtt">>], tags => ?API_TAG_MQTT,
description => <<"Enable or disable delayed, set max delayed messages">>, description => <<"Enable or disable delayed, set max delayed messages">>,
'requestBody' => ref(emqx_modules_schema, "delayed"), 'requestBody' => ref(emqx_modules_schema, "delayed"),
responses => #{ responses => #{
@ -85,7 +86,7 @@ schema("/mqtt/delayed") ->
schema("/mqtt/delayed/messages/:msgid") -> schema("/mqtt/delayed/messages/:msgid") ->
#{'operationId' => delayed_message, #{'operationId' => delayed_message,
get => #{ get => #{
tags => [<<"mqtt">>], tags => ?API_TAG_MQTT,
description => <<"Get delayed message">>, description => <<"Get delayed message">>,
parameters => [{msgid, mk(binary(), #{in => path, desc => <<"delay message ID">>})}], parameters => [{msgid, mk(binary(), #{in => path, desc => <<"delay message ID">>})}],
responses => #{ responses => #{
@ -97,7 +98,7 @@ schema("/mqtt/delayed/messages/:msgid") ->
} }
}, },
delete => #{ delete => #{
tags => [<<"mqtt">>], tags => ?API_TAG_MQTT,
description => <<"Delete delayed message">>, description => <<"Delete delayed message">>,
parameters => [{msgid, mk(binary(), #{in => path, desc => <<"delay message ID">>})}], parameters => [{msgid, mk(binary(), #{in => path, desc => <<"delay message ID">>})}],
responses => #{ responses => #{
@ -113,7 +114,7 @@ schema("/mqtt/delayed/messages") ->
#{ #{
'operationId' => delayed_messages, 'operationId' => delayed_messages,
get => #{ get => #{
tags => [<<"mqtt">>], tags => ?API_TAG_MQTT,
description => <<"List delayed messages">>, description => <<"List delayed messages">>,
parameters => [ref(emqx_dashboard_swagger, page), ref(emqx_dashboard_swagger, limit)], parameters => [ref(emqx_dashboard_swagger, page), ref(emqx_dashboard_swagger, limit)],
responses => #{ responses => #{

View File

@ -17,6 +17,7 @@
-behaviour(minirest_api). -behaviour(minirest_api).
-include_lib("typerefl/include/types.hrl"). -include_lib("typerefl/include/types.hrl").
-include("emqx_modules.hrl").
-export([api_spec/0, paths/0, schema/1]). -export([api_spec/0, paths/0, schema/1]).
@ -42,7 +43,7 @@ schema("/mqtt/topic_rewrite") ->
#{ #{
operationId => topic_rewrite, operationId => topic_rewrite,
get => #{ get => #{
tags => [mqtt], tags => ?API_TAG_MQTT,
description => <<"List rewrite topic.">>, description => <<"List rewrite topic.">>,
responses => #{ responses => #{
200 => hoconsc:mk(hoconsc:array(hoconsc:ref(emqx_modules_schema, "rewrite")), 200 => hoconsc:mk(hoconsc:array(hoconsc:ref(emqx_modules_schema, "rewrite")),
@ -51,6 +52,7 @@ schema("/mqtt/topic_rewrite") ->
}, },
put => #{ put => #{
description => <<"Update rewrite topic">>, description => <<"Update rewrite topic">>,
tags => ?API_TAG_MQTT,
requestBody => hoconsc:mk(hoconsc:array(hoconsc:ref(emqx_modules_schema, "rewrite")),#{}), requestBody => hoconsc:mk(hoconsc:array(hoconsc:ref(emqx_modules_schema, "rewrite")),#{}),
responses => #{ responses => #{
200 => hoconsc:mk(hoconsc:array(hoconsc:ref(emqx_modules_schema, "rewrite")), 200 => hoconsc:mk(hoconsc:array(hoconsc:ref(emqx_modules_schema, "rewrite")),

View File

@ -19,6 +19,7 @@
-behaviour(minirest_api). -behaviour(minirest_api).
-include_lib("typerefl/include/types.hrl"). -include_lib("typerefl/include/types.hrl").
-include("emqx_modules.hrl").
-import( hoconsc -import( hoconsc
, [ mk/2 , [ mk/2
@ -46,9 +47,6 @@
-define(BAD_RPC, 'BAD_RPC'). -define(BAD_RPC, 'BAD_RPC').
-define(BAD_REQUEST, 'BAD_REQUEST'). -define(BAD_REQUEST, 'BAD_REQUEST').
-define(API_TAG_MQTT, [<<"mqtt">>]).
api_spec() -> api_spec() ->
emqx_dashboard_swagger:spec(?MODULE, #{check_schema => true}). emqx_dashboard_swagger:spec(?MODULE, #{check_schema => true}).