Jelajahi Sumber

fix: authn bad examples

DDDHuang 3 tahun lalu
induk
melakukan
bf827cffa8

+ 25 - 20
apps/emqx_authn/src/emqx_authn_api.erl

@@ -1412,17 +1412,9 @@ authenticator_examples() ->
 
 status_metrics_example() ->
     #{
-        metrics => #{
-            matched => 0,
-            success => 0,
-            failed => 0,
-            rate => 0.0,
-            rate_last5m => 0.0,
-            rate_max => 0.0
-        },
-        node_metrics => [
-            #{
-                node => node(),
+        status_metrics => #{
+            summary => <<"Authn status metrics">>,
+            value => #{
                 metrics => #{
                     matched => 0,
                     success => 0,
@@ -1430,16 +1422,29 @@ status_metrics_example() ->
                     rate => 0.0,
                     rate_last5m => 0.0,
                     rate_max => 0.0
-                }
-            }
-        ],
-        status => connected,
-        node_status => [
-            #{
-                node => node(),
-                status => connected
+                },
+                node_metrics => [
+                    #{
+                        node => node(),
+                        metrics => #{
+                            matched => 0,
+                            success => 0,
+                            failed => 0,
+                            rate => 0.0,
+                            rate_last5m => 0.0,
+                            rate_max => 0.0
+                        }
+                    }
+                ],
+                status => connected,
+                node_status => [
+                    #{
+                        node => node(),
+                        status => connected
+                    }
+                ]
             }
-        ]
+        }
     }.
 
 request_user_create_examples() ->

+ 1 - 4
apps/emqx_dashboard/src/emqx_dashboard_swagger.erl

@@ -109,10 +109,7 @@ schema_with_example(Type, Example) ->
 
 -spec(schema_with_examples(hocon_schema:type(), map()) -> hocon_schema:field_schema_map()).
 schema_with_examples(Type, Examples) ->
-    %% Swagger can dynamically distinguish if there are multiple examples.
-    %% But explicitly declaring examples as plural
-    %% may cause some example structures to be incorrectly identified.
-    schema_with_example(Type, Examples).
+    hoconsc:mk(Type, #{examples => #{<<"examples">> => Examples}}).
 
 -spec(error_codes(list(atom())) -> hocon_schema:fields()).
 error_codes(Codes) ->