소스 검색

fix: dashboard ct failed

Zhongwen Deng 3 년 전
부모
커밋
f98cb972e2

+ 1 - 0
apps/emqx_dashboard/src/emqx_dashboard.erl

@@ -27,6 +27,7 @@
 
 
 -export([
 -export([
     init_i18n/2,
     init_i18n/2,
+    init_i18n/0,
     get_i18n/0,
     get_i18n/0,
     clear_i18n/0
     clear_i18n/0
 ]).
 ]).

+ 1 - 1
apps/emqx_dashboard/src/emqx_dashboard_schema.erl

@@ -197,7 +197,7 @@ cors(_) ->
 i18n_lang(type) -> ?ENUM([en, zh]);
 i18n_lang(type) -> ?ENUM([en, zh]);
 i18n_lang(default) -> zh;
 i18n_lang(default) -> zh;
 i18n_lang('readOnly') -> true;
 i18n_lang('readOnly') -> true;
-i18n_lang(desc) -> "i18n language";
+i18n_lang(desc) -> "Internationalization language support.";
 i18n_lang(_) -> undefined.
 i18n_lang(_) -> undefined.
 
 
 sc(Type, Meta) -> hoconsc:mk(Type, Meta).
 sc(Type, Meta) -> hoconsc:mk(Type, Meta).

+ 5 - 5
apps/emqx_dashboard/src/emqx_dashboard_swagger.erl

@@ -306,7 +306,7 @@ check_request_body(#{body := Body}, Spec, _Module, _CheckFun, false) when is_map
 %% tags, description, summary, security, deprecated
 %% tags, description, summary, security, deprecated
 meta_to_spec(Meta, Module, Options) ->
 meta_to_spec(Meta, Module, Options) ->
     {Params, Refs1} = parameters(maps:get(parameters, Meta, []), Module),
     {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),
     {Responses, Refs3} = responses(maps:get(responses, Meta, #{}), Module, Options),
     {
     {
         generate_method_desc(to_spec(Meta, Params, RequestBody, Responses)),
         generate_method_desc(to_spec(Meta, Params, RequestBody, Responses)),
@@ -424,11 +424,11 @@ resolve_desc(Key, Struct) ->
         false -> Desc
         false -> Desc
     end.
     end.
 
 
-request_body(#{content := _} = Content, _Module) ->
+request_body(#{content := _} = Content, _Module, _Options) ->
     {Content, []};
     {Content, []};
-request_body([], _Module) ->
+request_body([], _Module, _Options) ->
     {[], []};
     {[], []};
-request_body(Schema, Module) ->
+request_body(Schema, Module, Options) ->
     {{Props, Refs}, Examples} =
     {{Props, Refs}, Examples} =
         case hoconsc:is_schema(Schema) of
         case hoconsc:is_schema(Schema) of
             true ->
             true ->
@@ -436,7 +436,7 @@ request_body(Schema, Module) ->
                 SchemaExamples = hocon_schema:field_schema(Schema, examples),
                 SchemaExamples = hocon_schema:field_schema(Schema, examples),
                 {hocon_schema_to_spec(HoconSchema, Module), SchemaExamples};
                 {hocon_schema_to_spec(HoconSchema, Module), SchemaExamples};
             false ->
             false ->
-                {parse_object(Schema, Module, #{}), undefined}
+                {parse_object(Schema, Module, Options), undefined}
         end,
         end,
     {#{<<"content">> => content(Props, Examples)}, Refs}.
     {#{<<"content">> => content(Props, Examples)}, Refs}.
 
 

+ 22 - 0
apps/emqx_dashboard/test/emqx_swagger_parameter_SUITE.erl

@@ -4,6 +4,7 @@
 
 
 %% API
 %% API
 -export([paths/0, api_spec/0, schema/1, fields/1]).
 -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_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_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]).
 -export([t_in_path_trans/1, t_in_query_trans/1, t_in_mix_trans/1, t_ref_trans/1]).
@@ -26,6 +27,27 @@ groups() -> [
         t_in_path_trans_error, t_in_query_trans_error, t_in_mix_trans_error]}
         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) ->
 t_in_path(_Config) ->
     Expect =
     Expect =
         [#{description => <<"Indicates which sorts of issues to return">>,
         [#{description => <<"Indicates which sorts of issues to return">>,

+ 30 - 31
apps/emqx_dashboard/test/emqx_swagger_requestBody_SUITE.erl

@@ -3,41 +3,36 @@
 -behaviour(minirest_api).
 -behaviour(minirest_api).
 -behaviour(hocon_schema).
 -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("eunit/include/eunit.hrl").
 -include_lib("typerefl/include/types.hrl").
 -include_lib("typerefl/include/types.hrl").
 -include_lib("hocon/include/hoconsc.hrl").
 -include_lib("hocon/include/hoconsc.hrl").
 -import(hoconsc, [mk/2]).
 -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) ->
 t_object(_Config) ->
     Spec = #{
     Spec = #{
@@ -281,7 +276,7 @@ t_object_notrans(_Config) ->
     ?assertEqual(Body, ActualBody),
     ?assertEqual(Body, ActualBody),
     ok.
     ok.
 
 
-t_nest_object_trans(_Config) ->
+todo_t_nest_object_check(_Config) ->
     Path = "/nest/object",
     Path = "/nest/object",
     Body = #{
     Body = #{
         <<"timeout">> => "10m",
         <<"timeout">> => "10m",
@@ -306,7 +301,7 @@ t_nest_object_trans(_Config) ->
         body => #{<<"per_page">> => 10,
         body => #{<<"per_page">> => 10,
             <<"timeout">> => 600}
             <<"timeout">> => 600}
     },
     },
-    {ok, NewRequest} = trans_requestBody(Path, Body),
+    {ok, NewRequest} = check_requestBody(Path, Body),
     ?assertEqual(Expect, NewRequest),
     ?assertEqual(Expect, NewRequest),
     ok.
     ok.
 
 
@@ -487,6 +482,10 @@ trans_requestBody(Path, Body) ->
     trans_requestBody(Path, Body,
     trans_requestBody(Path, Body,
         fun emqx_dashboard_swagger:filter_check_request_and_translate_body/2).
         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) ->
 trans_requestBody(Path, Body, Filter) ->
     Meta = #{module => ?MODULE, method => post, path => Path},
     Meta = #{module => ?MODULE, method => post, path => Path},
     Request = #{bindings => #{}, query_string => #{}, body => Body},
     Request = #{bindings => #{}, query_string => #{}, body => Body},

+ 25 - 16
apps/emqx_dashboard/test/emqx_swagger_response_SUITE.erl

@@ -10,22 +10,31 @@
 -include_lib("hocon/include/hoconsc.hrl").
 -include_lib("hocon/include/hoconsc.hrl").
 -import(hoconsc, [mk/2]).
 -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) ->
 t_simple_binary(_config) ->
     Path = "/simple/bin",
     Path = "/simple/bin",