diff --git a/src/hocon_schema.erl b/src/hocon_schema.erl index 0971681..044d539 100644 --- a/src/hocon_schema.erl +++ b/src/hocon_schema.erl @@ -26,15 +26,18 @@ -export([map/2, map/3, map/4]). -export([translate/3]). --export([nest/1]). --export([generate/2, generate/3]). +-export([generate/2, generate/3, map_translate/3]). -export([check/2, check/3, check_plain/2, check_plain/3, check_plain/4]). -export([deep_get/2, deep_get/3, deep_get/4, deep_put/3]). --export([richmap_to_map/1, atom_key_map/1, get_value/2]). +-export([richmap_to_map/1, get_value/2]). -export([find_struct/2]). -include("hoconsc.hrl"). +-ifdef(TEST). +-export([nest/1]). +-endif. + -export_type([ name/0 , typefunc/0 , translationfunc/0 @@ -165,9 +168,14 @@ generate(Schema, Conf) -> generate(Schema, Conf, #{}). generate(Schema, Conf, Opts) -> + {Mapped, _NewConf} = map_translate(Schema, Conf, Opts), + Mapped. + +-spec(map_translate(schema(), hocon:config(), opts()) -> [proplists:property()]). +map_translate(Schema, Conf, Opts) -> {Mapped, NewConf} = map(Schema, Conf, all, Opts), Translated = translate(Schema, NewConf, Mapped), - nest(Translated). + {nest(Translated), NewConf}. %% @private returns a nested proplist with atom keys -spec(nest([proplists:property()]) -> [proplists:property()]). diff --git a/test/hocon_schema_tests.erl b/test/hocon_schema_tests.erl index c796e35..ec12838 100644 --- a/test/hocon_schema_tests.erl +++ b/test/hocon_schema_tests.erl @@ -170,6 +170,9 @@ generate_compatibility_test() -> [{app_foo, C0}] = cuttlefish_generator:map({Translations, Mappings, []}, Conf), [{app_foo, C1}] = hocon_schema:generate(demo_schema, Hocon), + {[{app_foo, C1}], Conf1} = hocon_schema:map_translate(demo_schema, Hocon, #{}), + ?assertMatch(#{<<"foo">> := #{<<"max">> := 2, <<"min">> := 1, <<"setting">> := "val"}}, + hocon_schema:richmap_to_map(Conf1)), ?assertEqual(lists:ukeysort(1, C0), lists:ukeysort(1, C1)). deep_get_test_() ->