From 3f35604d16f7cf006bee942b3c81209fa0b66b88 Mon Sep 17 00:00:00 2001 From: JianBo He Date: Tue, 30 Nov 2021 10:22:27 +0800 Subject: [PATCH] refactor(gw): fix gateway http api schema --- apps/emqx_gateway/src/emqx_gateway_api.erl | 18 ++++++++--- .../test/emqx_gateway_conf_SUITE.erl | 32 +++++++++++-------- 2 files changed, 31 insertions(+), 19 deletions(-) diff --git a/apps/emqx_gateway/src/emqx_gateway_api.erl b/apps/emqx_gateway/src/emqx_gateway_api.erl index 4836950d3..596d42c9a 100644 --- a/apps/emqx_gateway/src/emqx_gateway_api.erl +++ b/apps/emqx_gateway/src/emqx_gateway_api.erl @@ -269,12 +269,18 @@ fields(gateway_listener_overview) -> fields(Gw) when Gw == stomp; Gw == mqttsn; Gw == coap; Gw == lwm2m; Gw == exproto -> - convert_listener_struct(emqx_gateway_schema:fields(Gw)); + [{name, + mk(string(), #{ desc => <<"Gateway Name">>})} + ] ++ convert_listener_struct(emqx_gateway_schema:fields(Gw)); fields(Listener) when Listener == tcp_listener; Listener == ssl_listener; Listener == udp_listener; Listener == dtls_listener -> - [ {type, + [ {id, + mk(string(), + #{ nullable => true + , desc => <<"Listener ID">>})} + , {type, mk(hoconsc:union([tcp, ssl, udp, dtls]), #{ desc => <<"Listener type">>})} , {name, @@ -282,7 +288,8 @@ fields(Listener) when Listener == tcp_listener; #{ desc => <<"Listener Name">>})} , {running, mk(boolean(), - #{ desc => <<"Listener running status">>})} + #{ nullable => true + , desc => <<"Listener running status">>})} ] ++ emqx_gateway_schema:fields(Listener); fields(gateway_stats) -> @@ -292,8 +299,9 @@ schema_gateways_conf() -> %% XXX: We need convert the emqx_gateway_schema's listener map %% structure to array emqx_dashboard_swagger:schema_with_examples( - hoconsc:union([ref(stomp), ref(mqttsn), - ref(coap), ref(lwm2m), ref(exproto)]), + hoconsc:union([ref(?MODULE, stomp), ref(?MODULE, mqttsn), + ref(?MODULE, coap), ref(?MODULE, lwm2m), + ref(?MODULE, exproto)]), examples_gateway_confs() ). diff --git a/apps/emqx_gateway/test/emqx_gateway_conf_SUITE.erl b/apps/emqx_gateway/test/emqx_gateway_conf_SUITE.erl index 810f56e76..916913856 100644 --- a/apps/emqx_gateway/test/emqx_gateway_conf_SUITE.erl +++ b/apps/emqx_gateway/test/emqx_gateway_conf_SUITE.erl @@ -268,12 +268,12 @@ t_load_remove_authn(_) -> ok = emqx_gateway_conf:load_gateway(<<"stomp">>, StompConf), assert_confs(StompConf, emqx:get_raw_config([gateway, stomp])), - ok = emqx_gateway_conf:add_authn(<<"stomp">>, ?CONF_STOMP_AUTHN_1), + {ok, _} = emqx_gateway_conf:add_authn(<<"stomp">>, ?CONF_STOMP_AUTHN_1), assert_confs( maps:put(<<"authentication">>, ?CONF_STOMP_AUTHN_1, StompConf), emqx:get_raw_config([gateway, stomp])), - ok = emqx_gateway_conf:update_authn(<<"stomp">>, ?CONF_STOMP_AUTHN_2), + {ok, _} = emqx_gateway_conf:update_authn(<<"stomp">>, ?CONF_STOMP_AUTHN_2), assert_confs( maps:put(<<"authentication">>, ?CONF_STOMP_AUTHN_2, StompConf), emqx:get_raw_config([gateway, stomp])), @@ -295,14 +295,16 @@ t_load_remove_listeners(_) -> ok = emqx_gateway_conf:load_gateway(<<"stomp">>, StompConf), assert_confs(StompConf, emqx:get_raw_config([gateway, stomp])), - ok = emqx_gateway_conf:add_listener( - <<"stomp">>, {<<"tcp">>, <<"default">>}, ?CONF_STOMP_LISTENER_1), + {ok, _} = emqx_gateway_conf:add_listener( + <<"stomp">>, {<<"tcp">>, <<"default">>}, + ?CONF_STOMP_LISTENER_1), assert_confs( maps:merge(StompConf, listener(?CONF_STOMP_LISTENER_1)), emqx:get_raw_config([gateway, stomp])), - ok = emqx_gateway_conf:update_listener( - <<"stomp">>, {<<"tcp">>, <<"default">>}, ?CONF_STOMP_LISTENER_2), + {ok, _} = emqx_gateway_conf:update_listener( + <<"stomp">>, {<<"tcp">>, <<"default">>}, + ?CONF_STOMP_LISTENER_2), assert_confs( maps:merge(StompConf, listener(?CONF_STOMP_LISTENER_2)), emqx:get_raw_config([gateway, stomp])), @@ -339,12 +341,12 @@ t_load_remove_listener_authn(_) -> ok = emqx_gateway_conf:load_gateway(<<"stomp">>, StompConf), assert_confs(StompConf, emqx:get_raw_config([gateway, stomp])), - ok = emqx_gateway_conf:add_authn( - <<"stomp">>, {<<"tcp">>, <<"default">>}, ?CONF_STOMP_AUTHN_1), + {ok, _} = emqx_gateway_conf:add_authn( + <<"stomp">>, {<<"tcp">>, <<"default">>}, ?CONF_STOMP_AUTHN_1), assert_confs(StompConf1, emqx:get_raw_config([gateway, stomp])), - ok = emqx_gateway_conf:update_authn( - <<"stomp">>, {<<"tcp">>, <<"default">>}, ?CONF_STOMP_AUTHN_2), + {ok, _} = emqx_gateway_conf:update_authn( + <<"stomp">>, {<<"tcp">>, <<"default">>}, ?CONF_STOMP_AUTHN_2), assert_confs(StompConf2, emqx:get_raw_config([gateway, stomp])), ok = emqx_gateway_conf:remove_authn( @@ -403,14 +405,16 @@ t_add_listener_with_certs_content(_) -> ok = emqx_gateway_conf:load_gateway(<<"stomp">>, StompConf), assert_confs(StompConf, emqx:get_raw_config([gateway, stomp])), - ok = emqx_gateway_conf:add_listener( - <<"stomp">>, {<<"ssl">>, <<"default">>}, ?CONF_STOMP_LISTENER_SSL), + {ok, _} = emqx_gateway_conf:add_listener( + <<"stomp">>, {<<"ssl">>, <<"default">>}, + ?CONF_STOMP_LISTENER_SSL), assert_confs( maps:merge(StompConf, ssl_listener(?CONF_STOMP_LISTENER_SSL)), emqx:get_raw_config([gateway, stomp])), - ok = emqx_gateway_conf:update_listener( - <<"stomp">>, {<<"ssl">>, <<"default">>}, ?CONF_STOMP_LISTENER_SSL_2), + {ok, _} = emqx_gateway_conf:update_listener( + <<"stomp">>, {<<"ssl">>, <<"default">>}, + ?CONF_STOMP_LISTENER_SSL_2), assert_confs( maps:merge(StompConf, ssl_listener(?CONF_STOMP_LISTENER_SSL_2)), emqx:get_raw_config([gateway, stomp])),