fix(schema): Ensure enum is atom or int.

This commit is contained in:
Zhongwen Deng 2022-02-22 21:24:09 +08:00
parent d35ff9303a
commit 574bbafc9b
3 changed files with 6 additions and 4 deletions

View File

@ -425,7 +425,7 @@ hocon_schema_to_spec(Atom, _LocalModule) when is_atom(Atom) ->
%% todo: Find a way to fetch enum value from user_id_type(). %% todo: Find a way to fetch enum value from user_id_type().
typename_to_spec("user_id_type()", _Mod) -> #{type => string, enum => [clientid, username]}; typename_to_spec("user_id_type()", _Mod) -> #{type => string, enum => [clientid, username]};
typename_to_spec("term()", _Mod) -> #{type => string, example => "term"}; typename_to_spec("term()", _Mod) -> #{type => string, example => "any"};
typename_to_spec("boolean()", _Mod) -> #{type => boolean, example => true}; typename_to_spec("boolean()", _Mod) -> #{type => boolean, example => true};
typename_to_spec("binary()", _Mod) -> #{type => string, example => <<"binary-example">>}; typename_to_spec("binary()", _Mod) -> #{type => string, example => <<"binary-example">>};
typename_to_spec("float()", _Mod) -> #{type => number, example => 3.14159}; typename_to_spec("float()", _Mod) -> #{type => number, example => 3.14159};
@ -444,7 +444,6 @@ typename_to_spec("epoch_millisecond()", _Mod) ->
#{type => integer, example => 1640995200000, desc => <<"epoch-millisecond">>}, #{type => integer, example => 1640995200000, desc => <<"epoch-millisecond">>},
#{type => string, example => <<"2022-01-01T00:00:00.000Z">>, format => <<"date-time">>}] #{type => string, example => <<"2022-01-01T00:00:00.000Z">>, format => <<"date-time">>}]
}; };
typename_to_spec("unicode_binary()", _Mod) -> #{type => string, example => <<"unicode-binary">>};
typename_to_spec("duration()", _Mod) -> #{type => string, example => <<"12m">>}; typename_to_spec("duration()", _Mod) -> #{type => string, example => <<"12m">>};
typename_to_spec("duration_s()", _Mod) -> #{type => string, example => <<"1h">>}; typename_to_spec("duration_s()", _Mod) -> #{type => string, example => <<"1h">>};
typename_to_spec("duration_ms()", _Mod) -> #{type => string, example => <<"32s">>}; typename_to_spec("duration_ms()", _Mod) -> #{type => string, example => <<"32s">>};

View File

@ -56,7 +56,10 @@ schema("/configs") ->
} }
}; };
schema("/configs_reset/:rootname") -> schema("/configs_reset/:rootname") ->
Paths = lists:map(fun({Path, _}) -> Path end, config_list(?EXCLUDES)), Paths = lists:map(
fun({Path, _})when is_atom(Path) -> Path;
({Path, _}) when is_list(Path) -> list_to_atom(Path)
end, config_list(?EXCLUDES)),
#{ #{
'operationId' => config_reset, 'operationId' => config_reset,
post => #{ post => #{

View File

@ -54,7 +54,7 @@ fields("rule_info") ->
%% TODO: we can delete this API if the Dashboard not denpends on it %% TODO: we can delete this API if the Dashboard not denpends on it
fields("rule_events") -> fields("rule_events") ->
ETopics = [emqx_rule_events:event_topic(E) || E <- emqx_rule_events:event_names()], ETopics = [binary_to_atom(emqx_rule_events:event_topic(E)) || E <- emqx_rule_events:event_names()],
[ {"event", sc(hoconsc:enum(ETopics), #{desc => "The event topics", nullable => false})} [ {"event", sc(hoconsc:enum(ETopics), #{desc => "The event topics", nullable => false})}
, {"title", sc(binary(), #{desc => "The title", example => "some title"})} , {"title", sc(binary(), #{desc => "The title", example => "some title"})}
, {"description", sc(binary(), #{desc => "The description", example => "some desc"})} , {"description", sc(binary(), #{desc => "The description", example => "some desc"})}