diff --git a/apps/emqx_authn/src/emqx_authn_api.erl b/apps/emqx_authn/src/emqx_authn_api.erl index bef27f99d..36c1e9b6c 100644 --- a/apps/emqx_authn/src/emqx_authn_api.erl +++ b/apps/emqx_authn/src/emqx_authn_api.erl @@ -896,7 +896,7 @@ serialize_error({bad_ssl_config, Details}) -> message => binfmt("bad_ssl_config ~p", [Details])}}; serialize_error({missing_parameter, Detail}) -> {400, #{code => <<"MISSING_PARAMETER">>, - message => binfmt("Missing required parameter", [Detail])}}; + message => binfmt("Missing required parameter: ~p", [Detail])}}; serialize_error({invalid_parameter, Name}) -> {400, #{code => <<"INVALID_PARAMETER">>, message => binfmt("Invalid value for '~p'", [Name])}}; diff --git a/apps/emqx_authn/test/emqx_authn_api_SUITE.erl b/apps/emqx_authn/test/emqx_authn_api_SUITE.erl index 654aa042a..bcbd39a16 100644 --- a/apps/emqx_authn/test/emqx_authn_api_SUITE.erl +++ b/apps/emqx_authn/test/emqx_authn_api_SUITE.erl @@ -136,12 +136,10 @@ test_authenticators(PathPrefix) -> test_authenticator(PathPrefix) -> ValidConfig0 = emqx_authn_test_lib:http_example(), - {ok, 200, _} = request( post, uri(PathPrefix ++ ["authentication"]), ValidConfig0), - {ok, 200, _} = request( get, uri(PathPrefix ++ ["authentication", "password-based:http"])), @@ -262,9 +260,7 @@ test_authenticator_user(PathPrefix) -> fun(UserUpdate) -> {ok, 200, _} = request(put, UsersUri ++ "/u1", UserUpdate) end, ValidUserUpdates), - InvalidUserUpdates = [ - #{user_id => <<"u1">>, password => <<"p1">>}, - #{is_superuser => true}], + InvalidUserUpdates = [#{user_id => <<"u1">>, password => <<"p1">>}], lists:foreach( fun(UserUpdate) -> {ok, 400, _} = request(put, UsersUri ++ "/u1", UserUpdate) end, diff --git a/apps/emqx_bridge/test/emqx_bridge_api_SUITE.erl b/apps/emqx_bridge/test/emqx_bridge_api_SUITE.erl index e898d0dc4..af3ae1c07 100644 --- a/apps/emqx_bridge/test/emqx_bridge_api_SUITE.erl +++ b/apps/emqx_bridge/test/emqx_bridge_api_SUITE.erl @@ -56,7 +56,7 @@ init_per_suite(Config) -> port => 18083 }] }), - ok = application:load(emqx_conf), + _ = application:load(emqx_conf), ok = emqx_common_test_helpers:start_apps([emqx_bridge, emqx_dashboard]), ok = emqx_config:init_load(emqx_bridge_schema, ?CONF_DEFAULT), Config. diff --git a/apps/emqx_connector/src/emqx_connector_http.erl b/apps/emqx_connector/src/emqx_connector_http.erl index 5bfd72b6b..23fed81dd 100644 --- a/apps/emqx_connector/src/emqx_connector_http.erl +++ b/apps/emqx_connector/src/emqx_connector_http.erl @@ -101,6 +101,7 @@ For example: http://localhost:9901/ , {request, hoconsc:mk( ref("request"), #{ default => undefined + , nullable => true , desc => """ If the request is provided, the caller can send HTTP requests via emqx_resource:query(ResourceId, {send_message, BridgeId, Message}) @@ -109,13 +110,13 @@ If the request is provided, the caller can send HTTP requests via ] ++ emqx_connector_schema_lib:ssl_fields(); fields("request") -> - [ {method, hoconsc:mk(hoconsc:enum([post, put, get, delete]), #{})} - , {path, hoconsc:mk(binary(), #{})} - , {body, hoconsc:mk(binary(), #{})} - , {headers, hoconsc:mk(map(), #{})} + [ {method, hoconsc:mk(hoconsc:enum([post, put, get, delete]), #{nullable => true})} + , {path, hoconsc:mk(binary(), #{nullable => true})} + , {body, hoconsc:mk(binary(), #{nullable => true})} + , {headers, hoconsc:mk(map(), #{nullable => true})} , {request_timeout, sc(emqx_schema:duration_ms(), - #{ default => "30s" + #{ nullable => true , desc => "The timeout when sending request to the HTTP server" })} ]. @@ -222,20 +223,22 @@ on_health_check(_InstId, #{host := Host, port := Port} = State) -> %%-------------------------------------------------------------------- %% Internal functions %%-------------------------------------------------------------------- + preprocess_request(undefined) -> undefined; +preprocess_request(Req) when map_size(Req) == 0 -> + undefined; preprocess_request(#{ method := Method, path := Path, body := Body, - headers := Headers, - request_timeout := ReqTimeout - }) -> + headers := Headers + } = Req) -> #{ method => emqx_plugin_libs_rule:preproc_tmpl(bin(Method)) , path => emqx_plugin_libs_rule:preproc_tmpl(Path) , body => emqx_plugin_libs_rule:preproc_tmpl(Body) , headers => preproc_headers(Headers) - , request_timeout => ReqTimeout + , request_timeout => maps:get(request_timeout, Req, 30000) }. preproc_headers(Headers) -> diff --git a/apps/emqx_connector/test/emqx_connector_api_SUITE.erl b/apps/emqx_connector/test/emqx_connector_api_SUITE.erl index c9bd58394..e82d0bf7d 100644 --- a/apps/emqx_connector/test/emqx_connector_api_SUITE.erl +++ b/apps/emqx_connector/test/emqx_connector_api_SUITE.erl @@ -67,7 +67,7 @@ init_per_suite(Config) -> port => 18083 }] }), - ok = application:load(emqx_conf), + _ = application:load(emqx_conf), ok = emqx_common_test_helpers:start_apps([emqx_connector, emqx_bridge, emqx_dashboard]), ok = emqx_config:init_load(emqx_connector_schema, ?CONF_DEFAULT), ok = emqx_config:init_load(emqx_bridge_schema, ?BRIDGE_CONF_DEFAULT), @@ -76,6 +76,7 @@ init_per_suite(Config) -> end_per_suite(_Config) -> ok = ekka:stop(), emqx_common_test_helpers:stop_apps([emqx_connector, emqx_bridge, emqx_dashboard]), + application:unload(emqx_conf), ok. init_per_testcase(_, Config) -> diff --git a/apps/emqx_dashboard/src/emqx_dashboard_swagger.erl b/apps/emqx_dashboard/src/emqx_dashboard_swagger.erl index 89ceb6254..b6724f701 100644 --- a/apps/emqx_dashboard/src/emqx_dashboard_swagger.erl +++ b/apps/emqx_dashboard/src/emqx_dashboard_swagger.erl @@ -200,7 +200,7 @@ check_request_body(#{body := Body}, Schema, Module, CheckFun, true) -> _ -> Type0 end, NewSchema = ?INIT_SCHEMA#{roots => [{root, Type}]}, - Option = #{override_env => false}, + Option = #{override_env => false, nullable => true}, #{<<"root">> := NewBody} = CheckFun(NewSchema, #{<<"root">> => Body}, Option), NewBody; %% TODO not support nest object check yet, please use ref!