Skip to content

Commit

Permalink
fix: dashboard ct failed
Browse files Browse the repository at this point in the history
  • Loading branch information
zhongwencool committed Apr 15, 2022
1 parent 164754b commit f98cb97
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 53 deletions.
1 change: 1 addition & 0 deletions apps/emqx_dashboard/src/emqx_dashboard.erl
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

-export([
init_i18n/2,
init_i18n/0,
get_i18n/0,
clear_i18n/0
]).
Expand Down
2 changes: 1 addition & 1 deletion apps/emqx_dashboard/src/emqx_dashboard_schema.erl
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ cors(_) ->
i18n_lang(type) -> ?ENUM([en, zh]);
i18n_lang(default) -> zh;
i18n_lang('readOnly') -> true;
i18n_lang(desc) -> "i18n language";
i18n_lang(desc) -> "Internationalization language support.";
i18n_lang(_) -> undefined.

sc(Type, Meta) -> hoconsc:mk(Type, Meta).
10 changes: 5 additions & 5 deletions apps/emqx_dashboard/src/emqx_dashboard_swagger.erl
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ check_request_body(#{body := Body}, Spec, _Module, _CheckFun, false) when is_map
%% tags, description, summary, security, deprecated
meta_to_spec(Meta, Module, Options) ->
{Params, Refs1} = parameters(maps:get(parameters, Meta, []), Module),
{RequestBody, Refs2} = request_body(maps:get('requestBody', Meta, []), Module),
{RequestBody, Refs2} = request_body(maps:get('requestBody', Meta, []), Module, Options),
{Responses, Refs3} = responses(maps:get(responses, Meta, #{}), Module, Options),
{
generate_method_desc(to_spec(Meta, Params, RequestBody, Responses)),
Expand Down Expand Up @@ -424,19 +424,19 @@ resolve_desc(Key, Struct) ->
false -> Desc
end.

request_body(#{content := _} = Content, _Module) ->
request_body(#{content := _} = Content, _Module, _Options) ->
{Content, []};
request_body([], _Module) ->
request_body([], _Module, _Options) ->
{[], []};
request_body(Schema, Module) ->
request_body(Schema, Module, Options) ->
{{Props, Refs}, Examples} =
case hoconsc:is_schema(Schema) of
true ->
HoconSchema = hocon_schema:field_schema(Schema, type),
SchemaExamples = hocon_schema:field_schema(Schema, examples),
{hocon_schema_to_spec(HoconSchema, Module), SchemaExamples};
false ->
{parse_object(Schema, Module, #{}), undefined}
{parse_object(Schema, Module, Options), undefined}
end,
{#{<<"content">> => content(Props, Examples)}, Refs}.

Expand Down
22 changes: 22 additions & 0 deletions apps/emqx_dashboard/test/emqx_swagger_parameter_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

%% API
-export([paths/0, api_spec/0, schema/1, fields/1]).
-export([init_per_suite/1, end_per_suite/1]).
-export([t_in_path/1, t_in_query/1, t_in_mix/1, t_without_in/1, t_ref/1, t_public_ref/1]).
-export([t_require/1, t_nullable/1, t_method/1, t_api_spec/1]).
-export([t_in_path_trans/1, t_in_query_trans/1, t_in_mix_trans/1, t_ref_trans/1]).
Expand All @@ -26,6 +27,27 @@ groups() -> [
t_in_path_trans_error, t_in_query_trans_error, t_in_mix_trans_error]}
].

init_per_suite(Config) ->
mria:start(),
application:load(emqx_dashboard),
emqx_common_test_helpers:start_apps([emqx_conf, emqx_dashboard], fun set_special_configs/1),
emqx_dashboard:init_i18n(),
Config.

set_special_configs(emqx_dashboard) ->
emqx_dashboard_api_test_helpers:set_default_config(),
ok;
set_special_configs(_) ->
ok.

end_per_suite(Config) ->
end_suite(),
Config.

end_suite() ->
application:unload(emqx_management),
emqx_common_test_helpers:stop_apps([emqx_dashboard]).

t_in_path(_Config) ->
Expect =
[#{description => <<"Indicates which sorts of issues to return">>,
Expand Down
61 changes: 30 additions & 31 deletions apps/emqx_dashboard/test/emqx_swagger_requestBody_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -3,41 +3,36 @@
-behaviour(minirest_api).
-behaviour(hocon_schema).

%% API
-export([paths/0, api_spec/0, schema/1, fields/1]).
-export([t_object/1, t_nest_object/1, t_api_spec/1,
t_local_ref/1, t_remote_ref/1, t_bad_ref/1, t_none_ref/1, t_nest_ref/1,
t_ref_array_with_key/1, t_ref_array_without_key/1, t_sub_fields/1
]).
-export([
t_object_trans/1, t_object_notrans/1, t_nest_object_trans/1, t_local_ref_trans/1,
t_remote_ref_trans/1, t_nest_ref_trans/1,
t_ref_array_with_key_trans/1, t_ref_array_without_key_trans/1,
t_ref_trans_error/1, t_object_trans_error/1
]).
-export([all/0, suite/0, groups/0]).
-compile(nowarn_export_all).
-compile(export_all).

-include_lib("eunit/include/eunit.hrl").
-include_lib("typerefl/include/types.hrl").
-include_lib("hocon/include/hoconsc.hrl").
-import(hoconsc, [mk/2]).

all() -> [{group, spec}, {group, validation}].

suite() -> [{timetrap, {minutes, 1}}].
groups() -> [
{spec, [parallel], [
t_api_spec, t_object, t_nest_object,
t_local_ref, t_remote_ref, t_bad_ref, t_none_ref,
t_ref_array_with_key, t_ref_array_without_key, t_nest_ref]},
{validation, [parallel],
[
t_object_trans, t_object_notrans, t_local_ref_trans, t_remote_ref_trans,
t_ref_array_with_key_trans, t_ref_array_without_key_trans, t_nest_ref_trans,
t_ref_trans_error, t_object_trans_error
%% t_nest_object_trans,
]}
].
all() -> emqx_common_test_helpers:all(?MODULE).

init_per_suite(Config) ->
mria:start(),
application:load(emqx_dashboard),
emqx_common_test_helpers:start_apps([emqx_conf, emqx_dashboard], fun set_special_configs/1),
emqx_dashboard:init_i18n(),
Config.

set_special_configs(emqx_dashboard) ->
emqx_dashboard_api_test_helpers:set_default_config(),
ok;
set_special_configs(_) ->
ok.

end_per_suite(Config) ->
end_suite(),
Config.

end_suite() ->
application:unload(emqx_management),
emqx_common_test_helpers:stop_apps([emqx_dashboard]).

t_object(_Config) ->
Spec = #{
Expand Down Expand Up @@ -281,7 +276,7 @@ t_object_notrans(_Config) ->
?assertEqual(Body, ActualBody),
ok.

t_nest_object_trans(_Config) ->
todo_t_nest_object_check(_Config) ->
Path = "/nest/object",
Body = #{
<<"timeout">> => "10m",
Expand All @@ -306,7 +301,7 @@ t_nest_object_trans(_Config) ->
body => #{<<"per_page">> => 10,
<<"timeout">> => 600}
},
{ok, NewRequest} = trans_requestBody(Path, Body),
{ok, NewRequest} = check_requestBody(Path, Body),
?assertEqual(Expect, NewRequest),
ok.

Expand Down Expand Up @@ -487,6 +482,10 @@ trans_requestBody(Path, Body) ->
trans_requestBody(Path, Body,
fun emqx_dashboard_swagger:filter_check_request_and_translate_body/2).

check_requestBody(Path, Body) ->
trans_requestBody(Path, Body,
fun emqx_dashboard_swagger:filter_check_request/2).

trans_requestBody(Path, Body, Filter) ->
Meta = #{module => ?MODULE, method => post, path => Path},
Request = #{bindings => #{}, query_string => #{}, body => Body},
Expand Down
41 changes: 25 additions & 16 deletions apps/emqx_dashboard/test/emqx_swagger_response_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,31 @@
-include_lib("hocon/include/hoconsc.hrl").
-import(hoconsc, [mk/2]).

-export([all/0, suite/0, groups/0]).
-export([paths/0, api_spec/0, schema/1, fields/1]).
-export([t_simple_binary/1, t_object/1, t_nest_object/1, t_empty/1, t_error/1,
t_raw_local_ref/1, t_raw_remote_ref/1, t_hocon_schema_function/1, t_complicated_type/1,
t_local_ref/1, t_remote_ref/1, t_bad_ref/1, t_none_ref/1, t_nest_ref/1, t_sub_fields/1,
t_ref_array_with_key/1, t_ref_array_without_key/1, t_api_spec/1]).

all() -> [{group, spec}].
suite() -> [{timetrap, {minutes, 1}}].
groups() -> [
{spec, [parallel], [
t_api_spec, t_simple_binary, t_object, t_nest_object, t_error, t_complicated_type,
t_raw_local_ref, t_raw_remote_ref, t_empty, t_hocon_schema_function,
t_local_ref, t_remote_ref, t_bad_ref, t_none_ref, t_sub_fields,
t_ref_array_with_key, t_ref_array_without_key, t_nest_ref]}
].
-compile(nowarn_export_all).
-compile(export_all).

all() -> emqx_common_test_helpers:all(?MODULE).

init_per_suite(Config) ->
mria:start(),
application:load(emqx_dashboard),
emqx_common_test_helpers:start_apps([emqx_conf, emqx_dashboard], fun set_special_configs/1),
emqx_dashboard:init_i18n(),
Config.

set_special_configs(emqx_dashboard) ->
emqx_dashboard_api_test_helpers:set_default_config(),
ok;
set_special_configs(_) ->
ok.

end_per_suite(Config) ->
end_suite(),
Config.

end_suite() ->
application:unload(emqx_management),
emqx_common_test_helpers:stop_apps([emqx_dashboard]).

t_simple_binary(_config) ->
Path = "/simple/bin",
Expand Down

0 comments on commit f98cb97

Please sign in to comment.