Skip to content

Commit

Permalink
fix: no alias for map fields
Browse files Browse the repository at this point in the history
  • Loading branch information
zmstone committed Sep 6, 2024
1 parent 9711619 commit 19b3382
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/hocon_tconf.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions test/hocon_tconf_tests.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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.

0 comments on commit 19b3382

Please sign in to comment.