refactor(authn): make schema doc generation work

This commit is contained in:
Zaiming Shi 2021-10-20 17:15:16 +02:00
parent fa91e5f583
commit ce5b456872
10 changed files with 31 additions and 30 deletions

View File

@ -1355,11 +1355,12 @@ str(S) when is_list(S) ->
S.
authentication(Desc) ->
#{ type => hoconsc:union([typerefl:map(), hoconsc:array(typerefl:map())])
, desc => [Desc, "<br>", """
#{ type => hoconsc:lazy(hoconsc:union([typerefl:map(), hoconsc:array(typerefl:map())]))
, desc => iolist_to_binary([Desc, "<br>", """
Authentication can be one single authenticator instance or a chain of authenticators as an array.
The when authenticating a login (username, client ID, etc.) the authenticators are checked
in the configured order.
"""
]
in the configured order.<br>
EMQ X comes with a set of pre-built autenticators, for more details, see
<code>authenticator_config</code>.
"""])
}.

View File

@ -23,8 +23,10 @@
, fields/1
]).
%% just a stub, never used at root level
roots() -> [].
%% only for doc generation
roots() -> [{authenticator_config,
#{type => hoconsc:union(config_refs([Module || {_AuthnType, Module} <- emqx_authn:providers()]))
}}].
fields(_) -> [].
@ -35,3 +37,6 @@ common_fields() ->
enable(type) -> boolean();
enable(default) -> true;
enable(_) -> undefined.
config_refs(Modules) ->
lists:append([Module:refs() || Module <- Modules]).

View File

@ -40,12 +40,11 @@
%% Hocon Schema
%%------------------------------------------------------------------------------
namespace() -> "authn-password_based-http_server".
namespace() -> "authn-http".
roots() ->
[ {config, {union, [ hoconsc:ref(?MODULE, get)
, hoconsc:ref(?MODULE, post)
]}}
[ {config, hoconsc:mk(hoconsc:union(refs()),
#{})}
].
fields(get) ->
@ -61,8 +60,8 @@ fields(post) ->
] ++ common_fields().
common_fields() ->
[ {mechanism, 'password-based'}
, {backend, 'http'}
[ {mechanism, hoconsc:enum(['password-based'])}
, {backend, hoconsc:enum(['http'])}
, {url, fun url/1}
, {body, fun body/1}
, {request_timeout, fun request_timeout/1}

View File

@ -40,10 +40,9 @@
namespace() -> "authn-jwt".
roots() ->
[ {config, {union, [ hoconsc:mk('hmac-based')
, hoconsc:mk('public-key')
, hoconsc:mk('jwks')
]}}
[ {config, hoconsc:mk(hoconsc:union(refs()),
#{}
)}
].
fields('hmac-based') ->

View File

@ -84,7 +84,7 @@ mnesia(copy) ->
%% Hocon Schema
%%------------------------------------------------------------------------------
namespace() -> "authn-password_based-builtin_db".
namespace() -> "authn-builtin_db".
roots() -> [config].

View File

@ -39,13 +39,11 @@
%% Hocon Schema
%%------------------------------------------------------------------------------
namespace() -> "authn-password_based-mongodb".
namespace() -> "authn-mongodb".
roots() ->
[ {config, {union, [ hoconsc:mk(standalone)
, hoconsc:mk('replica-set')
, hoconsc:mk('sharded-cluster')
]}}
[ {config, hoconsc:mk(hoconsc:union(refs()),
#{})}
].
fields(standalone) ->

View File

@ -39,7 +39,7 @@
%% Hocon Schema
%%------------------------------------------------------------------------------
namespace() -> "authn-password_based-mysql".
namespace() -> "authn-mysql".
roots() -> [config].

View File

@ -40,7 +40,7 @@
%% Hocon Schema
%%------------------------------------------------------------------------------
namespace() -> "authn-password_based-postgresql".
namespace() -> "authn-postgresql".
roots() -> [config].

View File

@ -39,13 +39,11 @@
%% Hocon Schema
%%------------------------------------------------------------------------------
namespace() -> "authn-password_based-redis".
namespace() -> "authn-redis".
roots() ->
[ {config, {union, [ hoconsc:mk(standalone)
, hoconsc:mk(cluster)
, hoconsc:mk(sentinel)
]}}
[ {config, hoconsc:mk(hoconsc:union(refs()),
#{})}
].
fields(standalone) ->

View File

@ -45,6 +45,7 @@
[ emqx_bridge_schema
, emqx_retainer_schema
, emqx_statsd_schema
, emqx_authn_schema
, emqx_authz_schema
, emqx_auto_subscribe_schema
, emqx_modules_schema