From 5dec0be6e45a6a4a6b9e6c610c288895a1747b74 Mon Sep 17 00:00:00 2001 From: "Zaiming (Stone) Shi" Date: Sun, 26 Jun 2022 14:13:14 +0200 Subject: [PATCH] refactor(emqx_schema): remove union wrapper around array of maps it's previously a union of array (of maps) and map. since the second union member has been removed there is no point of keeping the union wrapper --- apps/emqx/src/emqx_schema.erl | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/apps/emqx/src/emqx_schema.erl b/apps/emqx/src/emqx_schema.erl index f0655d438..c38ef6111 100644 --- a/apps/emqx/src/emqx_schema.erl +++ b/apps/emqx/src/emqx_schema.erl @@ -2216,29 +2216,29 @@ str(B) when is_binary(B) -> str(S) when is_list(S) -> S. -authentication(Type) -> +authentication(Which) -> Desc = - case Type of + case Which of global -> ?DESC(global_authentication); listener -> ?DESC(listener_authentication) end, - %% authentication schema is lazy to make it more 'plugable' - %% the type checks are done in emqx_auth application when it boots. - %% and in emqx_authentication_config module for runtime changes. - Default = hoconsc:lazy(hoconsc:union([hoconsc:array(typerefl:map())])), - %% as the type is lazy, the runtime module injection + %% The runtime module injection %% from EMQX_AUTHENTICATION_SCHEMA_MODULE_PT_KEY %% is for now only affecting document generation. %% maybe in the future, we can find a more straightforward way to support %% * document generation (at compile time) %% * type checks before boot (in bin/emqx config generation) %% * type checks at runtime (when changing configs via management API) + Type0 = + case persistent_term:get(?EMQX_AUTHENTICATION_SCHEMA_MODULE_PT_KEY, undefined) of + undefined -> hoconsc:array(typerefl:map()); + Module -> Module:root_type() + end, + %% It is a lazy type because when handing runtime update requests + %% the config is not checked by emqx_schema, but by the injected schema + Type = hoconsc:lazy(Type0), #{ - type => - case persistent_term:get(?EMQX_AUTHENTICATION_SCHEMA_MODULE_PT_KEY, undefined) of - undefined -> Default; - Module -> hoconsc:lazy(Module:root_type()) - end, + type => Type, desc => Desc }.