refactor: remove ambiguity from api
In preparation for the "reorder" API
This commit is contained in:
parent
96ffc9b174
commit
bcb7fe96d5
|
@ -22,8 +22,8 @@
|
||||||
%% `minirest' handlers
|
%% `minirest' handlers
|
||||||
-export([
|
-export([
|
||||||
'/message_validations'/2,
|
'/message_validations'/2,
|
||||||
'/message_validations/:name'/2,
|
'/message_validations/validation/:name'/2,
|
||||||
'/message_validations/:name/move'/2
|
'/message_validations/validation/:name/move'/2
|
||||||
]).
|
]).
|
||||||
|
|
||||||
%%-------------------------------------------------------------------------------------------------
|
%%-------------------------------------------------------------------------------------------------
|
||||||
|
@ -44,8 +44,8 @@ api_spec() ->
|
||||||
paths() ->
|
paths() ->
|
||||||
[
|
[
|
||||||
"/message_validations",
|
"/message_validations",
|
||||||
"/message_validations/:name",
|
"/message_validations/validation/:name",
|
||||||
"/message_validations/:name/move"
|
"/message_validations/validation/:name/move"
|
||||||
].
|
].
|
||||||
|
|
||||||
schema("/message_validations") ->
|
schema("/message_validations") ->
|
||||||
|
@ -107,9 +107,9 @@ schema("/message_validations") ->
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
schema("/message_validations/:name") ->
|
schema("/message_validations/validation/:name") ->
|
||||||
#{
|
#{
|
||||||
'operationId' => '/message_validations/:name',
|
'operationId' => '/message_validations/validation/:name',
|
||||||
get => #{
|
get => #{
|
||||||
tags => ?TAGS,
|
tags => ?TAGS,
|
||||||
summary => <<"Lookup a validation">>,
|
summary => <<"Lookup a validation">>,
|
||||||
|
@ -142,9 +142,9 @@ schema("/message_validations/:name") ->
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
schema("/message_validations/:name/move") ->
|
schema("/message_validations/validation/:name/move") ->
|
||||||
#{
|
#{
|
||||||
'operationId' => '/message_validations/:name/move',
|
'operationId' => '/message_validations/validation/:name/move',
|
||||||
post => #{
|
post => #{
|
||||||
tags => ?TAGS,
|
tags => ?TAGS,
|
||||||
summary => <<"Change the order of a validation">>,
|
summary => <<"Change the order of a validation">>,
|
||||||
|
@ -226,13 +226,13 @@ fields(before) ->
|
||||||
not_found()
|
not_found()
|
||||||
).
|
).
|
||||||
|
|
||||||
'/message_validations/:name'(get, #{bindings := #{name := Name}}) ->
|
'/message_validations/validation/:name'(get, #{bindings := #{name := Name}}) ->
|
||||||
with_validation(
|
with_validation(
|
||||||
Name,
|
Name,
|
||||||
fun(Validation) -> ?OK(Validation) end,
|
fun(Validation) -> ?OK(Validation) end,
|
||||||
not_found()
|
not_found()
|
||||||
);
|
);
|
||||||
'/message_validations/:name'(delete, #{bindings := #{name := Name}}) ->
|
'/message_validations/validation/:name'(delete, #{bindings := #{name := Name}}) ->
|
||||||
with_validation(
|
with_validation(
|
||||||
Name,
|
Name,
|
||||||
fun() ->
|
fun() ->
|
||||||
|
@ -246,7 +246,7 @@ fields(before) ->
|
||||||
not_found()
|
not_found()
|
||||||
).
|
).
|
||||||
|
|
||||||
'/message_validations/:name/move'(post, #{bindings := #{name := Name}, body := Body}) ->
|
'/message_validations/validation/:name/move'(post, #{bindings := #{name := Name}, body := Body}) ->
|
||||||
with_validation(
|
with_validation(
|
||||||
Name,
|
Name,
|
||||||
fun() ->
|
fun() ->
|
||||||
|
|
|
@ -151,7 +151,7 @@ list() ->
|
||||||
simplify_result(Res).
|
simplify_result(Res).
|
||||||
|
|
||||||
lookup(Name) ->
|
lookup(Name) ->
|
||||||
Path = emqx_mgmt_api_test_util:api_path([api_root(), Name]),
|
Path = emqx_mgmt_api_test_util:api_path([api_root(), "validation", Name]),
|
||||||
Res = request(get, Path, _Params = []),
|
Res = request(get, Path, _Params = []),
|
||||||
ct:pal("lookup ~s result:\n ~p", [Name, Res]),
|
ct:pal("lookup ~s result:\n ~p", [Name, Res]),
|
||||||
simplify_result(Res).
|
simplify_result(Res).
|
||||||
|
@ -169,17 +169,23 @@ update(Params) ->
|
||||||
simplify_result(Res).
|
simplify_result(Res).
|
||||||
|
|
||||||
delete(Name) ->
|
delete(Name) ->
|
||||||
Path = emqx_mgmt_api_test_util:api_path([api_root(), Name]),
|
Path = emqx_mgmt_api_test_util:api_path([api_root(), "validation", Name]),
|
||||||
Res = request(delete, Path, _Params = []),
|
Res = request(delete, Path, _Params = []),
|
||||||
ct:pal("delete result:\n ~p", [Res]),
|
ct:pal("delete result:\n ~p", [Res]),
|
||||||
simplify_result(Res).
|
simplify_result(Res).
|
||||||
|
|
||||||
move(Name, Pos) ->
|
move(Name, Pos) ->
|
||||||
Path = emqx_mgmt_api_test_util:api_path([api_root(), Name, "move"]),
|
Path = emqx_mgmt_api_test_util:api_path([api_root(), "validation", Name, "move"]),
|
||||||
Res = request(post, Path, Pos),
|
Res = request(post, Path, Pos),
|
||||||
ct:pal("move result:\n ~p", [Res]),
|
ct:pal("move result:\n ~p", [Res]),
|
||||||
simplify_result(Res).
|
simplify_result(Res).
|
||||||
|
|
||||||
|
reorder(Order) ->
|
||||||
|
Path = emqx_mgmt_api_test_util:api_path([api_root(), "reorder"]),
|
||||||
|
Res = request(post, Path, Order),
|
||||||
|
ct:pal("reorder result:\n ~p", [Res]),
|
||||||
|
simplify_result(Res).
|
||||||
|
|
||||||
connect(ClientId) ->
|
connect(ClientId) ->
|
||||||
connect(ClientId, _IsPersistent = false).
|
connect(ClientId, _IsPersistent = false).
|
||||||
|
|
||||||
|
@ -410,6 +416,7 @@ t_crud(_Config) ->
|
||||||
|
|
||||||
ok.
|
ok.
|
||||||
|
|
||||||
|
%% test the "move" API
|
||||||
t_move(_Config) ->
|
t_move(_Config) ->
|
||||||
lists:foreach(
|
lists:foreach(
|
||||||
fun(Pos) ->
|
fun(Pos) ->
|
||||||
|
|
Loading…
Reference in New Issue