fix: generate dashboard api response code

This commit is contained in:
DDDHuang 2022-03-17 14:09:19 +08:00
parent 15b8203ac1
commit 60f107f91f
5 changed files with 28 additions and 28 deletions

View File

@ -92,7 +92,7 @@ stop_listeners() ->
%% internal
apps() ->
[emqx_exhook].
[emqx_management].
% [App || {App, _, _} <- application:loaded_applications(),
% case re:run(atom_to_list(App), "^emqx") of
% {match,[{0,4}]} -> true;

View File

@ -52,18 +52,18 @@ schema("/login") ->
summary => <<"Dashboard Auth">>,
'requestBody' => [
{username, mk(binary(),
#{desc => <<"The User for which to create the token.">>,
#{description => <<"The User for which to create the token.">>,
'maxLength' => 100, example => <<"admin">>})},
{password, mk(binary(),
#{desc => "password", example => "public"})}
#{description => "password", example => "public"})}
],
responses => #{
200 => [
{token, mk(string(), #{desc => <<"JWT Token">>})},
{token, mk(string(), #{description => <<"JWT Token">>})},
{license, [{edition,
mk(enum([community, enterprise]), #{desc => <<"license">>,
mk(enum([community, enterprise]), #{description => <<"license">>,
example => "community"})}]},
{version, mk(string(), #{desc => <<"version">>, example => <<"5.0.0">>})}
{version, mk(string(), #{description => <<"version">>, example => <<"5.0.0">>})}
],
401 => [
{code, mk(string(), #{example => 'ERROR_USERNAME_OR_PWD'})},
@ -80,7 +80,7 @@ schema("/logout") ->
description => <<"Dashboard User logout">>,
'requestBody' => [
{username, mk(binary(),
#{desc => <<"The User for which to create the token.">>,
#{description => <<"The User for which to create the token.">>,
'maxLength' => 100, example => <<"admin">>})}
],
responses => #{
@ -96,7 +96,7 @@ schema("/users") ->
description => <<"Get dashboard users list">>,
responses => #{
200 => mk( array(ref(?MODULE, user))
, #{desc => "User lists"})
, #{description => "User lists"})
}
},
post => #{
@ -105,7 +105,7 @@ schema("/users") ->
'requestBody' => fields(user_password),
responses => #{
200 => mk( ref(?MODULE, user)
, #{desc => <<"Create User successfully">>}),
, #{description => <<"Create User successfully">>}),
400 => [{code, mk(string(), #{example => 'CREATE_FAIL'})},
{message, mk(string(), #{example => "Create user failed"})}
]
@ -124,11 +124,11 @@ schema("/users/:username") ->
'requestBody' => [
{ description
, mk(binary(),
#{desc => <<"User description">>, example => <<"administrator">>})}
#{description => <<"User description">>, example => <<"administrator">>})}
],
responses => #{
200 => mk( ref(?MODULE, user)
, #{desc => <<"Update User successfully">>}),
, #{description => <<"Update User successfully">>}),
400 => [
{code, mk(string(), #{example => 'UPDATE_FAIL'})},
{message, mk(string(), #{example => "Update Failed unknown"})}
@ -177,13 +177,13 @@ fields(user) ->
[
{description,
mk(binary(),
#{desc => <<"User description">>, example => "administrator"})},
#{description => <<"User description">>, example => "administrator"})},
{username,
mk(binary(),
#{desc => <<"username">>, example => "emqx"})}
#{description => <<"username">>, example => "emqx"})}
];
fields(user_password) ->
fields(user) ++ [{password, mk(binary(), #{desc => "Password", example => <<"public">>})}].
fields(user) ++ [{password, mk(binary(), #{description => "Password", example => <<"public">>})}].
login(post, #{body := Params}) ->
Username = maps:get(<<"username">>, Params),

View File

@ -105,12 +105,12 @@ parameter_node() ->
fields(sampler) ->
Samplers =
[{SamplerName, hoconsc:mk(integer(), #{desc => swagger_desc(SamplerName)})}
[{SamplerName, hoconsc:mk(integer(), #{description => swagger_desc(SamplerName)})}
|| SamplerName <- ?SAMPLER_LIST],
[{time_stamp, hoconsc:mk(integer(), #{desc => <<"Timestamp">>})} | Samplers];
[{time_stamp, hoconsc:mk(integer(), #{description => <<"Timestamp">>})} | Samplers];
fields(sampler_current) ->
[{SamplerName, hoconsc:mk(integer(), #{desc => swagger_desc(SamplerName)})}
[{SamplerName, hoconsc:mk(integer(), #{description => 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, desc => Desc, default => 1, example => 1},
Meta = #{in => query, description => 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, desc => Desc, default => ?DEFAULT_ROW, example => 50},
Meta = #{in => query, description => 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(), #{
desc => <<"Details description of the error.">>,
description => <<"Details description of the error.">>,
example => MsgExample
})}
].
@ -446,12 +446,12 @@ typename_to_spec("string()", _Mod) -> #{type => string, example => <<"string-exa
typename_to_spec("atom()", _Mod) -> #{type => string, example => atom};
typename_to_spec("epoch_second()", _Mod) ->
#{<<"oneOf">> => [
#{type => integer, example => 1640995200, desc => <<"epoch-second">>},
#{type => integer, example => 1640995200, description => <<"epoch-second">>},
#{type => string, example => <<"2022-01-01T00:00:00.000Z">>, format => <<"date-time">>}]
};
typename_to_spec("epoch_millisecond()", _Mod) ->
#{<<"oneOf">> => [
#{type => integer, example => 1640995200000, desc => <<"epoch-millisecond">>},
#{type => integer, example => 1640995200000, description => <<"epoch-millisecond">>},
#{type => string, example => <<"2022-01-01T00:00:00.000Z">>, format => <<"date-time">>}]
};
typename_to_spec("duration()", _Mod) -> #{type => string, example => <<"12m">>};

View File

@ -273,7 +273,7 @@ schema("/test/in/:filter") ->
{filter,
mk(hoconsc:enum([assigned, created, mentioned, all]),
#{in => path,
desc => <<"Indicates which sorts of issues to return">>,
description => <<"Indicates which sorts of issues to return">>,
example => "all"
})}
],
@ -287,8 +287,8 @@ schema("/test/in/query") ->
parameters => [
{per_page,
mk(range(1, 100),
#{in => query, desc => <<"results per page (max 100)">>, example => 1})},
{qos, mk(emqx_schema:qos(), #{in => query, desc => <<"QOS">>})}
#{in => query, description => <<"results per page (max 100)">>, example => 1})},
{qos, mk(emqx_schema:qos(), #{in => query, description => <<"QOS">>})}
],
responses => #{200 => <<"ok">>}
}
@ -331,11 +331,11 @@ schema("/test/in/mix/:state") ->
deprecated => true,
parameters => [
{filter, hoconsc:mk(hoconsc:enum([assigned, created, mentioned, all]),
#{in => query, desc => <<"Indicates which sorts of issues to return">>,
#{in => query, description => <<"Indicates which sorts of issues to return">>,
example => "all"})},
{state, mk(emqx_schema:duration_s(),
#{in => path, required => true, example => "12m",
desc => <<"Indicates the state of the issues to return.">>})},
description => <<"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})},
@ -371,7 +371,7 @@ fields(page) ->
[
{per_page,
mk(range(1, 100),
#{in => query, desc => <<"results per page (max 100)">>, example => 1})}
#{in => query, description => <<"results per page (max 100)">>, example => 1})}
].
to_schema(Params) ->
#{