Skip to content

Commit 32a3d0b

Browse files
authored
Merge pull request #306 from thalesmg/computed-fields-opt
feat(computed fields): add option to avoid computing computed fields
2 parents 2780b00 + d44fe70 commit 32a3d0b

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

src/hocon_tconf.erl

+2
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,8 @@ map_one_field_non_hidden(FieldType, FieldSchema, FieldValue0, Opts) ->
524524

525525
maybe_computed(_FieldSchema, CheckedValue, #{make_serializable := true}) ->
526526
CheckedValue;
527+
maybe_computed(_FieldSchema, CheckedValue, #{computed_fields := false}) ->
528+
CheckedValue;
527529
maybe_computed(FieldSchema, #{} = CheckedValue, #{format := map} = Opts) ->
528530
case field_schema(FieldSchema, computed) of
529531
Fn when is_function(Fn, 2) ->

test/hocon_tconf_tests.erl

+20
Original file line numberDiff line numberDiff line change
@@ -2783,4 +2783,24 @@ computed_fields_test() ->
27832783
Res4 = #{} = hocon_tconf:check_plain(Sc, RichmapData, #{format => richmap}),
27842784
AssertNoComputed(Res4),
27852785

2786+
%% Option to not compute computed fields.
2787+
Res5 = hocon_tconf:check_plain(Sc, Data, #{computed_fields => false}),
2788+
?assertEqual(
2789+
#{
2790+
<<"root">> =>
2791+
#{
2792+
<<"bar">> => 123,
2793+
<<"baz">> =>
2794+
#{
2795+
<<"quux">> => 666
2796+
},
2797+
<<"bag">> =>
2798+
#{
2799+
<<"key">> => <<"value">>
2800+
}
2801+
}
2802+
},
2803+
Res5
2804+
),
2805+
27862806
ok.

0 commit comments

Comments
 (0)