fix(api): desc & remove useless api

This commit is contained in:
DDDHuang 2022-03-21 14:12:02 +08:00
parent 010dbbdb26
commit e517b41a4d
13 changed files with 242 additions and 252 deletions

View File

@ -117,7 +117,7 @@ param_path_id() ->
[{id, mk(binary(),
#{ in => path
, example => <<"mqtt:my_mqtt_connector">>
, description => <<"The connector Id. Must be of format {type}:{name}">>
, desc => <<"The connector Id. Must be of format {type}:{name}">>
})}].
schema("/connectors_test") ->
@ -125,7 +125,7 @@ schema("/connectors_test") ->
'operationId' => '/connectors_test',
post => #{
tags => [<<"connectors">>],
description => <<"Test creating a new connector by given Id <br>"
desc => <<"Test creating a new connector by given Id <br>"
"The ID must be of format '{type}:{name}'">>,
summary => <<"Test creating connector">>,
'requestBody' => post_request_body_schema(),
@ -141,7 +141,7 @@ schema("/connectors") ->
'operationId' => '/connectors',
get => #{
tags => [<<"connectors">>],
description => <<"List all connectors">>,
desc => <<"List all connectors">>,
summary => <<"List connectors">>,
responses => #{
200 => emqx_dashboard_swagger:schema_with_example(
@ -151,7 +151,7 @@ schema("/connectors") ->
},
post => #{
tags => [<<"connectors">>],
description => <<"Create a new connector">>,
desc => <<"Create a new connector">>,
summary => <<"Create connector">>,
'requestBody' => post_request_body_schema(),
responses => #{
@ -166,7 +166,7 @@ schema("/connectors/:id") ->
'operationId' => '/connectors/:id',
get => #{
tags => [<<"connectors">>],
description => <<"Get the connector by Id">>,
desc => <<"Get the connector by Id">>,
summary => <<"Get connector">>,
parameters => param_path_id(),
responses => #{
@ -177,7 +177,7 @@ schema("/connectors/:id") ->
},
put => #{
tags => [<<"connectors">>],
description => <<"Update an existing connector by Id">>,
desc => <<"Update an existing connector by Id">>,
summary => <<"Update connector">>,
parameters => param_path_id(),
'requestBody' => put_request_body_schema(),
@ -188,7 +188,7 @@ schema("/connectors/:id") ->
}},
delete => #{
tags => [<<"connectors">>],
description => <<"Delete a connector by Id">>,
desc => <<"Delete a connector by Id">>,
summary => <<"Delete connector">>,
parameters => param_path_id(),
responses => #{

View File

@ -48,22 +48,22 @@ schema("/login") ->
'operationId' => login,
post => #{
tags => [<<"dashboard">>],
description => <<"Dashboard Auth">>,
desc => <<"Dashboard Auth">>,
summary => <<"Dashboard Auth">>,
'requestBody' => [
{username, mk(binary(),
#{description => <<"The User for which to create the token.">>,
#{desc => <<"The User for which to create the token.">>,
'maxLength' => 100, example => <<"admin">>})},
{password, mk(binary(),
#{description => "password", example => "public"})}
#{desc => "password", example => "public"})}
],
responses => #{
200 => [
{token, mk(string(), #{description => <<"JWT Token">>})},
{token, mk(string(), #{desc => <<"JWT Token">>})},
{license, [{edition,
mk(enum([community, enterprise]), #{description => <<"license">>,
mk(enum([community, enterprise]), #{desc => <<"license">>,
example => "community"})}]},
{version, mk(string(), #{description => <<"version">>, example => <<"5.0.0">>})}
{version, mk(string(), #{desc => <<"version">>, example => <<"5.0.0">>})}
],
401 => [
{code, mk(string(), #{example => 'ERROR_USERNAME_OR_PWD'})},
@ -77,10 +77,10 @@ schema("/logout") ->
'operationId' => logout,
post => #{
tags => [<<"dashboard">>],
description => <<"Dashboard User logout">>,
desc => <<"Dashboard User logout">>,
'requestBody' => [
{username, mk(binary(),
#{description => <<"The User for which to create the token.">>,
#{desc => <<"The User for which to create the token.">>,
'maxLength' => 100, example => <<"admin">>})}
],
responses => #{
@ -93,19 +93,19 @@ schema("/users") ->
'operationId' => users,
get => #{
tags => [<<"dashboard">>],
description => <<"Get dashboard users list">>,
desc => <<"Get dashboard users list">>,
responses => #{
200 => mk( array(ref(?MODULE, user))
, #{description => "User lists"})
, #{desc => "User lists"})
}
},
post => #{
tags => [<<"dashboard">>],
description => <<"Create dashboard users">>,
desc => <<"Create dashboard users">>,
'requestBody' => fields(user_password),
responses => #{
200 => mk( ref(?MODULE, user)
, #{description => <<"Create User successfully">>}),
, #{desc => <<"Create User successfully">>}),
400 => [{code, mk(string(), #{example => 'CREATE_FAIL'})},
{message, mk(string(), #{example => "Create user failed"})}
]
@ -118,17 +118,17 @@ schema("/users/:username") ->
'operationId' => user,
put => #{
tags => [<<"dashboard">>],
description => <<"Update dashboard users">>,
desc => <<"Update dashboard users">>,
parameters => [{username, mk(binary(),
#{in => path, example => <<"admin">>})}],
'requestBody' => [
{ description
, mk(binary(),
#{description => <<"User description">>, example => <<"administrator">>})}
#{desc => <<"User description">>, example => <<"administrator">>})}
],
responses => #{
200 => mk( ref(?MODULE, user)
, #{description => <<"Update User successfully">>}),
, #{desc => <<"Update User successfully">>}),
400 => [
{code, mk(string(), #{example => 'UPDATE_FAIL'})},
{message, mk(string(), #{example => "Update Failed unknown"})}
@ -138,7 +138,7 @@ schema("/users/:username") ->
},
delete => #{
tags => [<<"dashboard">>],
description => <<"Delete dashboard users">>,
desc => <<"Delete dashboard users">>,
parameters => [{username, mk(binary(),
#{in => path, example => <<"admin">>})}],
responses => #{
@ -156,7 +156,7 @@ schema("/users/:username/change_pwd") ->
'operationId' => change_pwd,
put => #{
tags => [<<"dashboard">>],
description => <<"Update dashboard users password">>,
desc => <<"Update dashboard users password">>,
parameters => [{username, mk(binary(),
#{in => path, required => true, example => <<"admin">>})}],
'requestBody' => [
@ -177,14 +177,14 @@ fields(user) ->
[
{description,
mk(binary(),
#{description => <<"User description">>, example => "administrator"})},
#{desc => <<"User description">>, example => "administrator"})},
{username,
mk(binary(),
#{description => <<"username">>, example => "emqx"})}
#{desc => <<"username">>, example => "emqx"})}
];
fields(user_password) ->
fields(user) ++
[{password, mk(binary(), #{description => "Password", example => <<"public">>})}].
[{password, mk(binary(), #{desc => "Password", example => <<"public">>})}].
login(post, #{body := Params}) ->
Username = maps:get(<<"username">>, Params),

View File

@ -35,7 +35,7 @@ schema("/monitor") ->
'operationId' => monitor,
get => #{
tags => [dashboard],
description => <<"List monitor data.">>,
desc => <<"List monitor data.">>,
parameters => [parameter_latest()],
responses => #{
200 => hoconsc:mk(hoconsc:array(hoconsc:ref(sampler)), #{}),
@ -49,7 +49,7 @@ schema("/monitor/nodes/:node") ->
'operationId' => monitor,
get => #{
tags => [dashboard],
description => <<"List the monitor data on the node.">>,
desc => <<"List the monitor data on the node.">>,
parameters => [parameter_node(), parameter_latest()],
responses => #{
200 => hoconsc:mk(hoconsc:array(hoconsc:ref(sampler)), #{}),
@ -63,7 +63,7 @@ schema("/monitor_current") ->
'operationId' => monitor_current,
get => #{
tags => [dashboard],
description => <<"Current status. Gauge and rate.">>,
desc => <<"Current status. Gauge and rate.">>,
responses => #{
200 => hoconsc:mk(hoconsc:ref(sampler_current), #{})
}
@ -75,7 +75,7 @@ schema("/monitor_current/nodes/:node") ->
'operationId' => monitor_current,
get => #{
tags => [dashboard],
description => <<"Node current status. Gauge and rate.">>,
desc => <<"Node current status. Gauge and rate.">>,
parameters => [parameter_node()],
responses => #{
200 => hoconsc:mk(hoconsc:ref(sampler_current), #{}),
@ -89,7 +89,7 @@ parameter_latest() ->
in => query,
required => false,
example => 5 * 60,
description => <<"The latest N seconds data. Like 300 for 5 min.">>
desc => <<"The latest N seconds data. Like 300 for 5 min.">>
},
{latest, hoconsc:mk(range(1, inf), Info)}.
@ -98,19 +98,19 @@ parameter_node() ->
in => path,
required => true,
example => node(),
description => <<"EMQX node name.">>
desc => <<"EMQX node name.">>
},
{node, hoconsc:mk(binary(), Info)}.
fields(sampler) ->
Samplers =
[{SamplerName, hoconsc:mk(integer(), #{description => swagger_desc(SamplerName)})}
[{SamplerName, hoconsc:mk(integer(), #{desc => swagger_desc(SamplerName)})}
|| SamplerName <- ?SAMPLER_LIST],
[{time_stamp, hoconsc:mk(integer(), #{description => <<"Timestamp">>})} | Samplers];
[{time_stamp, hoconsc:mk(integer(), #{desc => <<"Timestamp">>})} | Samplers];
fields(sampler_current) ->
[{SamplerName, hoconsc:mk(integer(), #{description => swagger_desc(SamplerName)})}
[{SamplerName, hoconsc:mk(integer(), #{desc => swagger_desc(SamplerName)})}
|| SamplerName <- maps:values(?DELTA_SAMPLER_RATE_MAP) ++ ?GAUGE_SAMPLER_LIST].
%% -------------------------------------------------------------------------------------------------

View File

@ -95,12 +95,12 @@ namespace() -> "public".
-spec(fields(hocon_schema:name()) -> hocon_schema:fields()).
fields(page) ->
Desc = <<"Page number of the results to fetch.">>,
Meta = #{in => query, description => Desc, default => 1, example => 1},
Meta = #{in => query, desc => Desc, default => 1, example => 1},
[{page, hoconsc:mk(integer(), Meta)}];
fields(limit) ->
Desc = iolist_to_binary([<<"Results per page(max ">>,
integer_to_binary(?MAX_ROW_LIMIT), <<")">>]),
Meta = #{in => query, description => Desc, default => ?DEFAULT_ROW, example => 50},
Meta = #{in => query, desc => Desc, default => ?DEFAULT_ROW, example => 50},
[{limit, hoconsc:mk(range(1, ?MAX_ROW_LIMIT), Meta)}].
-spec(schema_with_example(hocon_schema:type(), term()) -> hocon_schema:field_schema_map()).
@ -120,7 +120,7 @@ error_codes(Codes = [_ | _], MsgExample) ->
[
{code, hoconsc:mk(hoconsc:enum(Codes))},
{message, hoconsc:mk(string(), #{
description => <<"Details description of the error.">>,
desc => <<"Details description of the error.">>,
example => MsgExample
})}
].
@ -247,7 +247,7 @@ meta_to_spec(Meta, Module, Options) ->
{RequestBody, Refs2} = request_body(maps:get('requestBody', Meta, []), Module),
{Responses, Refs3} = responses(maps:get(responses, Meta, #{}), Module, Options),
{
to_spec(Meta, Params, RequestBody, Responses),
generate_method_desc(to_spec(Meta, Params, RequestBody, Responses)),
lists:usort(Refs1 ++ Refs2 ++ Refs3)
}.
@ -258,6 +258,14 @@ to_spec(Meta, Params, RequestBody, Responses) ->
Spec = to_spec(Meta, Params, [], Responses),
maps:put('requestBody', RequestBody, Spec).
generate_method_desc(Spec0 = #{desc := Desc}) ->
Spec = maps:remove(desc, Spec0),
Spec#{description => to_bin(Desc)};
generate_method_desc(Spec = #{description := Desc}) ->
Spec#{description => to_bin(Desc)};
generate_method_desc(Spec) ->
Spec.
parameters(Params, Module) ->
{SpecList, AllRefs} =
lists:foldl(fun(Param, {Acc, RefsAcc}) ->
@ -298,7 +306,7 @@ trans_required(Spec, _, path) -> Spec#{required => true};
trans_required(Spec, _, _) -> Spec.
trans_desc(Init, Hocon, Func, Name) ->
Spec0 = trans_desc(Init, Hocon),
Spec0 = trans_desc(Init, Hocon),
case Func =:= fun hocon_schema_to_spec/2 of
true -> Spec0;
false ->

View File

@ -273,7 +273,7 @@ schema("/test/in/:filter") ->
{filter,
mk(hoconsc:enum([assigned, created, mentioned, all]),
#{in => path,
description => <<"Indicates which sorts of issues to return">>,
desc => <<"Indicates which sorts of issues to return">>,
example => "all"
})}
],
@ -288,9 +288,9 @@ schema("/test/in/query") ->
{per_page,
mk(range(1, 100),
#{in => query,
description => <<"results per page (max 100)">>,
desc => <<"results per page (max 100)">>,
example => 1})},
{qos, mk(emqx_schema:qos(), #{in => query, description => <<"QOS">>})}
{qos, mk(emqx_schema:qos(), #{in => query, desc => <<"QOS">>})}
],
responses => #{200 => <<"ok">>}
}
@ -327,17 +327,17 @@ schema("/test/in/mix/:state") ->
operationId => test,
post => #{
tags => [tags, good],
description => <<"good description">>,
desc => <<"good description">>,
summary => <<"good summary">>,
security => [],
deprecated => true,
parameters => [
{filter, hoconsc:mk(hoconsc:enum([assigned, created, mentioned, all]),
#{in => query, description => <<"Indicates which sorts of issues to return">>,
#{in => query, desc => <<"Indicates which sorts of issues to return">>,
example => "all"})},
{state, mk(emqx_schema:duration_s(),
#{in => path, required => true, example => "12m",
description => <<"Indicates the state of the issues to return.">>})},
desc => <<"Indicates the state of the issues to return.">>})},
{per_page, mk(range(1, 50),
#{in => query, required => false, example => 10, default => 5})},
{is_admin, mk(boolean(), #{in => query})},
@ -373,7 +373,7 @@ fields(page) ->
[
{per_page,
mk(range(1, 100),
#{in => query, description => <<"results per page (max 100)">>, example => 1})}
#{in => query, desc => <<"results per page (max 100)">>, example => 1})}
].
to_schema(Params) ->
#{

View File

@ -52,11 +52,11 @@ schema(("/exhooks")) ->
#{
'operationId' => exhooks,
get => #{tags => ?TAGS,
description => <<"List all servers">>,
desc => <<"List all servers">>,
responses => #{200 => mk(array(ref(detail_server_info)), #{})}
},
post => #{tags => ?TAGS,
description => <<"Add a servers">>,
desc => <<"Add a servers">>,
'requestBody' => server_conf_schema(),
responses => #{201 => mk(ref(detail_server_info), #{}),
500 => error_codes([?BAD_RPC], <<"Bad RPC">>)
@ -67,14 +67,14 @@ schema(("/exhooks")) ->
schema("/exhooks/:name") ->
#{'operationId' => action_with_name,
get => #{tags => ?TAGS,
description => <<"Get the detail information of server">>,
desc => <<"Get the detail information of server">>,
parameters => params_server_name_in_path(),
responses => #{200 => mk(ref(detail_server_info), #{}),
400 => error_codes([?BAD_REQUEST], <<"Bad Request">>)
}
},
put => #{tags => ?TAGS,
description => <<"Update the server">>,
desc => <<"Update the server">>,
parameters => params_server_name_in_path(),
'requestBody' => server_conf_schema(),
responses => #{200 => <<>>,
@ -83,7 +83,7 @@ schema("/exhooks/:name") ->
}
},
delete => #{tags => ?TAGS,
description => <<"Delete the server">>,
desc => <<"Delete the server">>,
parameters => params_server_name_in_path(),
responses => #{204 => <<>>,
500 => error_codes([?BAD_RPC], <<"Bad RPC">>)
@ -94,7 +94,7 @@ schema("/exhooks/:name") ->
schema("/exhooks/:name/hooks") ->
#{'operationId' => server_hooks,
get => #{tags => ?TAGS,
description => <<"Get the hooks information of server">>,
desc => <<"Get the hooks information of server">>,
parameters => params_server_name_in_path(),
responses => #{200 => mk(array(ref(list_hook_info)), #{}),
400 => error_codes([?BAD_REQUEST], <<"Bad Request">>)
@ -105,7 +105,7 @@ schema("/exhooks/:name/hooks") ->
schema("/exhooks/:name/move") ->
#{'operationId' => move,
post => #{tags => ?TAGS,
description =>
desc =>
<<"Move the server.\n",
"NOTE: The position should be \"front|rear|before:{name}|after:{name}\"\n">>,
parameters => params_server_name_in_path(),
@ -120,7 +120,7 @@ schema("/exhooks/:name/move") ->
}.
fields(move_req) ->
[{position, mk(string(), #{ description => <<"The target position to be moved.">>
[{position, mk(string(), #{ desc => <<"The target position to be moved.">>
, example => <<"front">>})}];
fields(detail_server_info) ->
@ -131,9 +131,9 @@ fields(detail_server_info) ->
] ++ emqx_exhook_schema:server_config();
fields(list_hook_info) ->
[ {name, mk(binary(), #{description => <<"The hook's name">>})}
[ {name, mk(binary(), #{desc => <<"The hook's name">>})}
, {params, mk(map(name, binary()),
#{description => <<"The parameters used when the hook is registered">>})}
#{desc => <<"The parameters used when the hook is registered">>})}
, {metrics, mk(ref(metrics), #{})}
, {node_metrics, mk(array(ref(node_metrics)), #{})}
];
@ -149,9 +149,9 @@ fields(node_status) ->
];
fields(hook_info) ->
[ {name, mk(binary(), #{description => <<"The hook's name">>})}
[ {name, mk(binary(), #{desc => <<"The hook's name">>})}
, {params, mk(map(name, binary()),
#{description => <<"The parameters used when the hook is registered">>})}
#{desc => <<"The parameters used when the hook is registered">>})}
];
fields(metrics) ->

View File

@ -46,7 +46,7 @@ paths() ->
schema(?PREFIX ++ "/request") ->
#{operationId => request,
post => #{ tags => [<<"gateway|coap">>]
, description => <<"Send a CoAP request message to the client">>
, desc => <<"Send a CoAP request message to the client">>
, parameters => request_parameters()
, requestBody => request_body()
, responses => #{200 => coap_message(),
@ -87,19 +87,19 @@ request_parameters() ->
[{clientid, mk(binary(), #{in => path, required => true})}].
request_body() ->
[ {token, mk(binary(), #{description => "message token, can be empty"})}
, {method, mk(enum([get, put, post, delete]), #{description => "request method type"})}
, {timeout, mk(emqx_schema:duration_ms(), #{description => "timespan for response"})}
[ {token, mk(binary(), #{desc => "message token, can be empty"})}
, {method, mk(enum([get, put, post, delete]), #{desc => "request method type"})}
, {timeout, mk(emqx_schema:duration_ms(), #{desc => "timespan for response"})}
, {content_type, mk(enum(['text/plain', 'application/json', 'application/octet-stream']),
#{description => "payload type"})}
, {payload, mk(binary(), #{description => "the content of the payload"})}
#{desc => "payload type"})}
, {payload, mk(binary(), #{desc => "the content of the payload"})}
].
coap_message() ->
[ {id, mk(integer(), #{description => "message id"})}
, {token, mk(string(), #{description => "message token, can be empty"})}
, {method, mk(string(), #{description => "response code"})}
, {payload, mk(string(), #{description => "payload"})}
[ {id, mk(integer(), #{desc => "message id"})}
, {token, mk(string(), #{desc => "message token, can be empty"})}
, {method, mk(string(), #{desc => "response code"})}
, {payload, mk(string(), #{desc => "payload"})}
].
format_to_response(ContentType, #coap_message{id = Id,

View File

@ -44,7 +44,6 @@
%% http handlers
-export([ gateway/2
, gateway_insta/2
, gateway_insta_stats/2
]).
%%--------------------------------------------------------------------
@ -57,7 +56,6 @@ api_spec() ->
paths() ->
[ "/gateway"
, "/gateway/:name"
, "/gateway/:name/stats"
].
%%--------------------------------------------------------------------
@ -140,9 +138,6 @@ gateway_insta(put, #{body := GwConf0,
end
end).
gateway_insta_stats(get, _Req) ->
return_http_error(409, "Implement it later (maybe 5.1)").
%%--------------------------------------------------------------------
%% Swagger defines
%%--------------------------------------------------------------------
@ -150,7 +145,7 @@ gateway_insta_stats(get, _Req) ->
schema("/gateway") ->
#{ 'operationId' => gateway,
get =>
#{ description => <<"Get gateway list">>
#{ desc => <<"Get gateway list">>
, parameters => params_gateway_status_in_qs()
, responses =>
?STANDARD_RESP(
@ -159,7 +154,7 @@ schema("/gateway") ->
examples_gateway_overview())})
},
post =>
#{ description => <<"Load a gateway">>
#{ desc => <<"Load a gateway">>
%% TODO: distinguish create & response swagger schema
, 'requestBody' => schema_gateways_conf()
, responses =>
@ -169,39 +164,24 @@ schema("/gateway") ->
schema("/gateway/:name") ->
#{ 'operationId' => gateway_insta,
get =>
#{ description => <<"Get the gateway configurations">>
#{ desc => <<"Get the gateway configurations">>
, parameters => params_gateway_name_in_path()
, responses =>
?STANDARD_RESP(#{200 => schema_gateways_conf()})
},
delete =>
#{ description => <<"Delete/Unload the gateway">>
#{ desc => <<"Delete/Unload the gateway">>
, parameters => params_gateway_name_in_path()
, responses =>
?STANDARD_RESP(#{204 => <<"Deleted">>})
},
put =>
#{ description => <<"Update the gateway configurations/status">>
#{ desc => <<"Update the gateway configurations/status">>
, parameters => params_gateway_name_in_path()
, 'requestBody' => schema_update_gateways_conf()
, responses =>
?STANDARD_RESP(#{200 => schema_gateways_conf()})
}
};
schema("/gateway/:name/stats") ->
#{ 'operationId' => gateway_insta_stats,
get =>
#{ description => <<"Get gateway Statistic">>
, parameters => params_gateway_name_in_path()
, responses =>
?STANDARD_RESP(
#{200 => emqx_dashboard_swagger:schema_with_examples(
ref(gateway_stats),
examples_gateway_stats()),
409 => emqx_dashboard_swagger:error_codes(
['NOT_SUPPORT'], <<"Resource not support">>)
})
}
}.
%%--------------------------------------------------------------------
@ -211,7 +191,7 @@ params_gateway_name_in_path() ->
[{name,
mk(binary(),
#{ in => path
, description => <<"Gateway Name">>
, desc => <<"Gateway Name">>
, example => <<"">>
})}
].
@ -222,7 +202,7 @@ params_gateway_status_in_qs() ->
mk(binary(),
#{ in => query
, required => false
, description => <<"Gateway Status">>
, desc => <<"Gateway Status">>
, example => <<"">>
})}
].
@ -238,50 +218,50 @@ roots() ->
fields(gateway_overview) ->
[ {name,
mk(binary(),
#{ description => <<"Gateway Name">>})}
#{ desc => <<"Gateway Name">>})}
, {status,
mk(hoconsc:enum([running, stopped, unloaded]),
#{ description => <<"The Gateway status">>})}
#{ desc => <<"The Gateway status">>})}
, {created_at,
mk(binary(),
#{description => <<"The Gateway created datetime">>})}
#{desc => <<"The Gateway created datetime">>})}
, {started_at,
mk(binary(),
#{ required => false
, description => <<"The Gateway started datetime">>})}
, desc => <<"The Gateway started datetime">>})}
, {stopped_at,
mk(binary(),
#{ required => false
, description => <<"The Gateway stopped datetime">>})}
, desc => <<"The Gateway stopped datetime">>})}
, {max_connections,
mk(integer(),
#{ description => <<"The Gateway allowed maximum connections/clients">>})}
#{ desc => <<"The Gateway allowed maximum connections/clients">>})}
, {current_connections,
mk(integer(),
#{ description => <<"The Gateway current connected connections/clients">>
#{ desc => <<"The Gateway current connected connections/clients">>
})}
, {listeners,
mk(hoconsc:array(ref(gateway_listener_overview)),
#{ required => {false, recursively}
, description => <<"The Gateway listeners overview">>})}
, desc => <<"The Gateway listeners overview">>})}
];
fields(gateway_listener_overview) ->
[ {id,
mk(binary(),
#{ description => <<"Listener ID">>})}
#{ desc => <<"Listener ID">>})}
, {running,
mk(boolean(),
#{ description => <<"Listener Running status">>})}
#{ desc => <<"Listener Running status">>})}
, {type,
mk(hoconsc:enum([tcp, ssl, udp, dtls]),
#{ description => <<"Listener Type">>})}
#{ desc => <<"Listener Type">>})}
];
fields(Gw) when Gw == stomp; Gw == mqttsn;
Gw == coap; Gw == lwm2m;
Gw == exproto ->
[{name,
mk(hoconsc:union([Gw]), #{ description => <<"Gateway Name">>})}
mk(hoconsc:union([Gw]), #{ desc => <<"Gateway Name">>})}
] ++ convert_listener_struct(emqx_gateway_schema:fields(Gw));
fields(Gw) when Gw == update_stomp; Gw == update_mqttsn;
@ -298,17 +278,17 @@ fields(Listener) when Listener == tcp_listener;
[ {id,
mk(binary(),
#{ required => false
, description => <<"Listener ID">>})}
, desc => <<"Listener ID">>})}
, {type,
mk(hoconsc:union([tcp, ssl, udp, dtls]),
#{ description => <<"Listener type">>})}
#{ desc => <<"Listener type">>})}
, {name,
mk(binary(),
#{ description => <<"Listener Name">>})}
#{ desc => <<"Listener Name">>})}
, {running,
mk(boolean(),
#{ required => false
, description => <<"Listener running status">>})}
, desc => <<"Listener running status">>})}
] ++ emqx_gateway_schema:fields(Listener);
fields(gateway_stats) ->
@ -337,7 +317,7 @@ convert_listener_struct(Schema) ->
#{type := Type}}, Schema1} = lists:keytake(listeners, 1, Schema),
ListenerSchema = hoconsc:mk(listeners_schema(Type),
#{ required => {false, recursively}
, description => <<"The gateway listeners">>
, desc => <<"The gateway listeners">>
}),
lists:keystore(listeners, 1, Schema1, {listeners, ListenerSchema}).
@ -625,6 +605,3 @@ examples_update_gateway_confs() ->
}
}
}.
examples_gateway_stats() ->
#{}.

View File

@ -159,7 +159,7 @@ parse_qstring(Qs) ->
schema("/gateway/:name/authentication") ->
#{ 'operationId' => authn,
get =>
#{ description => <<"Get the gateway authentication">>
#{ desc => <<"Get the gateway authentication">>
, parameters => params_gateway_name_in_path()
, responses =>
?STANDARD_RESP(
@ -168,21 +168,21 @@ schema("/gateway/:name/authentication") ->
})
},
put =>
#{ description => <<"Update authentication for the gateway">>
#{ desc => <<"Update authentication for the gateway">>
, parameters => params_gateway_name_in_path()
, 'requestBody' => schema_authn()
, responses =>
?STANDARD_RESP(#{200 => schema_authn()})
},
post =>
#{ description => <<"Add authentication for the gateway">>
#{ desc => <<"Add authentication for the gateway">>
, parameters => params_gateway_name_in_path()
, 'requestBody' => schema_authn()
, responses =>
?STANDARD_RESP(#{201 => schema_authn()})
},
delete =>
#{ description => <<"Remove the gateway authentication">>
#{ desc => <<"Remove the gateway authentication">>
, parameters => params_gateway_name_in_path()
, responses =>
?STANDARD_RESP(#{204 => <<"Deleted">>})
@ -191,7 +191,7 @@ schema("/gateway/:name/authentication") ->
schema("/gateway/:name/authentication/users") ->
#{ 'operationId' => users
, get =>
#{ description => <<"Get the users for the authentication">>
#{ desc => <<"Get the users for the authentication">>
, parameters => params_gateway_name_in_path() ++
params_paging_in_qs() ++
params_fuzzy_in_qs()
@ -203,7 +203,7 @@ schema("/gateway/:name/authentication/users") ->
})
},
post =>
#{ description => <<"Add user for the authentication">>
#{ desc => <<"Add user for the authentication">>
, parameters => params_gateway_name_in_path()
, 'requestBody' => emqx_dashboard_swagger:schema_with_examples(
ref(emqx_authn_api, request_user_create),
@ -219,7 +219,7 @@ schema("/gateway/:name/authentication/users") ->
schema("/gateway/:name/authentication/users/:uid") ->
#{ 'operationId' => users_insta
, get =>
#{ description => <<"Get user info from the gateway "
#{ desc => <<"Get user info from the gateway "
"authentication">>
, parameters => params_gateway_name_in_path() ++
params_userid_in_path()
@ -231,7 +231,7 @@ schema("/gateway/:name/authentication/users/:uid") ->
})
},
put =>
#{ description => <<"Update the user info for the gateway "
#{ desc => <<"Update the user info for the gateway "
"authentication">>
, parameters => params_gateway_name_in_path() ++
params_userid_in_path()
@ -246,7 +246,7 @@ schema("/gateway/:name/authentication/users/:uid") ->
})
},
delete =>
#{ description => <<"Delete the user for the gateway "
#{ desc => <<"Delete the user for the gateway "
"authentication">>
, parameters => params_gateway_name_in_path() ++
params_userid_in_path()
@ -257,7 +257,7 @@ schema("/gateway/:name/authentication/users/:uid") ->
schema("/gateway/:name/authentication/import_users") ->
#{ 'operationId' => import_users
, post =>
#{ description => <<"Import users into the gateway authentication">>
#{ desc => <<"Import users into the gateway authentication">>
, parameters => params_gateway_name_in_path()
, 'requestBody' => emqx_dashboard_swagger:schema_with_examples(
ref(emqx_authn_api, request_import_users),
@ -275,7 +275,7 @@ params_gateway_name_in_path() ->
[{name,
mk(binary(),
#{ in => path
, description => <<"Gateway Name">>
, desc => <<"Gateway Name">>
, example => <<"">>
})}
].
@ -283,7 +283,7 @@ params_gateway_name_in_path() ->
params_userid_in_path() ->
[{uid, mk(binary(),
#{ in => path
, description => <<"User ID">>
, desc => <<"User ID">>
, example => <<"">>
})}
].
@ -292,13 +292,13 @@ params_paging_in_qs() ->
[{page, mk(integer(),
#{ in => query
, required => false
, description => <<"Page Index">>
, desc => <<"Page Index">>
, example => 1
})},
{limit, mk(integer(),
#{ in => query
, required => false
, description => <<"Page Limit">>
, desc => <<"Page Limit">>
, example => 100
})}
].
@ -308,14 +308,14 @@ params_fuzzy_in_qs() ->
mk(binary(),
#{ in => query
, required => false
, description => <<"Fuzzy search by username">>
, desc => <<"Fuzzy search by username">>
, example => <<"username">>
})},
{like_clientid,
mk(binary(),
#{ in => query
, required => false
, description => <<"Fuzzy search by clientid">>
, desc => <<"Fuzzy search by clientid">>
, example => <<"clientid">>
})}
].

View File

@ -403,7 +403,7 @@ conn_state_to_connected(_) -> false.
schema("/gateway/:name/clients") ->
#{ 'operationId' => clients
, get =>
#{ description => <<"Get the gateway client list">>
#{ desc => <<"Get the gateway client list">>
, parameters => params_client_query()
, responses =>
?STANDARD_RESP(#{200 => schema_client_list()})
@ -412,13 +412,13 @@ schema("/gateway/:name/clients") ->
schema("/gateway/:name/clients/:clientid") ->
#{ 'operationId' => clients_insta
, get =>
#{ description => <<"Get the gateway client information">>
#{ desc => <<"Get the gateway client information">>
, parameters => params_client_insta()
, responses =>
?STANDARD_RESP(#{200 => schema_client()})
}
, delete =>
#{ description => <<"Kick out the gateway client">>
#{ desc => <<"Kick out the gateway client">>
, parameters => params_client_insta()
, responses =>
?STANDARD_RESP(#{204 => <<"Kicked">>})
@ -427,7 +427,7 @@ schema("/gateway/:name/clients/:clientid") ->
schema("/gateway/:name/clients/:clientid/subscriptions") ->
#{ 'operationId' => subscriptions
, get =>
#{ description => <<"Get the gateway client subscriptions">>
#{ desc => <<"Get the gateway client subscriptions">>
, parameters => params_client_insta()
, responses =>
?STANDARD_RESP(
@ -436,7 +436,7 @@ schema("/gateway/:name/clients/:clientid/subscriptions") ->
examples_subsctiption_list())})
}
, post =>
#{ description => <<"Create a subscription membership">>
#{ desc => <<"Create a subscription membership">>
, parameters => params_client_insta()
, 'requestBody' => emqx_dashboard_swagger:schema_with_examples(
ref(subscription),
@ -451,7 +451,7 @@ schema("/gateway/:name/clients/:clientid/subscriptions") ->
schema("/gateway/:name/clients/:clientid/subscriptions/:topic") ->
#{ 'operationId' => subscriptions
, delete =>
#{ description => <<"Delete a subscriptions membership">>
#{ desc => <<"Delete a subscriptions membership">>
, parameters => params_topic_name_in_path() ++ params_client_insta()
, responses =>
?STANDARD_RESP(#{204 => <<"Unsubscribed">>})
@ -471,60 +471,60 @@ params_client_searching_in_qs() ->
M = #{in => query, required => false, example => <<"">>},
[ {node,
mk(binary(),
M#{description => <<"Match the client's node name">>})}
M#{desc => <<"Match the client's node name">>})}
, {clientid,
mk(binary(),
M#{description => <<"Match the client's ID">>})}
M#{desc => <<"Match the client's ID">>})}
, {username,
mk(binary(),
M#{description => <<"Match the client's Username">>})}
M#{desc => <<"Match the client's Username">>})}
, {ip_address,
mk(binary(),
M#{description => <<"Match the client's ip address">>})}
M#{desc => <<"Match the client's ip address">>})}
, {conn_state,
mk(binary(),
M#{description => <<"Match the client's connection state">>})}
M#{desc => <<"Match the client's connection state">>})}
, {proto_ver,
mk(binary(),
M#{description => <<"Match the client's protocol version">>})}
M#{desc => <<"Match the client's protocol version">>})}
, {clean_start,
mk(boolean(),
M#{description => <<"Match the client's clean start flag">>})}
M#{desc => <<"Match the client's clean start flag">>})}
, {like_clientid,
mk(binary(),
M#{description => <<"Use sub-string to match client's ID">>})}
M#{desc => <<"Use sub-string to match client's ID">>})}
, {like_username,
mk(binary(),
M#{description => <<"Use sub-string to match client's username">>})}
M#{desc => <<"Use sub-string to match client's username">>})}
, {gte_created_at,
mk(emqx_datetime:epoch_millisecond(),
M#{description => <<"Match the session created datetime greater than "
M#{desc => <<"Match the session created datetime greater than "
"a certain value">>})}
, {lte_created_at,
mk(emqx_datetime:epoch_millisecond(),
M#{description => <<"Match the session created datetime less than "
M#{desc => <<"Match the session created datetime less than "
"a certain value">>})}
, {gte_connected_at,
mk(emqx_datetime:epoch_millisecond(),
M#{description => <<"Match the client socket connected datetime greater "
M#{desc => <<"Match the client socket connected datetime greater "
"than a certain value">>})}
, {lte_connected_at,
mk(emqx_datetime:epoch_millisecond(),
M#{description => <<"Match the client socket connected datatime less than "
M#{desc => <<"Match the client socket connected datatime less than "
"a certain value">>})}
, {endpoint_name,
mk(binary(),
M#{description => <<"Match the lwm2m client's endpoint name">>})}
M#{desc => <<"Match the lwm2m client's endpoint name">>})}
, {like_endpoint_name,
mk(binary(),
M#{description => <<"Use sub-string to match lwm2m client's endpoint name">>})}
M#{desc => <<"Use sub-string to match lwm2m client's endpoint name">>})}
, {gte_lifetime,
mk(binary(),
M#{description => <<"Match the lwm2m client registered lifetime greater "
M#{desc => <<"Match the lwm2m client registered lifetime greater "
"than a certain value">>})}
, {lte_lifetime,
mk(binary(),
M#{description => <<"Match the lwm2m client registered lifetime less than "
M#{desc => <<"Match the lwm2m client registered lifetime less than "
"a certain value">>})}
].
@ -533,13 +533,13 @@ params_paging() ->
mk(integer(),
#{ in => query
, required => false
, description => <<"Page Index">>
, desc => <<"Page Index">>
, example => 1
})}
, {limit,
mk(integer(),
#{ in => query
, description => <<"Page Limit">>
, desc => <<"Page Limit">>
, required => false
, example => 100
})}
@ -549,7 +549,7 @@ params_gateway_name_in_path() ->
[{name,
mk(binary(),
#{ in => path
, description => <<"Gateway Name">>
, desc => <<"Gateway Name">>
})}
].
@ -557,7 +557,7 @@ params_clientid_in_path() ->
[{clientid,
mk(binary(),
#{ in => path
, description => <<"Client ID">>
, desc => <<"Client ID">>
})}
].
@ -565,7 +565,7 @@ params_topic_name_in_path() ->
[{topic,
mk(binary(),
#{ in => path
, description => <<"Topic Filter/Name">>
, desc => <<"Topic Filter/Name">>
})}
].
@ -612,10 +612,10 @@ fields(coap_client) ->
fields(lwm2m_client) ->
[ {endpoint_name,
mk(binary(),
#{ description => <<"The LwM2M client endpoint name">>})}
#{ desc => <<"The LwM2M client endpoint name">>})}
, {lifetime,
mk(integer(),
#{ description => <<"Life time">>})}
#{ desc => <<"Life time">>})}
] ++ common_client_props();
fields(exproto_client) ->
common_client_props();
@ -623,153 +623,153 @@ fields(exproto_client) ->
fields(subscription) ->
[ {topic,
mk(binary(),
#{ description => <<"Topic Fillter">>})}
#{ desc => <<"Topic Fillter">>})}
, {qos,
mk(integer(),
#{ description => <<"QoS level, enum: 0, 1, 2">>})}
#{ desc => <<"QoS level, enum: 0, 1, 2">>})}
, {nl,
mk(integer(), %% FIXME: why not boolean?
#{ description => <<"No Local option, enum: 0, 1">>})}
#{ desc => <<"No Local option, enum: 0, 1">>})}
, {rap,
mk(integer(),
#{ description => <<"Retain as Published option, enum: 0, 1">>})}
#{ desc => <<"Retain as Published option, enum: 0, 1">>})}
, {rh,
mk(integer(),
#{ description => <<"Retain Handling option, enum: 0, 1, 2">>})}
#{ desc => <<"Retain Handling option, enum: 0, 1, 2">>})}
, {sub_props,
mk(ref(extra_sub_props),
#{description => <<"Subscription properties">>})}
#{desc => <<"Subscription properties">>})}
];
fields(extra_sub_props) ->
[ {subid,
mk(binary(),
#{ description => <<"Only stomp protocol, a unique identity for "
#{ desc => <<"Only stomp protocol, a unique identity for "
"the subscription. range: 1-65535.">>})}
].
common_client_props() ->
[ {node,
mk(binary(),
#{ description => <<"Name of the node to which the client is "
#{ desc => <<"Name of the node to which the client is "
"connected">>})}
, {clientid,
mk(binary(),
#{ description => <<"Client identifier">>})}
#{ desc => <<"Client identifier">>})}
, {username,
mk(binary(),
#{ description => <<"Username of client when connecting">>})}
#{ desc => <<"Username of client when connecting">>})}
, {proto_name,
mk(binary(),
#{ description => <<"Client protocol name">>})}
#{ desc => <<"Client protocol name">>})}
, {proto_ver,
mk(binary(),
#{ description => <<"Protocol version used by the client">>})}
#{ desc => <<"Protocol version used by the client">>})}
, {ip_address,
mk(binary(),
#{ description => <<"Client's IP address">>})}
#{ desc => <<"Client's IP address">>})}
, {port,
mk(integer(),
#{ description => <<"Client's port">>})}
#{ desc => <<"Client's port">>})}
, {is_bridge,
mk(boolean(),
#{ description => <<"Indicates whether the client is connected via "
#{ desc => <<"Indicates whether the client is connected via "
"bridge">>})}
, {connected_at,
mk(emqx_datetime:epoch_millisecond(),
#{ description => <<"Client connection time">>})}
#{ desc => <<"Client connection time">>})}
, {disconnected_at,
mk(emqx_datetime:epoch_millisecond(),
#{ description => <<"Client offline time, This field is only valid and "
#{ desc => <<"Client offline time, This field is only valid and "
"returned when connected is false">>})}
, {connected,
mk(boolean(),
#{ description => <<"Whether the client is connected">>})}
#{ desc => <<"Whether the client is connected">>})}
%% FIXME: the will_msg attribute is not a general attribute
%% for every protocol. But it should be returned to frontend if someone
%% want it
%%
%, {will_msg,
% mk(binary(),
% #{ description => <<"Client will message">>})}
% #{ desc => <<"Client will message">>})}
, {keepalive,
mk(integer(),
#{ description => <<"keepalive time, with the unit of second">>})}
#{ desc => <<"keepalive time, with the unit of second">>})}
, {clean_start,
mk(boolean(),
#{ description => <<"Indicate whether the client is using a brand "
#{ desc => <<"Indicate whether the client is using a brand "
"new session">>})}
, {expiry_interval,
mk(integer(),
#{ description => <<"Session expiration interval, with the unit of "
#{ desc => <<"Session expiration interval, with the unit of "
"second">>})}
, {created_at,
mk(emqx_datetime:epoch_millisecond(),
#{ description => <<"Session creation time">>})}
#{ desc => <<"Session creation time">>})}
, {subscriptions_cnt,
mk(integer(),
#{ description => <<"Number of subscriptions established by this "
#{ desc => <<"Number of subscriptions established by this "
"client">>})}
, {subscriptions_max,
mk(integer(),
#{ description => <<"Maximum number of subscriptions allowed by this "
#{ desc => <<"Maximum number of subscriptions allowed by this "
"client">>})}
, {inflight_cnt,
mk(integer(),
#{ description => <<"Current length of inflight">>})}
#{ desc => <<"Current length of inflight">>})}
, {inflight_max,
mk(integer(),
#{ description => <<"Maximum length of inflight">>})}
#{ desc => <<"Maximum length of inflight">>})}
, {mqueue_len,
mk(integer(),
#{ description => <<"Current length of message queue">>})}
#{ desc => <<"Current length of message queue">>})}
, {mqueue_max,
mk(integer(),
#{ description => <<"Maximum length of message queue">>})}
#{ desc => <<"Maximum length of message queue">>})}
, {mqueue_dropped,
mk(integer(),
#{ description => <<"Number of messages dropped by the message queue "
#{ desc => <<"Number of messages dropped by the message queue "
"due to exceeding the length">>})}
, {awaiting_rel_cnt,
mk(integer(),
%% FIXME: PUBREC ??
#{ description => <<"Number of awaiting acknowledge packet">>})}
#{ desc => <<"Number of awaiting acknowledge packet">>})}
, {awaiting_rel_max,
mk(integer(),
#{ description => <<"Maximum allowed number of awaiting PUBREC "
#{ desc => <<"Maximum allowed number of awaiting PUBREC "
"packet">>})}
, {recv_oct,
mk(integer(),
#{ description => <<"Number of bytes received">>})}
#{ desc => <<"Number of bytes received">>})}
, {recv_cnt,
mk(integer(),
#{ description => <<"Number of socket packets received">>})}
#{ desc => <<"Number of socket packets received">>})}
, {recv_pkt,
mk(integer(),
#{ description => <<"Number of protocol packets received">>})}
#{ desc => <<"Number of protocol packets received">>})}
, {recv_msg,
mk(integer(),
#{ description => <<"Number of message packets received">>})}
#{ desc => <<"Number of message packets received">>})}
, {send_oct,
mk(integer(),
#{ description => <<"Number of bytes sent">>})}
#{ desc => <<"Number of bytes sent">>})}
, {send_cnt,
mk(integer(),
#{ description => <<"Number of socket packets sent">>})}
#{ desc => <<"Number of socket packets sent">>})}
, {send_pkt,
mk(integer(),
#{ description => <<"Number of protocol packets sent">>})}
#{ desc => <<"Number of protocol packets sent">>})}
, {send_msg,
mk(integer(),
#{ description => <<"Number of message packets sent">>})}
#{ desc => <<"Number of message packets sent">>})}
, {mailbox_len,
mk(integer(),
#{ description => <<"Process mailbox size">>})}
#{ desc => <<"Process mailbox size">>})}
, {heap_size,
mk(integer(),
#{ description => <<"Process heap size with the unit of byte">>})}
#{ desc => <<"Process heap size with the unit of byte">>})}
, {reductions,
mk(integer(),
#{ description => <<"Erlang reduction">>})}
#{ desc => <<"Erlang reduction">>})}
].
%%--------------------------------------------------------------------

View File

@ -221,7 +221,7 @@ page_pramas(Qs) ->
schema("/gateway/:name/listeners") ->
#{ 'operationId' => listeners,
get =>
#{ description => <<"Get the gateway listeners">>
#{ desc => <<"Get the gateway listeners">>
, parameters => params_gateway_name_in_path()
, responses =>
?STANDARD_RESP(
@ -231,7 +231,7 @@ schema("/gateway/:name/listeners") ->
})
},
post =>
#{ description => <<"Create the gateway listener">>
#{ desc => <<"Create the gateway listener">>
, parameters => params_gateway_name_in_path()
%% XXX: How to distinguish the different listener supported by
%% different types of gateways?
@ -249,7 +249,7 @@ schema("/gateway/:name/listeners") ->
schema("/gateway/:name/listeners/:id") ->
#{ 'operationId' => listeners_insta,
get =>
#{ description => <<"Get the gateway listener configurations">>
#{ desc => <<"Get the gateway listener configurations">>
, parameters => params_gateway_name_in_path()
++ params_listener_id_in_path()
, responses =>
@ -260,14 +260,14 @@ schema("/gateway/:name/listeners/:id") ->
})
},
delete =>
#{ description => <<"Delete the gateway listener">>
#{ desc => <<"Delete the gateway listener">>
, parameters => params_gateway_name_in_path()
++ params_listener_id_in_path()
, responses =>
?STANDARD_RESP(#{204 => <<"Deleted">>})
},
put =>
#{ description => <<"Update the gateway listener">>
#{ desc => <<"Update the gateway listener">>
, parameters => params_gateway_name_in_path()
++ params_listener_id_in_path()
, 'requestBody' => emqx_dashboard_swagger:schema_with_examples(
@ -284,7 +284,7 @@ schema("/gateway/:name/listeners/:id") ->
schema("/gateway/:name/listeners/:id/authentication") ->
#{ 'operationId' => listeners_insta_authn,
get =>
#{ description => <<"Get the listener's authentication info">>
#{ desc => <<"Get the listener's authentication info">>
, parameters => params_gateway_name_in_path()
++ params_listener_id_in_path()
, responses =>
@ -294,7 +294,7 @@ schema("/gateway/:name/listeners/:id/authentication") ->
})
},
post =>
#{ description => <<"Add authentication for the listener">>
#{ desc => <<"Add authentication for the listener">>
, parameters => params_gateway_name_in_path()
++ params_listener_id_in_path()
, 'requestBody' => schema_authn()
@ -302,7 +302,7 @@ schema("/gateway/:name/listeners/:id/authentication") ->
?STANDARD_RESP(#{201 => schema_authn()})
},
put =>
#{ description => <<"Update authentication for the listener">>
#{ desc => <<"Update authentication for the listener">>
, parameters => params_gateway_name_in_path()
++ params_listener_id_in_path()
, 'requestBody' => schema_authn()
@ -310,7 +310,7 @@ schema("/gateway/:name/listeners/:id/authentication") ->
?STANDARD_RESP(#{200 => schema_authn()})
},
delete =>
#{ description => <<"Remove authentication for the listener">>
#{ desc => <<"Remove authentication for the listener">>
, parameters => params_gateway_name_in_path()
++ params_listener_id_in_path()
, responses =>
@ -320,7 +320,7 @@ schema("/gateway/:name/listeners/:id/authentication") ->
schema("/gateway/:name/listeners/:id/authentication/users") ->
#{ 'operationId' => users
, get =>
#{ description => <<"Get the users for the authentication">>
#{ desc => <<"Get the users for the authentication">>
, parameters => params_gateway_name_in_path() ++
params_listener_id_in_path() ++
params_paging_in_qs()
@ -332,7 +332,7 @@ schema("/gateway/:name/listeners/:id/authentication/users") ->
})
},
post =>
#{ description => <<"Add user for the authentication">>
#{ desc => <<"Add user for the authentication">>
, parameters => params_gateway_name_in_path() ++
params_listener_id_in_path()
, 'requestBody' => emqx_dashboard_swagger:schema_with_examples(
@ -349,7 +349,7 @@ schema("/gateway/:name/listeners/:id/authentication/users") ->
schema("/gateway/:name/listeners/:id/authentication/users/:uid") ->
#{ 'operationId' => users_insta
, get =>
#{ description => <<"Get user info from the gateway "
#{ desc => <<"Get user info from the gateway "
"authentication">>
, parameters => params_gateway_name_in_path() ++
params_listener_id_in_path() ++
@ -362,7 +362,7 @@ schema("/gateway/:name/listeners/:id/authentication/users/:uid") ->
})
},
put =>
#{ description => <<"Update the user info for the gateway "
#{ desc => <<"Update the user info for the gateway "
"authentication">>
, parameters => params_gateway_name_in_path() ++
params_listener_id_in_path() ++
@ -378,7 +378,7 @@ schema("/gateway/:name/listeners/:id/authentication/users/:uid") ->
})
},
delete =>
#{ description => <<"Delete the user for the gateway "
#{ desc => <<"Delete the user for the gateway "
"authentication">>
, parameters => params_gateway_name_in_path() ++
params_listener_id_in_path() ++
@ -390,7 +390,7 @@ schema("/gateway/:name/listeners/:id/authentication/users/:uid") ->
schema("/gateway/:name/listeners/:id/authentication/import_users") ->
#{ 'operationId' => import_users
, post =>
#{ description => <<"Import users into the gateway authentication">>
#{ desc => <<"Import users into the gateway authentication">>
, parameters => params_gateway_name_in_path() ++
params_listener_id_in_path()
, 'requestBody' => emqx_dashboard_swagger:schema_with_examples(
@ -409,7 +409,7 @@ params_gateway_name_in_path() ->
[{name,
mk(binary(),
#{ in => path
, description => <<"Gateway Name">>
, desc => <<"Gateway Name">>
, example => <<"">>
})}
].
@ -418,7 +418,7 @@ params_listener_id_in_path() ->
[{id,
mk(binary(),
#{ in => path
, description => <<"Listener ID">>
, desc => <<"Listener ID">>
, example => <<"">>
})}
].
@ -426,7 +426,7 @@ params_listener_id_in_path() ->
params_userid_in_path() ->
[{uid, mk(binary(),
#{ in => path
, description => <<"User ID">>
, desc => <<"User ID">>
, example => <<"">>
})}
].
@ -435,13 +435,13 @@ params_paging_in_qs() ->
[{page, mk(integer(),
#{ in => query
, required => false
, description => <<"Page Index">>
, desc => <<"Page Index">>
, example => 1
})},
{limit, mk(integer(),
#{ in => query
, required => false
, description => <<"Page Limit">>
, desc => <<"Page Limit">>
, example => 100
})}
].
@ -458,22 +458,22 @@ fields(listener) ->
[ {tcp,
mk(ref(tcp_listener_opts),
#{ required => {false, recursively}
, description => <<"The tcp socket options for tcp or ssl listener">>
, desc => <<"The tcp socket options for tcp or ssl listener">>
})}
, {ssl,
mk(ref(ssl_listener_opts),
#{ required => {false, recursively}
, description => <<"The ssl socket options for ssl listener">>
, desc => <<"The ssl socket options for ssl listener">>
})}
, {udp,
mk(ref(udp_listener_opts),
#{ required => {false, recursively}
, description => <<"The udp socket options for udp or dtls listener">>
, desc => <<"The udp socket options for udp or dtls listener">>
})}
, {dtls,
mk(ref(dtls_listener_opts),
#{ required => {false, recursively}
, description => <<"The dtls socket options for dtls listener">>
, desc => <<"The dtls socket options for dtls listener">>
})}
];
fields(tcp_listener_opts) ->
@ -530,47 +530,47 @@ common_listener_opts() ->
[ {enable,
mk(boolean(),
#{ required => false
, description => <<"Whether to enable this listener">>})}
, desc => <<"Whether to enable this listener">>})}
, {id,
mk(binary(),
#{ required => false
, description => <<"Listener Id">>})}
, desc => <<"Listener Id">>})}
, {name,
mk(binary(),
#{ required => false
, description => <<"Listener name">>})}
, desc => <<"Listener name">>})}
, {type,
mk(hoconsc:enum([tcp, ssl, udp, dtls]),
#{ required => false
, description => <<"Listener type. Enum: tcp, udp, ssl, dtls">>})}
, desc => <<"Listener type. Enum: tcp, udp, ssl, dtls">>})}
, {running,
mk(boolean(),
#{ required => false
, description => <<"Listener running status">>})}
, desc => <<"Listener running status">>})}
, {bind,
mk(binary(),
#{ required => false
, description => <<"Listener bind address or port">>})}
, desc => <<"Listener bind address or port">>})}
, {acceptors,
mk(integer(),
#{ required => false
, description => <<"Listener acceptors number">>})}
, desc => <<"Listener acceptors number">>})}
, {access_rules,
mk(hoconsc:array(binary()),
#{ required => false
, description => <<"Listener Access rules for client">>})}
, desc => <<"Listener Access rules for client">>})}
, {max_conn_rate,
mk(integer(),
#{ required => false
, description => <<"Max connection rate for the listener">>})}
, desc => <<"Max connection rate for the listener">>})}
, {max_connections,
mk(integer(),
#{ required => false
, description => <<"Max connections for the listener">>})}
, desc => <<"Max connections for the listener">>})}
, {mountpoint,
mk(binary(),
#{ required => false
, description =>
, desc =>
<<"The Mounpoint for clients of the listener. "
"The gateway-level mountpoint configuration can be overloaded "
"when it is not null or empty string">>})}
@ -578,7 +578,7 @@ common_listener_opts() ->
, {authentication,
mk(emqx_authn_schema:authenticator_type(),
#{ required => {false, recursively}
, description => <<"The authenticatior for this listener">>
, desc => <<"The authenticatior for this listener">>
})}
] ++ emqx_gateway_schema:proxy_protocol_opts().

View File

@ -42,7 +42,7 @@ schema(?PATH("/lookup_cmd")) ->
'operationId' => lookup_cmd,
get => #{
tags => [<<"lwm2m">>],
description => <<"Look up resource">>,
desc => <<"Look up resource">>,
parameters => [
{clientid, mk(binary(), #{in => path, example => "urn:oma:lwm2m:oma:2"})},
{path, mk(binary(), #{in => query, required => true, example => "/3/0/7"})},
@ -66,7 +66,7 @@ schema(?PATH("/observe")) ->
'operationId' => observe,
post => #{
tags => [<<"lwm2m">>],
description => <<"(cancel) observe resource">>,
desc => <<"(cancel) observe resource">>,
parameters => [
{clientid, mk(binary(), #{in => path, example => "urn:oma:lwm2m:oma:2"})},
{path, mk(binary(), #{in => query, required => true, example => "/3/0/7"})},
@ -84,7 +84,7 @@ schema(?PATH("/read")) ->
'operationId' => read,
post => #{
tags => [<<"lwm2m">>],
description => <<"Send a read command to resource">>,
desc => <<"Send a read command to resource">>,
parameters => [
{clientid, mk(binary(), #{in => path, example => "urn:oma:lwm2m:oma:2"})},
{path, mk(binary(), #{in => query, required => true, example => "/3/0/7"})}
@ -99,7 +99,7 @@ schema(?PATH("/write")) ->
#{
'operationId' => write,
post => #{
description => <<"Send a write command to resource">>,
desc => <<"Send a write command to resource">>,
tags => [<<"lwm2m">>],
parameters => [
{clientid, mk(binary(), #{in => path, example => "urn:oma:lwm2m:oma:2"})},
@ -117,11 +117,11 @@ schema(?PATH("/write")) ->
fields(resource) ->
[
{operations, mk(binary(), #{description => <<"Resource Operations">>, example => "E"})},
{'dataType', mk(hoconsc:enum(?DATA_TYPE), #{description => <<"Data Type">>,
{operations, mk(binary(), #{desc => <<"Resource Operations">>, example => "E"})},
{'dataType', mk(hoconsc:enum(?DATA_TYPE), #{desc => <<"Data Type">>,
example => 'Integer'})},
{path, mk(binary(), #{description => <<"Resource Path">>, example => "urn:oma:lwm2m:oma:2"})},
{name, mk(binary(), #{description => <<"Resource Name">>, example => "lwm2m-test"})}
{path, mk(binary(), #{desc => <<"Resource Path">>, example => "urn:oma:lwm2m:oma:2"})},
{name, mk(binary(), #{desc => <<"Resource Name">>, example => "lwm2m-test"})}
].
lookup_cmd(get, #{bindings := Bindings, query_string := QS}) ->

View File

@ -129,8 +129,13 @@ settings(get, _) ->
{200, emqx:get_raw_config([slow_subs], #{})};
settings(put, #{body := Body}) ->
_ = emqx_slow_subs:update_settings(Body),
{200, emqx:get_raw_config([slow_subs], #{})}.
case emqx_slow_subs:update_settings(Body) of
{ok, NewConf} ->
{200, NewConf};
{error, Reason} ->
Message = list_to_binary(io_lib:format("Update slow subs config failed ~p", [Reason])),
{400, 'BAD_REQUEST', Message}
end.
rpc_call(Fun) ->
Nodes = mria_mnesia:running_nodes(),