Merge pull request #10167 from zhongwencool/fix-swagger-doc-500-crash
fix: swagger doc 500 crash
This commit is contained in:
commit
6a668c35db
|
@ -162,7 +162,7 @@ gen_schema_json(Dir, I18nFile, SchemaModule, Lang) ->
|
|||
ok = file:write_file(SchemaJsonFile, IoData).
|
||||
|
||||
gen_api_schema_json(Dir, I18nFile, Lang) ->
|
||||
emqx_dashboard:init_i18n(I18nFile, Lang),
|
||||
emqx_dashboard:init_i18n(I18nFile, list_to_binary(Lang)),
|
||||
gen_api_schema_json_hotconf(Dir, Lang),
|
||||
gen_api_schema_json_bridge(Dir, Lang),
|
||||
emqx_dashboard:clear_i18n().
|
||||
|
|
|
@ -133,8 +133,8 @@ get_i18n() ->
|
|||
application:get_env(emqx_dashboard, i18n).
|
||||
|
||||
init_i18n(File, Lang) when is_atom(Lang) ->
|
||||
init_i18n(File, atom_to_list(Lang));
|
||||
init_i18n(File, Lang) when is_list(Lang) ->
|
||||
init_i18n(File, atom_to_binary(Lang));
|
||||
init_i18n(File, Lang) when is_binary(Lang) ->
|
||||
Cache = hocon_schema:new_desc_cache(File),
|
||||
application:set_env(emqx_dashboard, i18n, #{lang => Lang, cache => Cache}).
|
||||
|
||||
|
|
|
@ -155,6 +155,18 @@ t_rest_api(_Config) ->
|
|||
emqx_dashboard_admin:add_user(<<"admin">>, Password, <<"administrator">>),
|
||||
ok.
|
||||
|
||||
t_swagger_json(_Config) ->
|
||||
Url = ?HOST ++ "/api-docs/swagger.json",
|
||||
%% with auth
|
||||
Auth = auth_header_(<<"admin">>, <<"public_www1">>),
|
||||
{ok, 200, Body1} = request_api(get, Url, Auth),
|
||||
?assert(jsx:is_json(Body1)),
|
||||
%% without auth
|
||||
{ok, {{"HTTP/1.1", 200, "OK"}, _Headers, Body2}} =
|
||||
httpc:request(get, {Url, []}, [], [{body_format, binary}]),
|
||||
?assertEqual(Body1, Body2),
|
||||
ok.
|
||||
|
||||
t_cli(_Config) ->
|
||||
[mria:dirty_delete(?ADMIN, Admin) || Admin <- mnesia:dirty_all_keys(?ADMIN)],
|
||||
emqx_dashboard_cli:admins(["add", "username", "password_ww2"]),
|
||||
|
|
Loading…
Reference in New Issue