fix: generate bridge api response code

fix: generate connector api response code SUITE

fix: generate exhook api response code
This commit is contained in:
DDDHuang 2022-03-16 10:40:17 +08:00
parent 1748691db1
commit 74e6fa5a94
5 changed files with 21 additions and 15 deletions

View File

@ -30,6 +30,7 @@
-define(NO_DEFAULT_VALUE, 'NO_DEFAULT_VALUE').
-define(DEPENDENCY_EXISTS, 'DEPENDENCY_EXISTS').
-define(MESSAGE_ID_SCHEMA_ERROR, 'MESSAGE_ID_SCHEMA_ERROR').
-define(INVALID_ID, 'INVALID_ID').
%% Resource Not Found
-define(NOT_FOUND, 'NOT_FOUND').
@ -63,6 +64,7 @@
, {'NO_DEFAULT_VALUE', <<"Request parameters do not use default values">>}
, {'DEPENDENCY_EXISTS', <<"Resource is dependent by another resource">>}
, {'MESSAGE_ID_SCHEMA_ERROR', <<"Message ID parsing error">>}
, {'INVALID_ID', <<"Bad ID schema">>}
, {'MESSAGE_ID_NOT_FOUND', <<"Message ID does not exist">>}
, {'NOT_FOUND', <<"Resource was not found or does not exist">>}
, {'CLIENTID_NOT_FOUND', <<"Client ID was not found or does not exist">>}

View File

@ -267,7 +267,7 @@ schema("/bridges/:id") ->
responses => #{
200 => get_response_body_schema(),
404 => error_schema('NOT_FOUND', "Bridge not found"),
400 => error_schema('BAD_REQUEST', "Update bridge failed")
400 => error_schema(['BAD_REQUEST', 'INVALID_ID'], "Update bridge failed")
}
},
delete => #{
@ -276,7 +276,8 @@ schema("/bridges/:id") ->
description => <<"Delete a bridge by Id">>,
parameters => [param_path_id()],
responses => #{
204 => <<"Bridge deleted">>
204 => <<"Bridge deleted">>,
400 => error_schema(['INVALID_ID'], "Update bridge failed")
}
}
};
@ -294,8 +295,8 @@ schema("/bridges/:id/operation/:operation") ->
param_path_operation_cluster()
],
responses => #{
500 => error_schema('INTERNAL_ERROR', "Operation Failed"),
200 => <<"Operation success">>
200 => <<"Operation success">>,
400 => error_schema('INVALID_ID', "Bad bridge ID")
}
}
};
@ -314,8 +315,8 @@ schema("/nodes/:node/bridges/:id/operation/:operation") ->
param_path_operation_on_node()
],
responses => #{
500 => error_schema('INTERNAL_ERROR', "Operation Failed"),
200 => <<"Operation success">>
200 => <<"Operation success">>,
400 => error_schema('INVALID_ID', "Bad bridge ID")
}
}
}.

View File

@ -171,7 +171,8 @@ schema("/connectors/:id") ->
parameters => param_path_id(),
responses => #{
200 => get_response_body_schema(),
404 => error_schema(['NOT_FOUND'], "Connector not found")
404 => error_schema(['NOT_FOUND'], "Connector not found"),
400 => error_schema(['INVALID_ID'], "Bad connector ID")
}
},
put => #{
@ -182,7 +183,8 @@ schema("/connectors/:id") ->
'requestBody' => put_request_body_schema(),
responses => #{
200 => get_response_body_schema(),
404 => error_schema(['NOT_FOUND'], "Connector not found")
404 => error_schema(['NOT_FOUND'], "Connector not found"),
400 => error_schema(['INVALID_ID'], "Bad connector ID")
}},
delete => #{
tags => [<<"connectors">>],
@ -192,7 +194,8 @@ schema("/connectors/:id") ->
responses => #{
204 => <<"Delete connector successfully">>,
403 => error_schema(['DEPENDENCY_EXISTS'], "Cannot remove dependent connector"),
404 => error_schema(['NOT_FOUND'], "Delete failed, not found")
404 => error_schema(['NOT_FOUND'], "Delete failed, not found"),
400 => error_schema(['INVALID_ID'], "Bad connector ID")
}}
}.

View File

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

View File

@ -241,7 +241,6 @@ move(post, #{bindings := #{name := Name}, body := #{<<"position">> := RawPositio
{ok, ok} ->
{204};
{ok, not_found} ->
%% TODO: unify status code
{400, #{code => <<"BAD_REQUEST">>,
message => <<"Server not found">>
}};