fix: don't add default if root_key not found

This commit is contained in:
Zhongwen Deng 2022-05-23 14:08:14 +08:00
parent 8aa60cc0a5
commit 96baf4ccdb
1 changed files with 12 additions and 8 deletions

View File

@ -334,7 +334,10 @@ raw_conf_with_default(SchemaMod, RootNames, RawConf) ->
true -> true ->
Acc; Acc;
false -> false ->
{_, {_, Schema}} = lists:keyfind(Name, 1, hocon_schema:roots(SchemaMod)), case lists:keyfind(Name, 1, hocon_schema:roots(SchemaMod)) of
false ->
Acc;
{_, {_, Schema}} ->
Default = Default =
case hocon_schema:field_schema(Schema, type) of case hocon_schema:field_schema(Schema, type) of
?ARRAY(_) -> []; ?ARRAY(_) -> [];
@ -343,6 +346,7 @@ raw_conf_with_default(SchemaMod, RootNames, RawConf) ->
end, end,
Acc#{Name => Default} Acc#{Name => Default}
end end
end
end, end,
RawDefault = lists:foldl(Fun, #{}, RootNames), RawDefault = lists:foldl(Fun, #{}, RootNames),
maps:merge(RawConf, fill_defaults(SchemaMod, RawDefault, #{})). maps:merge(RawConf, fill_defaults(SchemaMod, RawDefault, #{})).