fix(banned): create banned with utf8 failed by 500

This commit is contained in:
zhongwencool 2021-12-22 14:24:58 +08:00
parent 96ee51fe57
commit b11a15fa00
4 changed files with 13 additions and 6 deletions

View File

@ -194,6 +194,7 @@ format(Traces) ->
end, Traces). end, Traces).
init([]) -> init([]) ->
ok = mria:wait_for_tables([?TRACE]),
erlang:process_flag(trap_exit, true), erlang:process_flag(trap_exit, true),
OriginLogLevel = emqx_logger:get_primary_log_level(), OriginLogLevel = emqx_logger:get_primary_log_level(),
ok = filelib:ensure_dir(trace_dir()), ok = filelib:ensure_dir(trace_dir()),

View File

@ -211,11 +211,16 @@ check_request_body(#{body := Body}, Schema, Module, CheckFun, true) ->
%% {good_nest_2, mk(ref(?MODULE, good_ref), #{})} %% {good_nest_2, mk(ref(?MODULE, good_ref), #{})}
%% ]} %% ]}
%% ] %% ]
check_request_body(#{body := Body}, Spec, _Module, CheckFun, false) -> check_request_body(#{body := Body}, Spec, _Module, CheckFun, false)when is_list(Spec) ->
lists:foldl(fun({Name, Type}, Acc) -> lists:foldl(fun({Name, Type}, Acc) ->
Schema = ?INIT_SCHEMA#{roots => [{Name, Type}]}, Schema = ?INIT_SCHEMA#{roots => [{Name, Type}]},
maps:merge(Acc, CheckFun(Schema, Body, #{})) maps:merge(Acc, CheckFun(Schema, Body, #{}))
end, #{}, Spec). end, #{}, Spec);
%% requestBody => #{content => #{ 'application/octet-stream' =>
%% #{schema => #{ type => string, format => binary}}}
check_request_body(#{body := Body}, Spec, _Module, _CheckFun, false)when is_map(Spec) ->
Body.
%% tags, description, summary, security, deprecated %% tags, description, summary, security, deprecated
meta_to_spec(Meta, Module) -> meta_to_spec(Meta, Module) ->
@ -287,6 +292,7 @@ trans_desc(Spec, Hocon) ->
Desc -> Spec#{description => to_bin(Desc)} Desc -> Spec#{description => to_bin(Desc)}
end. end.
request_body(#{content := _} = Content, _Module) -> {Content, []};
request_body([], _Module) -> {[], []}; request_body([], _Module) -> {[], []};
request_body(Schema, Module) -> request_body(Schema, Module) ->
{{Props, Refs}, Examples} = {{Props, Refs}, Examples} =

View File

@ -32,7 +32,7 @@
-import(emqx_gateway_api_authn, [schema_authn/0]). -import(emqx_gateway_api_authn, [schema_authn/0]).
%% minirest/dashbaord_swagger behaviour callbacks %% minirest/dashboard_swagger behaviour callbacks
-export([ api_spec/0 -export([ api_spec/0
, paths/0 , paths/0
, schema/1 , schema/1

View File

@ -101,15 +101,15 @@ fields(ban) ->
desc => <<"Banned type clientid, username, peerhost">>, desc => <<"Banned type clientid, username, peerhost">>,
nullable => false, nullable => false,
example => username})}, example => username})},
{who, hoconsc:mk(binary(), #{ {who, hoconsc:mk(emqx_schema:unicode_binary(), #{
desc => <<"Client info as banned type">>, desc => <<"Client info as banned type">>,
nullable => false, nullable => false,
example => <<"Badass">>})}, example => <<"Badass"/utf8>>})},
{by, hoconsc:mk(binary(), #{ {by, hoconsc:mk(binary(), #{
desc => <<"Commander">>, desc => <<"Commander">>,
nullable => true, nullable => true,
example => <<"mgmt_api">>})}, example => <<"mgmt_api">>})},
{reason, hoconsc:mk(binary(), #{ {reason, hoconsc:mk(emqx_schema:unicode_binary(), #{
desc => <<"Banned reason">>, desc => <<"Banned reason">>,
nullable => true, nullable => true,
example => <<"Too many requests">>})}, example => <<"Too many requests">>})},