style: reformat some modules in emqx_management app

This commit is contained in:
Zaiming (Stone) Shi 2022-04-19 22:26:44 +02:00
parent a0145f4692
commit 628f0bf579
2 changed files with 45 additions and 36 deletions

View File

@ -22,14 +22,14 @@
-include_lib("typerefl/include/types.hrl"). -include_lib("typerefl/include/types.hrl").
%% API %% API
-export([ api_spec/0 -export([
, paths/0 api_spec/0,
, schema/1 paths/0,
, namespace/0 schema/1,
]). namespace/0
]).
-export([ sys/2 -export([sys/2]).
]).
-define(TAGS, [<<"sys">>]). -define(TAGS, [<<"sys">>]).
@ -61,8 +61,8 @@ schema("/mqtt/sys_topics") ->
responses => responses =>
#{ #{
200 => schema_sys_topics() 200 => schema_sys_topics()
} }
}, },
put => put =>
#{ #{
tags => ?TAGS, tags => ?TAGS,
@ -71,20 +71,24 @@ schema("/mqtt/sys_topics") ->
responses => responses =>
#{ #{
200 => schema_sys_topics() 200 => schema_sys_topics()
} }
} }
}. }.
schema_sys_topics() -> schema_sys_topics() ->
emqx_dashboard_swagger:schema_with_example( emqx_dashboard_swagger:schema_with_example(
hoconsc:ref(emqx_schema, "sys_topics"), example_sys_topics()). hoconsc:ref(emqx_schema, "sys_topics"), example_sys_topics()
).
example_sys_topics() -> example_sys_topics() ->
#{<<"sys_event_messages">> => #{
#{<<"client_connected">> => true, <<"sys_event_messages">> =>
<<"client_disconnected">> => true, #{
<<"client_subscribed">> => false, <<"client_connected">> => true,
<<"client_unsubscribed">> => false}, <<"client_disconnected">> => true,
<<"sys_heartbeat_interval">> => <<"30s">>, <<"client_subscribed">> => false,
<<"sys_msg_interval">> => <<"1m">> <<"client_unsubscribed">> => false
}. },
<<"sys_heartbeat_interval">> => <<"30s">>,
<<"sys_msg_interval">> => <<"1m">>
}.

View File

@ -33,22 +33,27 @@ end_per_suite(_) ->
t_get_put(_) -> t_get_put(_) ->
{ok, Default} = get_sys_topics_config(), {ok, Default} = get_sys_topics_config(),
?assertEqual( ?assertEqual(
#{<<"sys_event_messages">> => #{
#{<<"client_connected">> => true, <<"sys_event_messages">> =>
<<"client_disconnected">> => true, #{
<<"client_subscribed">> => false, <<"client_connected">> => true,
<<"client_unsubscribed">> => false <<"client_disconnected">> => true,
}, <<"client_subscribed">> => false,
<<"sys_heartbeat_interval">> => <<"30s">>, <<"client_unsubscribed">> => false
<<"sys_msg_interval">> => <<"1m">>}, Default), },
<<"sys_heartbeat_interval">> => <<"30s">>,
<<"sys_msg_interval">> => <<"1m">>
},
Default
),
NConfig = Default#{ NConfig = Default#{
<<"sys_msg_interval">> => <<"4m">>, <<"sys_msg_interval">> => <<"4m">>,
<<"sys_event_messages">> => #{<<"client_subscribed">> => false} <<"sys_event_messages">> => #{<<"client_subscribed">> => false}
}, },
{ok, ConfigResp} = put_sys_topics_config(NConfig), {ok, ConfigResp} = put_sys_topics_config(NConfig),
?assertEqual(NConfig, ConfigResp), ?assertEqual(NConfig, ConfigResp),
{ok, Default} = put_sys_topics_config(Default). {ok, Default} = put_sys_topics_config(Default).
get_sys_topics_config() -> get_sys_topics_config() ->
Path = emqx_mgmt_api_test_util:api_path(["mqtt", "sys_topics"]), Path = emqx_mgmt_api_test_util:api_path(["mqtt", "sys_topics"]),