fix(config_api): improve the schema for config update APIs
This commit is contained in:
parent
f01b77e4fe
commit
213b7c2501
|
@ -24,6 +24,7 @@
|
||||||
, safe_atom_key_map/1
|
, safe_atom_key_map/1
|
||||||
, unsafe_atom_key_map/1
|
, unsafe_atom_key_map/1
|
||||||
, jsonable_map/1
|
, jsonable_map/1
|
||||||
|
, jsonable_value/1
|
||||||
, deep_convert/2
|
, deep_convert/2
|
||||||
]).
|
]).
|
||||||
|
|
||||||
|
|
|
@ -24,6 +24,8 @@
|
||||||
, config_reset/2
|
, config_reset/2
|
||||||
]).
|
]).
|
||||||
|
|
||||||
|
-export([get_conf_schema/2]).
|
||||||
|
|
||||||
-define(PARAM_CONF_PATH, [#{
|
-define(PARAM_CONF_PATH, [#{
|
||||||
name => conf_path,
|
name => conf_path,
|
||||||
in => query,
|
in => query,
|
||||||
|
@ -171,15 +173,19 @@ get_conf_schema(BasePath, [{Key, Conf} | Confs], Result, MaxDepth) ->
|
||||||
|
|
||||||
%% TODO: generate from hocon schema
|
%% TODO: generate from hocon schema
|
||||||
gen_schema(Conf) when is_boolean(Conf) ->
|
gen_schema(Conf) when is_boolean(Conf) ->
|
||||||
#{type => boolean};
|
with_default_value(#{type => boolean}, Conf);
|
||||||
gen_schema(Conf) when is_binary(Conf); is_atom(Conf) ->
|
gen_schema(Conf) when is_binary(Conf); is_atom(Conf) ->
|
||||||
#{type => string};
|
with_default_value(#{type => string}, Conf);
|
||||||
gen_schema(Conf) when is_number(Conf) ->
|
gen_schema(Conf) when is_number(Conf) ->
|
||||||
#{type => number};
|
with_default_value(#{type => number}, Conf);
|
||||||
gen_schema(Conf) when is_list(Conf) ->
|
gen_schema(Conf) when is_list(Conf) ->
|
||||||
#{type => array, items => case Conf of
|
#{type => array, items => case Conf of
|
||||||
[] -> #{}; %% don't know the type
|
[] -> #{}; %% don't know the type
|
||||||
_ -> gen_schema(hd(Conf))
|
_ ->
|
||||||
|
case io_lib:printable_unicode_list(Conf) of
|
||||||
|
true -> gen_schema(unicode:characters_to_binary(Conf));
|
||||||
|
false -> gen_schema(hd(Conf))
|
||||||
|
end
|
||||||
end};
|
end};
|
||||||
gen_schema(Conf) when is_map(Conf) ->
|
gen_schema(Conf) when is_map(Conf) ->
|
||||||
#{type => object, properties =>
|
#{type => object, properties =>
|
||||||
|
@ -189,6 +195,9 @@ gen_schema(_Conf) ->
|
||||||
%% by the hocon schema
|
%% by the hocon schema
|
||||||
#{type => string}.
|
#{type => string}.
|
||||||
|
|
||||||
|
with_default_value(Type, Value) ->
|
||||||
|
Type#{example => emqx_map_lib:jsonable_value(Value)}.
|
||||||
|
|
||||||
path_join(Path) ->
|
path_join(Path) ->
|
||||||
path_join(Path, "/").
|
path_join(Path, "/").
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue