소스 검색

refactor(dashboard_schema): no need to translate labels

the trans_label implementation was ugly, it compares an anonymous
function to check if the label should be translated.

since we have stopped generating i18n message ids for dashboard
schema, this entire function is now stale, so this function
is deleted.
zmstone 1 년 전
부모
커밋
df458b98d7
1개의 변경된 파일5개의 추가작업 그리고 31개의 파일을 삭제
  1. 5 31
      apps/emqx_dashboard/src/emqx_dashboard_swagger.erl

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

@@ -652,19 +652,6 @@ trans_required(Spec, true, _) -> Spec#{required => true};
 trans_required(Spec, _, path) -> Spec#{required => true};
 trans_required(Spec, _, path) -> Spec#{required => true};
 trans_required(Spec, _, _) -> Spec.
 trans_required(Spec, _, _) -> Spec.
 
 
-trans_desc(Init, Hocon, Func, Name, Options) ->
-    Spec0 = trans_description(Init, Hocon, Options),
-    case Func =:= fun hocon_schema_to_spec/2 of
-        true ->
-            Spec0;
-        false ->
-            Spec1 = trans_label(Spec0, Hocon, Name, Options),
-            case Spec1 of
-                #{description := _} -> Spec1;
-                _ -> Spec1
-            end
-    end.
-
 trans_description(Spec, Hocon, Options) ->
 trans_description(Spec, Hocon, Options) ->
     Desc =
     Desc =
         case desc_struct(Hocon) of
         case desc_struct(Hocon) of
@@ -702,19 +689,6 @@ get_i18n_text(Lang, Namespace, Id, Tag, Default) ->
 get_lang(#{i18n_lang := Lang}) -> Lang;
 get_lang(#{i18n_lang := Lang}) -> Lang;
 get_lang(_) -> emqx:get_config([dashboard, i18n_lang]).
 get_lang(_) -> emqx:get_config([dashboard, i18n_lang]).
 
 
-trans_label(Spec, Hocon, Default, Options) ->
-    Label =
-        case desc_struct(Hocon) of
-            ?DESC(_, _) = Struct -> get_i18n(<<"label">>, Struct, Default, Options);
-            _ -> Default
-        end,
-    case Label =:= undefined of
-        true ->
-            Spec;
-        false ->
-            Spec#{label => Label}
-    end.
-
 desc_struct(Hocon) ->
 desc_struct(Hocon) ->
     R =
     R =
         case hocon_schema:field_schema(Hocon, desc) of
         case hocon_schema:field_schema(Hocon, desc) of
@@ -772,7 +746,7 @@ response(Status, #{content := _} = Content, {Acc, RefsAcc, Module, Options}) ->
 response(Status, ?REF(StructName), {Acc, RefsAcc, Module, Options}) ->
 response(Status, ?REF(StructName), {Acc, RefsAcc, Module, Options}) ->
     response(Status, ?R_REF(Module, StructName), {Acc, RefsAcc, Module, Options});
     response(Status, ?R_REF(Module, StructName), {Acc, RefsAcc, Module, Options});
 response(Status, ?R_REF(_Mod, _Name) = RRef, {Acc, RefsAcc, Module, Options}) ->
 response(Status, ?R_REF(_Mod, _Name) = RRef, {Acc, RefsAcc, Module, Options}) ->
-    SchemaToSpec = schema_converter(Options),
+    SchemaToSpec = get_schema_converter(Options),
     {Spec, Refs} = SchemaToSpec(RRef, Module),
     {Spec, Refs} = SchemaToSpec(RRef, Module),
     Content = content(Spec),
     Content = content(Spec),
     {
     {
@@ -910,7 +884,7 @@ parse_object(PropList = [_ | _], Module, Options) when is_list(PropList) ->
 parse_object(Other, Module, Options) ->
 parse_object(Other, Module, Options) ->
     erlang:throw(
     erlang:throw(
         {error, #{
         {error, #{
-            msg => <<"Object only supports not empty proplists">>,
+            msg => <<"Object only supports non-empty fields list">>,
             args => Other,
             args => Other,
             module => Module,
             module => Module,
             options => Options
             options => Options
@@ -950,10 +924,10 @@ parse_object_loop([{Name, Hocon} | Rest], Module, Options, Props, Required, Refs
         true ->
         true ->
             HoconType = hocon_schema:field_schema(Hocon, type),
             HoconType = hocon_schema:field_schema(Hocon, type),
             Init0 = init_prop([default | ?DEFAULT_FIELDS], #{}, Hocon),
             Init0 = init_prop([default | ?DEFAULT_FIELDS], #{}, Hocon),
-            SchemaToSpec = schema_converter(Options),
+            SchemaToSpec = get_schema_converter(Options),
             Init = maps:remove(
             Init = maps:remove(
                 summary,
                 summary,
-                trans_desc(Init0, Hocon, SchemaToSpec, NameBin, Options)
+                trans_description(Init0, Hocon, Options)
             ),
             ),
             {Prop, Refs1} = SchemaToSpec(HoconType, Module),
             {Prop, Refs1} = SchemaToSpec(HoconType, Module),
             NewRequiredAcc =
             NewRequiredAcc =
@@ -1002,7 +976,7 @@ to_ref(Mod, StructName, Acc, RefsAcc) ->
     Ref = #{<<"$ref">> => ?TO_COMPONENTS_PARAM(Mod, StructName)},
     Ref = #{<<"$ref">> => ?TO_COMPONENTS_PARAM(Mod, StructName)},
     {[Ref | Acc], [{Mod, StructName, parameter} | RefsAcc]}.
     {[Ref | Acc], [{Mod, StructName, parameter} | RefsAcc]}.
 
 
-schema_converter(Options) ->
+get_schema_converter(Options) ->
     maps:get(schema_converter, Options, fun hocon_schema_to_spec/2).
     maps:get(schema_converter, Options, fun hocon_schema_to_spec/2).
 
 
 hocon_error_msg(Reason) ->
 hocon_error_msg(Reason) ->