Merge pull request #7743 from EMQ-YangM/work1

fix: avoid '/connectors' function pattern matching failures
This commit is contained in:
Yang Miao 2022-04-24 18:50:56 +08:00 committed by GitHub
commit 742e9eed43
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 1 deletions

View File

@ -223,7 +223,10 @@ schema("/connectors/:id") ->
{error, Error} -> {error, Error} ->
{400, error_msg('BAD_REQUEST', Error)} {400, error_msg('BAD_REQUEST', Error)}
end end
end. end;
'/connectors'(post, _) ->
{400, error_msg('BAD_REQUEST', <<"missing some required fields: [name, type]">>)}.
'/connectors/:id'(get, #{bindings := #{id := Id}}) -> '/connectors/:id'(get, #{bindings := #{id := Id}}) ->
?TRY_PARSE_ID(Id, ?TRY_PARSE_ID(Id,

View File

@ -137,6 +137,11 @@ t_mqtt_crud_apis(_) ->
%% then we add a mqtt connector, using POST %% then we add a mqtt connector, using POST
%% POST /connectors/ will create a connector %% POST /connectors/ will create a connector
User1 = <<"user1">>, User1 = <<"user1">>,
{ok, 400, <<"{\"code\":\"BAD_REQUEST\",\"message\""
":\"missing some required fields: [name, type]\"}">>}
= request(post, uri(["connectors"]),
?MQTT_CONNECTOR(User1)#{ <<"type">> => ?CONNECTR_TYPE
}),
{ok, 201, Connector} = request(post, uri(["connectors"]), {ok, 201, Connector} = request(post, uri(["connectors"]),
?MQTT_CONNECTOR(User1)#{ <<"type">> => ?CONNECTR_TYPE ?MQTT_CONNECTOR(User1)#{ <<"type">> => ?CONNECTR_TYPE
, <<"name">> => ?CONNECTR_NAME , <<"name">> => ?CONNECTR_NAME