From 19b33827ad082c78795dad1b0cc8a8487dd8b4f7 Mon Sep 17 00:00:00 2001 From: zmstone Date: Fri, 6 Sep 2024 12:36:31 +0200 Subject: [PATCH] fix: no alias for map fields --- src/hocon_tconf.erl | 9 ++++++++- test/hocon_tconf_tests.erl | 15 +++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/hocon_tconf.erl b/src/hocon_tconf.erl index 4965b7c..7d468d7 100644 --- a/src/hocon_tconf.erl +++ b/src/hocon_tconf.erl @@ -561,9 +561,16 @@ map_field(?MAP(NameType, Type), FieldSchema, Value, Opts) -> case check_map_key_name(NameType, FieldNames) of ok -> %% All objects in this map should share the same schema. + %% And each fake 'field' should not have any alias + %% because the alias belongs to the parent field NewSc = hocon_schema:override( FieldSchema, - #{type => Type, mapping => undefined, converter => undefined} + #{ + type => Type, + mapping => undefined, + converter => undefined, + aliases => [] + } ), NewFields = [{FieldName, NewSc} || FieldName <- FieldNames], %% start over diff --git a/test/hocon_tconf_tests.erl b/test/hocon_tconf_tests.erl index 24dda89..ba5483e 100644 --- a/test/hocon_tconf_tests.erl +++ b/test/hocon_tconf_tests.erl @@ -2571,3 +2571,18 @@ random_key() -> Bytes = crypto:strong_rand_bytes(10), Key0 = base64:encode(Bytes), iolist_to_binary(re:replace(Key0, <<"[^-a-zA-Z0-9_]">>, <<>>, [global])). + +map_type_with_alias_test() -> + Sc = #{ + roots => [ + {"root", hoconsc:mk(hoconsc:map(name, hoconsc:ref(foo)), #{aliases => [foo]})} + ], + fields => + #{foo => [{bar, hoconsc:mk(integer(), #{})}]} + }, + MapValue = #{<<"foo">> => #{<<"bar">> => 0}}, + NormalRecord = #{<<"root">> => MapValue}, + AliasedRecord = #{<<"foo">> => MapValue}, + ?assertEqual(NormalRecord, hocon_tconf:check_plain(Sc, NormalRecord)), + ?assertEqual(NormalRecord, hocon_tconf:check_plain(Sc, AliasedRecord)), + ok.