fix: generate dashboard api response code
This commit is contained in:
parent
15b8203ac1
commit
60f107f91f
|
@ -92,7 +92,7 @@ stop_listeners() ->
|
||||||
%% internal
|
%% internal
|
||||||
|
|
||||||
apps() ->
|
apps() ->
|
||||||
[emqx_exhook].
|
[emqx_management].
|
||||||
% [App || {App, _, _} <- application:loaded_applications(),
|
% [App || {App, _, _} <- application:loaded_applications(),
|
||||||
% case re:run(atom_to_list(App), "^emqx") of
|
% case re:run(atom_to_list(App), "^emqx") of
|
||||||
% {match,[{0,4}]} -> true;
|
% {match,[{0,4}]} -> true;
|
||||||
|
|
|
@ -52,18 +52,18 @@ schema("/login") ->
|
||||||
summary => <<"Dashboard Auth">>,
|
summary => <<"Dashboard Auth">>,
|
||||||
'requestBody' => [
|
'requestBody' => [
|
||||||
{username, mk(binary(),
|
{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">>})},
|
'maxLength' => 100, example => <<"admin">>})},
|
||||||
{password, mk(binary(),
|
{password, mk(binary(),
|
||||||
#{desc => "password", example => "public"})}
|
#{description => "password", example => "public"})}
|
||||||
],
|
],
|
||||||
responses => #{
|
responses => #{
|
||||||
200 => [
|
200 => [
|
||||||
{token, mk(string(), #{desc => <<"JWT Token">>})},
|
{token, mk(string(), #{description => <<"JWT Token">>})},
|
||||||
{license, [{edition,
|
{license, [{edition,
|
||||||
mk(enum([community, enterprise]), #{desc => <<"license">>,
|
mk(enum([community, enterprise]), #{description => <<"license">>,
|
||||||
example => "community"})}]},
|
example => "community"})}]},
|
||||||
{version, mk(string(), #{desc => <<"version">>, example => <<"5.0.0">>})}
|
{version, mk(string(), #{description => <<"version">>, example => <<"5.0.0">>})}
|
||||||
],
|
],
|
||||||
401 => [
|
401 => [
|
||||||
{code, mk(string(), #{example => 'ERROR_USERNAME_OR_PWD'})},
|
{code, mk(string(), #{example => 'ERROR_USERNAME_OR_PWD'})},
|
||||||
|
@ -80,7 +80,7 @@ schema("/logout") ->
|
||||||
description => <<"Dashboard User logout">>,
|
description => <<"Dashboard User logout">>,
|
||||||
'requestBody' => [
|
'requestBody' => [
|
||||||
{username, mk(binary(),
|
{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">>})}
|
'maxLength' => 100, example => <<"admin">>})}
|
||||||
],
|
],
|
||||||
responses => #{
|
responses => #{
|
||||||
|
@ -96,7 +96,7 @@ schema("/users") ->
|
||||||
description => <<"Get dashboard users list">>,
|
description => <<"Get dashboard users list">>,
|
||||||
responses => #{
|
responses => #{
|
||||||
200 => mk( array(ref(?MODULE, user))
|
200 => mk( array(ref(?MODULE, user))
|
||||||
, #{desc => "User lists"})
|
, #{description => "User lists"})
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
post => #{
|
post => #{
|
||||||
|
@ -105,7 +105,7 @@ schema("/users") ->
|
||||||
'requestBody' => fields(user_password),
|
'requestBody' => fields(user_password),
|
||||||
responses => #{
|
responses => #{
|
||||||
200 => mk( ref(?MODULE, user)
|
200 => mk( ref(?MODULE, user)
|
||||||
, #{desc => <<"Create User successfully">>}),
|
, #{description => <<"Create User successfully">>}),
|
||||||
400 => [{code, mk(string(), #{example => 'CREATE_FAIL'})},
|
400 => [{code, mk(string(), #{example => 'CREATE_FAIL'})},
|
||||||
{message, mk(string(), #{example => "Create user failed"})}
|
{message, mk(string(), #{example => "Create user failed"})}
|
||||||
]
|
]
|
||||||
|
@ -124,11 +124,11 @@ schema("/users/:username") ->
|
||||||
'requestBody' => [
|
'requestBody' => [
|
||||||
{ description
|
{ description
|
||||||
, mk(binary(),
|
, mk(binary(),
|
||||||
#{desc => <<"User description">>, example => <<"administrator">>})}
|
#{description => <<"User description">>, example => <<"administrator">>})}
|
||||||
],
|
],
|
||||||
responses => #{
|
responses => #{
|
||||||
200 => mk( ref(?MODULE, user)
|
200 => mk( ref(?MODULE, user)
|
||||||
, #{desc => <<"Update User successfully">>}),
|
, #{description => <<"Update User successfully">>}),
|
||||||
400 => [
|
400 => [
|
||||||
{code, mk(string(), #{example => 'UPDATE_FAIL'})},
|
{code, mk(string(), #{example => 'UPDATE_FAIL'})},
|
||||||
{message, mk(string(), #{example => "Update Failed unknown"})}
|
{message, mk(string(), #{example => "Update Failed unknown"})}
|
||||||
|
@ -177,13 +177,13 @@ fields(user) ->
|
||||||
[
|
[
|
||||||
{description,
|
{description,
|
||||||
mk(binary(),
|
mk(binary(),
|
||||||
#{desc => <<"User description">>, example => "administrator"})},
|
#{description => <<"User description">>, example => "administrator"})},
|
||||||
{username,
|
{username,
|
||||||
mk(binary(),
|
mk(binary(),
|
||||||
#{desc => <<"username">>, example => "emqx"})}
|
#{description => <<"username">>, example => "emqx"})}
|
||||||
];
|
];
|
||||||
fields(user_password) ->
|
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}) ->
|
login(post, #{body := Params}) ->
|
||||||
Username = maps:get(<<"username">>, Params),
|
Username = maps:get(<<"username">>, Params),
|
||||||
|
|
|
@ -105,12 +105,12 @@ parameter_node() ->
|
||||||
|
|
||||||
fields(sampler) ->
|
fields(sampler) ->
|
||||||
Samplers =
|
Samplers =
|
||||||
[{SamplerName, hoconsc:mk(integer(), #{desc => swagger_desc(SamplerName)})}
|
[{SamplerName, hoconsc:mk(integer(), #{description => swagger_desc(SamplerName)})}
|
||||||
|| SamplerName <- ?SAMPLER_LIST],
|
|| SamplerName <- ?SAMPLER_LIST],
|
||||||
[{time_stamp, hoconsc:mk(integer(), #{desc => <<"Timestamp">>})} | Samplers];
|
[{time_stamp, hoconsc:mk(integer(), #{description => <<"Timestamp">>})} | Samplers];
|
||||||
|
|
||||||
fields(sampler_current) ->
|
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].
|
|| SamplerName <- maps:values(?DELTA_SAMPLER_RATE_MAP) ++ ?GAUGE_SAMPLER_LIST].
|
||||||
|
|
||||||
%% -------------------------------------------------------------------------------------------------
|
%% -------------------------------------------------------------------------------------------------
|
||||||
|
|
|
@ -95,12 +95,12 @@ namespace() -> "public".
|
||||||
-spec(fields(hocon_schema:name()) -> hocon_schema:fields()).
|
-spec(fields(hocon_schema:name()) -> hocon_schema:fields()).
|
||||||
fields(page) ->
|
fields(page) ->
|
||||||
Desc = <<"Page number of the results to fetch.">>,
|
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)}];
|
[{page, hoconsc:mk(integer(), Meta)}];
|
||||||
fields(limit) ->
|
fields(limit) ->
|
||||||
Desc = iolist_to_binary([<<"Results per page(max ">>,
|
Desc = iolist_to_binary([<<"Results per page(max ">>,
|
||||||
integer_to_binary(?MAX_ROW_LIMIT), <<")">>]),
|
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)}].
|
[{limit, hoconsc:mk(range(1, ?MAX_ROW_LIMIT), Meta)}].
|
||||||
|
|
||||||
-spec(schema_with_example(hocon_schema:type(), term()) -> hocon_schema:field_schema_map()).
|
-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))},
|
{code, hoconsc:mk(hoconsc:enum(Codes))},
|
||||||
{message, hoconsc:mk(string(), #{
|
{message, hoconsc:mk(string(), #{
|
||||||
desc => <<"Details description of the error.">>,
|
description => <<"Details description of the error.">>,
|
||||||
example => MsgExample
|
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("atom()", _Mod) -> #{type => string, example => atom};
|
||||||
typename_to_spec("epoch_second()", _Mod) ->
|
typename_to_spec("epoch_second()", _Mod) ->
|
||||||
#{<<"oneOf">> => [
|
#{<<"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">>}]
|
#{type => string, example => <<"2022-01-01T00:00:00.000Z">>, format => <<"date-time">>}]
|
||||||
};
|
};
|
||||||
typename_to_spec("epoch_millisecond()", _Mod) ->
|
typename_to_spec("epoch_millisecond()", _Mod) ->
|
||||||
#{<<"oneOf">> => [
|
#{<<"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">>}]
|
#{type => string, example => <<"2022-01-01T00:00:00.000Z">>, format => <<"date-time">>}]
|
||||||
};
|
};
|
||||||
typename_to_spec("duration()", _Mod) -> #{type => string, example => <<"12m">>};
|
typename_to_spec("duration()", _Mod) -> #{type => string, example => <<"12m">>};
|
||||||
|
|
|
@ -273,7 +273,7 @@ schema("/test/in/:filter") ->
|
||||||
{filter,
|
{filter,
|
||||||
mk(hoconsc:enum([assigned, created, mentioned, all]),
|
mk(hoconsc:enum([assigned, created, mentioned, all]),
|
||||||
#{in => path,
|
#{in => path,
|
||||||
desc => <<"Indicates which sorts of issues to return">>,
|
description => <<"Indicates which sorts of issues to return">>,
|
||||||
example => "all"
|
example => "all"
|
||||||
})}
|
})}
|
||||||
],
|
],
|
||||||
|
@ -287,8 +287,8 @@ schema("/test/in/query") ->
|
||||||
parameters => [
|
parameters => [
|
||||||
{per_page,
|
{per_page,
|
||||||
mk(range(1, 100),
|
mk(range(1, 100),
|
||||||
#{in => query, desc => <<"results per page (max 100)">>, example => 1})},
|
#{in => query, description => <<"results per page (max 100)">>, example => 1})},
|
||||||
{qos, mk(emqx_schema:qos(), #{in => query, desc => <<"QOS">>})}
|
{qos, mk(emqx_schema:qos(), #{in => query, description => <<"QOS">>})}
|
||||||
],
|
],
|
||||||
responses => #{200 => <<"ok">>}
|
responses => #{200 => <<"ok">>}
|
||||||
}
|
}
|
||||||
|
@ -331,11 +331,11 @@ schema("/test/in/mix/:state") ->
|
||||||
deprecated => true,
|
deprecated => true,
|
||||||
parameters => [
|
parameters => [
|
||||||
{filter, hoconsc:mk(hoconsc:enum([assigned, created, mentioned, all]),
|
{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"})},
|
example => "all"})},
|
||||||
{state, mk(emqx_schema:duration_s(),
|
{state, mk(emqx_schema:duration_s(),
|
||||||
#{in => path, required => true, example => "12m",
|
#{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),
|
{per_page, mk(range(1, 50),
|
||||||
#{in => query, required => false, example => 10, default => 5})},
|
#{in => query, required => false, example => 10, default => 5})},
|
||||||
{is_admin, mk(boolean(), #{in => query})},
|
{is_admin, mk(boolean(), #{in => query})},
|
||||||
|
@ -371,7 +371,7 @@ fields(page) ->
|
||||||
[
|
[
|
||||||
{per_page,
|
{per_page,
|
||||||
mk(range(1, 100),
|
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) ->
|
to_schema(Params) ->
|
||||||
#{
|
#{
|
||||||
|
|
Loading…
Reference in New Issue