From fbb8f46fcd6dd82b34e38e81fb6aa46d7ed29c52 Mon Sep 17 00:00:00 2001 From: DDDHuang <44492639+DDDHuang@users.noreply.github.com> Date: Wed, 9 Feb 2022 17:05:06 +0800 Subject: [PATCH] fix(api): qos shcema & code formate --- apps/emqx/src/emqx_schema.erl | 2 +- apps/emqx_dashboard/src/emqx_dashboard.erl | 11 +++++------ apps/emqx_management/src/emqx_mgmt_api_clients.erl | 4 ++-- .../src/emqx_mgmt_api_subscriptions.erl | 7 +++---- 4 files changed, 11 insertions(+), 13 deletions(-) diff --git a/apps/emqx/src/emqx_schema.erl b/apps/emqx/src/emqx_schema.erl index 79703bd4a..ad6d7c9ac 100644 --- a/apps/emqx/src/emqx_schema.erl +++ b/apps/emqx/src/emqx_schema.erl @@ -38,7 +38,7 @@ -type ip_port() :: tuple(). -type cipher() :: map(). -type rfc3339_system_time() :: integer(). --type qos():: integer(). +-type qos() :: integer(). -typerefl_from_string({qos/0, emqx_schema, to_qos}). -typerefl_from_string({duration/0, emqx_schema, to_duration}). diff --git a/apps/emqx_dashboard/src/emqx_dashboard.erl b/apps/emqx_dashboard/src/emqx_dashboard.erl index 777669f2f..37629c16e 100644 --- a/apps/emqx_dashboard/src/emqx_dashboard.erl +++ b/apps/emqx_dashboard/src/emqx_dashboard.erl @@ -92,12 +92,11 @@ stop_listeners() -> %% internal apps() -> - [emqx_management]. - % [App || {App, _, _} <- application:loaded_applications(), - % case re:run(atom_to_list(App), "^emqx") of - % {match,[{0,4}]} -> true; - % _ -> false - % end]. + [App || {App, _, _} <- application:loaded_applications(), + case re:run(atom_to_list(App), "^emqx") of + {match,[{0,4}]} -> true; + _ -> false + end]. listeners() -> [begin diff --git a/apps/emqx_management/src/emqx_mgmt_api_clients.erl b/apps/emqx_management/src/emqx_mgmt_api_clients.erl index 91d5b8b0c..4febd888c 100644 --- a/apps/emqx_management/src/emqx_mgmt_api_clients.erl +++ b/apps/emqx_management/src/emqx_mgmt_api_clients.erl @@ -233,7 +233,7 @@ schema("/clients/:clientid/subscribe") -> parameters => [{clientid, hoconsc:mk(binary(), #{in => path})}], 'requestBody' => hoconsc:mk(hoconsc:ref(?MODULE, subscribe)), responses => #{ - % 200 => hoconsc:ref(emqx_mgmt_api_subscriptions, subscription), + 200 => hoconsc:ref(emqx_mgmt_api_subscriptions, subscription), 404 => emqx_dashboard_swagger:error_codes( ['CLIENTID_NOT_FOUND'], <<"Client id not found">>) } @@ -369,7 +369,7 @@ fields(keepalive) -> fields(subscribe) -> [ {topic, hoconsc:mk(binary(), #{desc => <<"Access type">>})}, - {qos, hoconsc:mk(integer(), #{desc => <<"Update time">>})} + {qos, hoconsc:mk(emqx_schema:qos(), #{desc => <<"QoS">>})} ]; fields(unsubscribe) -> diff --git a/apps/emqx_management/src/emqx_mgmt_api_subscriptions.erl b/apps/emqx_management/src/emqx_mgmt_api_subscriptions.erl index 0a7011a07..40e3948a7 100644 --- a/apps/emqx_management/src/emqx_mgmt_api_subscriptions.erl +++ b/apps/emqx_management/src/emqx_mgmt_api_subscriptions.erl @@ -65,7 +65,7 @@ fields(subscription) -> {node, hoconsc:mk(binary(), #{desc => <<"Access type">>})}, {topic, hoconsc:mk(binary(), #{desc => <<"Topic name">>})}, {clientid, hoconsc:mk(binary(), #{desc => <<"Client identifier">>})}, - {qos, hoconsc:mk(hoconsc:enum([?QOS_0, ?QOS_1, ?QOS_2]), #{desc => <<"QoS">>})} + {qos, hoconsc:mk(emqx_schema:qos(), #{desc => <<"QoS">>})} ]. parameters() -> @@ -86,11 +86,10 @@ parameters() -> desc => <<"Client ID">>}) }, { - qos, hoconsc:mk(hoconsc:union( - [typerefl:integer(0), typerefl:integer(1), typerefl:integer(2)]), #{ + qos, hoconsc:mk(emqx_schema:qos(), #{ in => query, nullable => true, - desc => "QoS"}) + desc => <<"QoS">>}) }, { topic, hoconsc:mk(binary(), #{