diff --git a/apps/emqx/src/emqx_config.erl b/apps/emqx/src/emqx_config.erl index 6d706316c..c462b6725 100644 --- a/apps/emqx/src/emqx_config.erl +++ b/apps/emqx/src/emqx_config.erl @@ -366,13 +366,6 @@ schema_default(Schema) -> case hocon_schema:field_schema(Schema, type) of ?ARRAY(_) -> []; - ?LAZY(?ARRAY(_)) -> - []; - ?LAZY(?UNION(Members)) -> - case [A || ?ARRAY(A) <- hoconsc:union_members(Members)] of - [_ | _] -> []; - _ -> #{} - end; _ -> #{} end. @@ -407,8 +400,7 @@ merge_envs(SchemaMod, RawConf) -> Opts = #{ required => false, format => map, - apply_override_envs => true, - check_lazy => true + apply_override_envs => true }, hocon_tconf:merge_env_overrides(SchemaMod, RawConf, all, Opts). @@ -451,9 +443,7 @@ compact_errors(Schema, Errors) -> do_check_config(SchemaMod, RawConf, Opts0) -> Opts1 = #{ return_plain => true, - format => map, - %% Don't check lazy types, such as authenticate - check_lazy => false + format => map }, Opts = maps:merge(Opts0, Opts1), {AppEnvs, CheckedConf} = diff --git a/apps/emqx/src/emqx_schema.erl b/apps/emqx/src/emqx_schema.erl index 48bd206c9..77b51f074 100644 --- a/apps/emqx/src/emqx_schema.erl +++ b/apps/emqx/src/emqx_schema.erl @@ -2352,25 +2352,18 @@ authentication(Which) -> global -> ?DESC(global_authentication); listener -> ?DESC(listener_authentication) end, - %% 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 = + %% poor man's dependency injection + %% this is due to the fact that authn is implemented outside of 'emqx' app. + %% so it can not be a part of emqx_schema since 'emqx' app is supposed to + %% work standalone. + Type = case persistent_term:get(?EMQX_AUTHENTICATION_SCHEMA_MODULE_PT_KEY, undefined) of - undefined -> hoconsc:array(typerefl:map()); - Module -> Module:root_type() + undefined -> + hoconsc:array(typerefl:map()); + Module -> + Module:root_type() end, - %% It is a lazy type because when handling runtime update requests - %% the config is not checked by emqx_schema, but by the injected schema - Type = hoconsc:lazy(Type0), - #{ - type => Type, - desc => Desc - }. + hoconsc:mk(Type, #{desc => Desc}). -spec qos() -> typerefl:type(). qos() -> diff --git a/apps/emqx_conf/src/emqx_conf.erl b/apps/emqx_conf/src/emqx_conf.erl index 8b471a137..00648db31 100644 --- a/apps/emqx_conf/src/emqx_conf.erl +++ b/apps/emqx_conf/src/emqx_conf.erl @@ -296,8 +296,6 @@ hocon_schema_to_spec(Type, LocalModule) when ?IS_TYPEREFL(Type) -> hocon_schema_to_spec(?ARRAY(Item), LocalModule) -> {Schema, Refs} = hocon_schema_to_spec(Item, LocalModule), {#{type => array, items => Schema}, Refs}; -hocon_schema_to_spec(?LAZY(Item), LocalModule) -> - hocon_schema_to_spec(Item, LocalModule); hocon_schema_to_spec(?ENUM(Items), _LocalModule) -> {#{type => enum, symbols => Items}, []}; hocon_schema_to_spec(?MAP(Name, Type), LocalModule) -> diff --git a/apps/emqx_dashboard/src/emqx_dashboard_swagger.erl b/apps/emqx_dashboard/src/emqx_dashboard_swagger.erl index 0afbf5f1e..1d0fa7352 100644 --- a/apps/emqx_dashboard/src/emqx_dashboard_swagger.erl +++ b/apps/emqx_dashboard/src/emqx_dashboard_swagger.erl @@ -609,8 +609,6 @@ hocon_schema_to_spec(Type, LocalModule) when ?IS_TYPEREFL(Type) -> hocon_schema_to_spec(?ARRAY(Item), LocalModule) -> {Schema, Refs} = hocon_schema_to_spec(Item, LocalModule), {#{type => array, items => Schema}, Refs}; -hocon_schema_to_spec(?LAZY(Item), LocalModule) -> - hocon_schema_to_spec(Item, LocalModule); hocon_schema_to_spec(?ENUM(Items), _LocalModule) -> {#{type => string, enum => Items}, []}; hocon_schema_to_spec(?MAP(Name, Type), LocalModule) ->