refactor(gw): fix gateway http api schema

This commit is contained in:
JianBo He 2021-11-30 10:22:27 +08:00
parent f3f3f12635
commit 3f35604d16
2 changed files with 31 additions and 19 deletions

View File

@ -269,12 +269,18 @@ fields(gateway_listener_overview) ->
fields(Gw) when Gw == stomp; Gw == mqttsn; fields(Gw) when Gw == stomp; Gw == mqttsn;
Gw == coap; Gw == lwm2m; Gw == coap; Gw == lwm2m;
Gw == exproto -> 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; fields(Listener) when Listener == tcp_listener;
Listener == ssl_listener; Listener == ssl_listener;
Listener == udp_listener; Listener == udp_listener;
Listener == dtls_listener -> Listener == dtls_listener ->
[ {type, [ {id,
mk(string(),
#{ nullable => true
, desc => <<"Listener ID">>})}
, {type,
mk(hoconsc:union([tcp, ssl, udp, dtls]), mk(hoconsc:union([tcp, ssl, udp, dtls]),
#{ desc => <<"Listener type">>})} #{ desc => <<"Listener type">>})}
, {name, , {name,
@ -282,7 +288,8 @@ fields(Listener) when Listener == tcp_listener;
#{ desc => <<"Listener Name">>})} #{ desc => <<"Listener Name">>})}
, {running, , {running,
mk(boolean(), mk(boolean(),
#{ desc => <<"Listener running status">>})} #{ nullable => true
, desc => <<"Listener running status">>})}
] ++ emqx_gateway_schema:fields(Listener); ] ++ emqx_gateway_schema:fields(Listener);
fields(gateway_stats) -> fields(gateway_stats) ->
@ -292,8 +299,9 @@ schema_gateways_conf() ->
%% XXX: We need convert the emqx_gateway_schema's listener map %% XXX: We need convert the emqx_gateway_schema's listener map
%% structure to array %% structure to array
emqx_dashboard_swagger:schema_with_examples( emqx_dashboard_swagger:schema_with_examples(
hoconsc:union([ref(stomp), ref(mqttsn), hoconsc:union([ref(?MODULE, stomp), ref(?MODULE, mqttsn),
ref(coap), ref(lwm2m), ref(exproto)]), ref(?MODULE, coap), ref(?MODULE, lwm2m),
ref(?MODULE, exproto)]),
examples_gateway_confs() examples_gateway_confs()
). ).

View File

@ -268,12 +268,12 @@ t_load_remove_authn(_) ->
ok = emqx_gateway_conf:load_gateway(<<"stomp">>, StompConf), ok = emqx_gateway_conf:load_gateway(<<"stomp">>, StompConf),
assert_confs(StompConf, emqx:get_raw_config([gateway, stomp])), 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( assert_confs(
maps:put(<<"authentication">>, ?CONF_STOMP_AUTHN_1, StompConf), maps:put(<<"authentication">>, ?CONF_STOMP_AUTHN_1, StompConf),
emqx:get_raw_config([gateway, stomp])), 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( assert_confs(
maps:put(<<"authentication">>, ?CONF_STOMP_AUTHN_2, StompConf), maps:put(<<"authentication">>, ?CONF_STOMP_AUTHN_2, StompConf),
emqx:get_raw_config([gateway, stomp])), emqx:get_raw_config([gateway, stomp])),
@ -295,14 +295,16 @@ t_load_remove_listeners(_) ->
ok = emqx_gateway_conf:load_gateway(<<"stomp">>, StompConf), ok = emqx_gateway_conf:load_gateway(<<"stomp">>, StompConf),
assert_confs(StompConf, emqx:get_raw_config([gateway, stomp])), assert_confs(StompConf, emqx:get_raw_config([gateway, stomp])),
ok = emqx_gateway_conf:add_listener( {ok, _} = emqx_gateway_conf:add_listener(
<<"stomp">>, {<<"tcp">>, <<"default">>}, ?CONF_STOMP_LISTENER_1), <<"stomp">>, {<<"tcp">>, <<"default">>},
?CONF_STOMP_LISTENER_1),
assert_confs( assert_confs(
maps:merge(StompConf, listener(?CONF_STOMP_LISTENER_1)), maps:merge(StompConf, listener(?CONF_STOMP_LISTENER_1)),
emqx:get_raw_config([gateway, stomp])), emqx:get_raw_config([gateway, stomp])),
ok = emqx_gateway_conf:update_listener( {ok, _} = emqx_gateway_conf:update_listener(
<<"stomp">>, {<<"tcp">>, <<"default">>}, ?CONF_STOMP_LISTENER_2), <<"stomp">>, {<<"tcp">>, <<"default">>},
?CONF_STOMP_LISTENER_2),
assert_confs( assert_confs(
maps:merge(StompConf, listener(?CONF_STOMP_LISTENER_2)), maps:merge(StompConf, listener(?CONF_STOMP_LISTENER_2)),
emqx:get_raw_config([gateway, stomp])), emqx:get_raw_config([gateway, stomp])),
@ -339,12 +341,12 @@ t_load_remove_listener_authn(_) ->
ok = emqx_gateway_conf:load_gateway(<<"stomp">>, StompConf), ok = emqx_gateway_conf:load_gateway(<<"stomp">>, StompConf),
assert_confs(StompConf, emqx:get_raw_config([gateway, stomp])), assert_confs(StompConf, emqx:get_raw_config([gateway, stomp])),
ok = emqx_gateway_conf:add_authn( {ok, _} = emqx_gateway_conf:add_authn(
<<"stomp">>, {<<"tcp">>, <<"default">>}, ?CONF_STOMP_AUTHN_1), <<"stomp">>, {<<"tcp">>, <<"default">>}, ?CONF_STOMP_AUTHN_1),
assert_confs(StompConf1, emqx:get_raw_config([gateway, stomp])), assert_confs(StompConf1, emqx:get_raw_config([gateway, stomp])),
ok = emqx_gateway_conf:update_authn( {ok, _} = emqx_gateway_conf:update_authn(
<<"stomp">>, {<<"tcp">>, <<"default">>}, ?CONF_STOMP_AUTHN_2), <<"stomp">>, {<<"tcp">>, <<"default">>}, ?CONF_STOMP_AUTHN_2),
assert_confs(StompConf2, emqx:get_raw_config([gateway, stomp])), assert_confs(StompConf2, emqx:get_raw_config([gateway, stomp])),
ok = emqx_gateway_conf:remove_authn( ok = emqx_gateway_conf:remove_authn(
@ -403,14 +405,16 @@ t_add_listener_with_certs_content(_) ->
ok = emqx_gateway_conf:load_gateway(<<"stomp">>, StompConf), ok = emqx_gateway_conf:load_gateway(<<"stomp">>, StompConf),
assert_confs(StompConf, emqx:get_raw_config([gateway, stomp])), assert_confs(StompConf, emqx:get_raw_config([gateway, stomp])),
ok = emqx_gateway_conf:add_listener( {ok, _} = emqx_gateway_conf:add_listener(
<<"stomp">>, {<<"ssl">>, <<"default">>}, ?CONF_STOMP_LISTENER_SSL), <<"stomp">>, {<<"ssl">>, <<"default">>},
?CONF_STOMP_LISTENER_SSL),
assert_confs( assert_confs(
maps:merge(StompConf, ssl_listener(?CONF_STOMP_LISTENER_SSL)), maps:merge(StompConf, ssl_listener(?CONF_STOMP_LISTENER_SSL)),
emqx:get_raw_config([gateway, stomp])), emqx:get_raw_config([gateway, stomp])),
ok = emqx_gateway_conf:update_listener( {ok, _} = emqx_gateway_conf:update_listener(
<<"stomp">>, {<<"ssl">>, <<"default">>}, ?CONF_STOMP_LISTENER_SSL_2), <<"stomp">>, {<<"ssl">>, <<"default">>},
?CONF_STOMP_LISTENER_SSL_2),
assert_confs( assert_confs(
maps:merge(StompConf, ssl_listener(?CONF_STOMP_LISTENER_SSL_2)), maps:merge(StompConf, ssl_listener(?CONF_STOMP_LISTENER_SSL_2)),
emqx:get_raw_config([gateway, stomp])), emqx:get_raw_config([gateway, stomp])),