diff --git a/src/hocon_schema.erl b/src/hocon_schema.erl index cacf1f6..13dceca 100644 --- a/src/hocon_schema.erl +++ b/src/hocon_schema.erl @@ -467,6 +467,7 @@ str(A) when is_atom(A) -> atom_to_list(A); str(S) when is_list(S) -> S. bin(A) when is_atom(A) -> atom_to_binary(A, utf8); +bin(I) when is_integer(I) -> integer_to_binary(I); bin(S) -> unicode:characters_to_binary(S, utf8). %% get type validation stack. diff --git a/test/hocon_schema_json_tests.erl b/test/hocon_schema_json_tests.erl index ec579e5..892a20c 100644 --- a/test/hocon_schema_json_tests.erl +++ b/test/hocon_schema_json_tests.erl @@ -66,6 +66,61 @@ unique_field_names_test() -> gen(Sc) ). +enum_test() -> + Structs = #{ + foo => [ + {number, hoconsc:mk(hoconsc:enum([1, 2]), #{default => 1})}, + {atom, hoconsc:mk(hoconsc:enum([test1, test2]), #{default => test2})} + ] + }, + Sc = #{ + roots => [{"root", hoconsc:mk(hoconsc:ref(foo), #{required => false})}], + fields => Structs + }, + Json = gen(Sc), + ?assertMatch( + [ + #{ + fields := + [ + #{ + name := <<"root">>, + type := #{kind := struct} + } + ] + }, + #{ + fields := + [ + #{ + default := #{hocon := <<"1">>}, + name := <<"number">>, + type := + #{ + symbols := [<<"1">>, <<"2">>], + kind := enum + }, + raw_default := 1 + }, + #{ + default := + #{hocon := <<"test2">>}, + name := <<"atom">>, + type := + #{ + symbols := [<<"test1">>, <<"test2">>], + kind := enum + }, + raw_default := test2 + } + ], + paths := [<<"root">>], + full_name := <<"foo">> + } + ], + Json + ). + unique_field_name_with_aliases_test() -> Structs = #{ foo => [