Skip to content

Commit

Permalink
Merge pull request #298 from thalesmg/no-doc
Browse files Browse the repository at this point in the history
feat: add `?IMPORTANCE_NO_DOC` importance
  • Loading branch information
thalesmg committed Jul 19, 2024
2 parents fc0451c + 250db44 commit c7cff4b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
4 changes: 3 additions & 1 deletion include/hoconsc.hrl
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,15 @@
-define(IMPORTANCE_MEDIUM, medium).
%% not important, usually only for advanced users
-define(IMPORTANCE_LOW, low).
%% hidden from documentation, but still returned by HTTP APIs and raw config
-define(IMPORTANCE_NO_DOC, no_doc).
%% hidden for normal users, only experts should need to care
-define(IMPORTANCE_HIDDEN, hidden).

%% The default importance level for a config item.
-define(DEFAULT_IMPORTANCE, ?IMPORTANCE_HIGH).
%% The default minimum importance level when dumping config schema
%% or filling config default values.
-define(DEFAULT_INCLUDE_IMPORTANCE_UP_FROM, ?IMPORTANCE_LOW).
-define(DEFAULT_INCLUDE_IMPORTANCE_UP_FROM, ?IMPORTANCE_NO_DOC).

-endif.
8 changes: 7 additions & 1 deletion src/hocon_schema.erl
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,12 @@
-type desc() :: iodata() | {desc, module(), desc_id()}.
-type union_selector() :: fun((all_union_members | {value, _}) -> type() | [type()]).
-type union_members() :: [type()] | union_selector().
-type importance() :: ?IMPORTANCE_HIGH | ?IMPORTANCE_MEDIUM | ?IMPORTANCE_LOW | ?IMPORTANCE_HIDDEN.
-type importance() ::
?IMPORTANCE_HIGH
| ?IMPORTANCE_MEDIUM
| ?IMPORTANCE_LOW
| ?IMPORTANCE_NO_DOC
| ?IMPORTANCE_HIDDEN.
%% primitive (or complex, but terminal) type
-type type() ::
typerefl:type()
Expand Down Expand Up @@ -572,6 +577,7 @@ is_hidden(Schema, Opts) ->
importance_num(DefinedImprotance) < importance_num(NeededImportance).

importance_num(?IMPORTANCE_HIDDEN) -> 0;
importance_num(?IMPORTANCE_NO_DOC) -> 5;
importance_num(?IMPORTANCE_LOW) -> 7;
importance_num(?IMPORTANCE_MEDIUM) -> 8;
importance_num(?IMPORTANCE_HIGH) -> 9.
Expand Down
16 changes: 13 additions & 3 deletions test/hocon_tconf_tests.erl
Original file line number Diff line number Diff line change
Expand Up @@ -1638,18 +1638,28 @@ no_default_value_fill_for_hidden_fields_test() ->
hoconsc:mk(
hoconsc:array(integer()),
#{default => [$d]}
)},
{"e",
hoconsc:mk(
hoconsc:array(integer()), #{
default => [$e],
importance => ?IMPORTANCE_NO_DOC
}
)}
]
}
},
?assertEqual(#{}, hocon_tconf:make_serializable(Sc, #{}, #{})),
C1 = #{<<"a">> => #{<<"d">> => [1]}},
C1 = #{<<"a">> => #{<<"d">> => [1], <<"e">> => [$e]}},
?assertEqual(C1, hocon_tconf:make_serializable(Sc, C1, #{})),
C2 = #{<<"a">> => #{<<"c">> => 2, <<"d">> => [1]}},
C2 = #{<<"a">> => #{<<"c">> => 2, <<"d">> => [1], <<"e">> => [$e]}},
?assertEqual(C2, hocon_tconf:make_serializable(Sc, C2, #{})),
C3 = #{<<"a">> => #{<<"c">> => 2}},
C4 = #{<<"a">> => #{<<"c">> => 2, <<"d">> => [$d]}},
C4 = #{<<"a">> => #{<<"c">> => 2, <<"d">> => [$d], <<"e">> => [$e]}},
?assertEqual(C4, hocon_tconf:make_serializable(Sc, C3, #{})),
C5 = #{<<"a">> => #{<<"e">> => [3]}},
C6 = #{<<"a">> => #{<<"d">> => [$d], <<"e">> => [3]}},
?assertEqual(C6, hocon_tconf:make_serializable(Sc, C5, #{})),
ok.

root_array_test_() ->
Expand Down

0 comments on commit c7cff4b

Please sign in to comment.