فهرست منبع

refactor: delete default type converter for dashboard schema json

prior to this commit, dashboard scheam json type conversion
has a 'fallback' type for all unknown types, which is 'string'

this commit removes this fallback and add all possible types
to the function clauses.

also, some of the old types which are no longer in use
are deleted from both swagger spec converter and dashboard
sechema converter
Zaiming (Stone) Shi 2 سال پیش
والد
کامیت
2fda91ec59
2فایلهای تغییر یافته به همراه9 افزوده شده و 33 حذف شده
  1. 9 15
      apps/emqx_conf/src/emqx_conf.erl
  2. 0 18
      apps/emqx_dashboard/src/emqx_dashboard_swagger.erl

+ 9 - 15
apps/emqx_conf/src/emqx_conf.erl

@@ -305,10 +305,6 @@ hocon_schema_to_spec(?UNION(Types, _DisplayName), LocalModule) ->
 hocon_schema_to_spec(Atom, _LocalModule) when is_atom(Atom) ->
     {#{type => enum, symbols => [Atom]}, []}.
 
-typename_to_spec("user_id_type()", _Mod) ->
-    #{type => enum, symbols => [clientid, username]};
-typename_to_spec("term()", _Mod) ->
-    #{type => string};
 typename_to_spec("boolean()", _Mod) ->
     #{type => boolean};
 typename_to_spec("binary()", _Mod) ->
@@ -317,6 +313,8 @@ typename_to_spec("float()", _Mod) ->
     #{type => number};
 typename_to_spec("integer()", _Mod) ->
     #{type => number};
+typename_to_spec("pos_integer()", _Mod) ->
+    #{type => integer};
 typename_to_spec("non_neg_integer()", _Mod) ->
     #{type => number, minimum => 0};
 typename_to_spec("number()", _Mod) ->
@@ -355,26 +353,22 @@ typename_to_spec("comma_separated_list()", _Mod) ->
     #{type => comma_separated_string};
 typename_to_spec("comma_separated_atoms()", _Mod) ->
     #{type => comma_separated_string};
-typename_to_spec("capacity()", _Mod) ->
-    #{type => string};
-typename_to_spec("failure_strategy()", _Mod) ->
-    #{type => enum, symbols => [force, drop, throw]};
-typename_to_spec("initial()", _Mod) ->
-    #{type => string};
 typename_to_spec("map(" ++ Map, _Mod) ->
     [$) | _MapArgs] = lists:reverse(Map),
     #{type => object};
-typename_to_spec("#{" ++ _, Mod) ->
-    typename_to_spec("map()", Mod);
+typename_to_spec("port_number()", _Mod) ->
+    #{type => integer};
 typename_to_spec(Name, Mod) ->
     Spec = range(Name),
     Spec1 = remote_module_type(Spec, Name, Mod),
     Spec2 = typerefl_array(Spec1, Name, Mod),
     Spec3 = integer(Spec2, Name),
-    default_type(Spec3).
+    default_type(Mod, Name, Spec3).
 
-default_type(nomatch) -> #{type => string};
-default_type(Type) -> Type.
+default_type(Mod, Name, nomatch) ->
+    error({unknown_type, Mod, Name});
+default_type(_Mod, _Name, Type) ->
+    Type.
 
 range(Name) ->
     case string:split(Name, "..") of

+ 0 - 18
apps/emqx_dashboard/src/emqx_dashboard_swagger.erl

@@ -845,20 +845,10 @@ typename_to_spec("timeout_duration_ms()", _Mod) ->
     #{type => string, example => <<"32s">>};
 typename_to_spec("percent()", _Mod) ->
     #{type => number, example => <<"12%">>};
-typename_to_spec("file()", _Mod) ->
-    #{type => string, example => <<"/path/to/file">>};
 typename_to_spec("ip_port()", _Mod) ->
     #{type => string, example => <<"127.0.0.1:80">>};
 typename_to_spec("url()", _Mod) ->
     #{type => string, example => <<"http://127.0.0.1">>};
-typename_to_spec("timeout()", _Mod) ->
-    #{
-        <<"oneOf">> => [
-            #{type => string, example => infinity},
-            #{type => integer}
-        ],
-        example => infinity
-    };
 typename_to_spec("bytesize()", _Mod) ->
     #{type => string, example => <<"32MB">>};
 typename_to_spec("wordsize()", _Mod) ->
@@ -866,16 +856,8 @@ typename_to_spec("wordsize()", _Mod) ->
 typename_to_spec("map(" ++ Map, _Mod) ->
     [$) | _MapArgs] = lists:reverse(Map),
     #{type => object, example => #{}};
-typename_to_spec("service_account_json()", _Mod) ->
-    #{type => object, example => #{}};
-typename_to_spec("#{" ++ _, Mod) ->
-    typename_to_spec("map()", Mod);
 typename_to_spec("qos()", _Mod) ->
     #{type => integer, minimum => 0, maximum => 2, example => 0};
-typename_to_spec("{binary(), binary()}", _Mod) ->
-    #{type => object, example => #{}};
-typename_to_spec("{string(), string()}", _Mod) ->
-    #{type => object, example => #{}};
 typename_to_spec("comma_separated_list()", _Mod) ->
     #{type => string, example => <<"item1,item2">>};
 typename_to_spec("comma_separated_binary()", _Mod) ->