fix: remove the Id field from response of GET, POST /bridges
The response body of POST, GET /bridges should be the same as the request body of the POST /bridges: ``` {"type": "mqtt", "name": "my_mqtt_bridge" } ``` We force the user to provide an Id of format `{type}:{name}` when GET, DELETE, PUT a bridge: `GET /bridges/{type}:{name}`
This commit is contained in:
parent
b5c011d4a5
commit
72409782eb
|
@ -88,16 +88,18 @@ get_response_body_schema() ->
|
||||||
bridge_info_examples(get)).
|
bridge_info_examples(get)).
|
||||||
|
|
||||||
param_path_operation() ->
|
param_path_operation() ->
|
||||||
path_param(operation, enum([start, stop, restart]), <<"start">>).
|
{operation, mk(enum([start, stop, restart]),
|
||||||
|
|
||||||
param_path_id() ->
|
|
||||||
path_param(id, binary(), <<"http:my_http_bridge">>).
|
|
||||||
|
|
||||||
path_param(Name, Type, Example) ->
|
|
||||||
{Name, mk(Type,
|
|
||||||
#{ in => path
|
#{ in => path
|
||||||
, required => true
|
, required => true
|
||||||
, example => Example
|
, example => <<"start">>
|
||||||
|
})}.
|
||||||
|
|
||||||
|
param_path_id() ->
|
||||||
|
{id, mk(binary(),
|
||||||
|
#{ in => path
|
||||||
|
, required => true
|
||||||
|
, example => <<"http:my_http_bridge">>
|
||||||
|
, desc => <<"The bridge Id. Must be of format {type}:{name}">>
|
||||||
})}.
|
})}.
|
||||||
|
|
||||||
bridge_info_array_example(Method) ->
|
bridge_info_array_example(Method) ->
|
||||||
|
@ -140,7 +142,6 @@ method_example(Type, Direction, get) ->
|
||||||
_ -> "my_" ++ SDir ++ "_" ++ SType ++ "_bridge"
|
_ -> "my_" ++ SDir ++ "_" ++ SType ++ "_bridge"
|
||||||
end,
|
end,
|
||||||
#{
|
#{
|
||||||
id => bin(SType ++ ":" ++ SName),
|
|
||||||
type => bin(SType),
|
type => bin(SType),
|
||||||
name => bin(SName),
|
name => bin(SName),
|
||||||
metrics => ?METRICS(0, 0, 0, 0, 0, 0),
|
metrics => ?METRICS(0, 0, 0, 0, 0, 0),
|
||||||
|
@ -216,7 +217,7 @@ schema("/bridges") ->
|
||||||
post => #{
|
post => #{
|
||||||
tags => [<<"bridges">>],
|
tags => [<<"bridges">>],
|
||||||
summary => <<"Create Bridge">>,
|
summary => <<"Create Bridge">>,
|
||||||
description => <<"Create a new bridge">>,
|
description => <<"Create a new bridge by type and name">>,
|
||||||
requestBody => emqx_dashboard_swagger:schema_with_examples(
|
requestBody => emqx_dashboard_swagger:schema_with_examples(
|
||||||
emqx_bridge_schema:post_request(),
|
emqx_bridge_schema:post_request(),
|
||||||
bridge_info_examples(post)),
|
bridge_info_examples(post)),
|
||||||
|
@ -243,7 +244,7 @@ schema("/bridges/:id") ->
|
||||||
put => #{
|
put => #{
|
||||||
tags => [<<"bridges">>],
|
tags => [<<"bridges">>],
|
||||||
summary => <<"Update Bridge">>,
|
summary => <<"Update Bridge">>,
|
||||||
description => <<"Update a bridge">>,
|
description => <<"Update a bridge by Id">>,
|
||||||
parameters => [param_path_id()],
|
parameters => [param_path_id()],
|
||||||
requestBody => emqx_dashboard_swagger:schema_with_examples(
|
requestBody => emqx_dashboard_swagger:schema_with_examples(
|
||||||
emqx_bridge_schema:put_request(),
|
emqx_bridge_schema:put_request(),
|
||||||
|
@ -257,7 +258,7 @@ schema("/bridges/:id") ->
|
||||||
delete => #{
|
delete => #{
|
||||||
tags => [<<"bridges">>],
|
tags => [<<"bridges">>],
|
||||||
summary => <<"Delete Bridge">>,
|
summary => <<"Delete Bridge">>,
|
||||||
description => <<"Delete a bridge">>,
|
description => <<"Delete a bridge by Id">>,
|
||||||
parameters => [param_path_id()],
|
parameters => [param_path_id()],
|
||||||
responses => #{
|
responses => #{
|
||||||
204 => <<"Bridge deleted">>
|
204 => <<"Bridge deleted">>
|
||||||
|
@ -271,7 +272,7 @@ schema("/bridges/:id/operation/:operation") ->
|
||||||
post => #{
|
post => #{
|
||||||
tags => [<<"bridges">>],
|
tags => [<<"bridges">>],
|
||||||
summary => <<"Start/Stop/Restart Bridge">>,
|
summary => <<"Start/Stop/Restart Bridge">>,
|
||||||
description => <<"Start/Stop/Restart bridges on a specific node">>,
|
description => <<"Start/Stop/Restart bridges on a specific node.">>,
|
||||||
parameters => [
|
parameters => [
|
||||||
param_path_id(),
|
param_path_id(),
|
||||||
param_path_operation()
|
param_path_operation()
|
||||||
|
@ -425,7 +426,6 @@ format_resp(#{id := Id, raw_config := RawConf,
|
||||||
{Type, BridgeName} = emqx_bridge:parse_bridge_id(Id),
|
{Type, BridgeName} = emqx_bridge:parse_bridge_id(Id),
|
||||||
IsConnected = fun(connected) -> connected; (_) -> disconnected end,
|
IsConnected = fun(connected) -> connected; (_) -> disconnected end,
|
||||||
RawConf#{
|
RawConf#{
|
||||||
id => Id,
|
|
||||||
type => Type,
|
type => Type,
|
||||||
name => maps:get(<<"name">>, RawConf, BridgeName),
|
name => maps:get(<<"name">>, RawConf, BridgeName),
|
||||||
node => node(),
|
node => node(),
|
||||||
|
|
|
@ -74,8 +74,7 @@ fields("put") ->
|
||||||
fields("bridge");
|
fields("bridge");
|
||||||
|
|
||||||
fields("get") ->
|
fields("get") ->
|
||||||
[ id_field()
|
emqx_bridge_schema:metrics_status_fields() ++ fields("post").
|
||||||
] ++ emqx_bridge_schema:metrics_status_fields() ++ fields("post").
|
|
||||||
|
|
||||||
basic_config() ->
|
basic_config() ->
|
||||||
[ {enable,
|
[ {enable,
|
||||||
|
@ -96,8 +95,6 @@ basic_config() ->
|
||||||
++ proplists:delete(base_url, emqx_connector_http:fields(config)).
|
++ proplists:delete(base_url, emqx_connector_http:fields(config)).
|
||||||
|
|
||||||
%%======================================================================================
|
%%======================================================================================
|
||||||
id_field() ->
|
|
||||||
{id, mk(binary(), #{desc => "The Bridge ID", example => "http:my_http_bridge"})}.
|
|
||||||
|
|
||||||
type_field() ->
|
type_field() ->
|
||||||
{type, mk(http, #{desc => "The Bridge Type"})}.
|
{type, mk(http, #{desc => "The Bridge Type"})}.
|
||||||
|
|
|
@ -35,15 +35,10 @@ fields("put_egress") ->
|
||||||
proplists:delete(enable, fields("egress"));
|
proplists:delete(enable, fields("egress"));
|
||||||
|
|
||||||
fields("get_ingress") ->
|
fields("get_ingress") ->
|
||||||
[ id_field()
|
emqx_bridge_schema:metrics_status_fields() ++ fields("post_ingress");
|
||||||
] ++ emqx_bridge_schema:metrics_status_fields() ++ fields("post_ingress");
|
|
||||||
fields("get_egress") ->
|
fields("get_egress") ->
|
||||||
[ id_field()
|
emqx_bridge_schema:metrics_status_fields() ++ fields("post_egress").
|
||||||
] ++ emqx_bridge_schema:metrics_status_fields() ++ fields("post_egress").
|
|
||||||
|
|
||||||
%%======================================================================================
|
%%======================================================================================
|
||||||
id_field() ->
|
|
||||||
{id, mk(binary(), #{desc => "The bridge ID", example => "mqtt:my_mqtt_bridge"})}.
|
|
||||||
|
|
||||||
type_field() ->
|
type_field() ->
|
||||||
{type, mk(mqtt, #{desc => "The bridge type"})}.
|
{type, mk(mqtt, #{desc => "The bridge type"})}.
|
||||||
|
|
Loading…
Reference in New Issue