Просмотр исходного кода

chore(schema): use emqx_schema:qos() instead of union integer.

zhongwencool 4 лет назад
Родитель
Сommit
f5415589e9

+ 4 - 6
apps/emqx_auto_subscribe/src/emqx_auto_subscribe_schema.erl

@@ -35,12 +35,10 @@ fields("auto_subscribe") ->
 
 fields("topic") ->
     [ {topic, sc(binary(), #{example => topic_example()})}
-    , {qos, sc(hoconsc:union([typerefl:integer(0), typerefl:integer(1), typerefl:integer(2)]),
-        #{default => 0})}
-    , {rh, sc(hoconsc:union([typerefl:integer(0), typerefl:integer(1), typerefl:integer(2)]),
-        #{default => 0})}
-    , {rap, sc(hoconsc:union([typerefl:integer(0), typerefl:integer(1)]), #{default => 0})}
-    , {nl, sc(hoconsc:union([typerefl:integer(0), typerefl:integer(1)]), #{default => 0})}
+    , {qos, sc(emqx_schema:qos(), #{default => 0})}
+    , {rh, sc(range(0,2), #{default => 0})}
+    , {rap, sc(range(0, 1), #{default => 0})}
+    , {nl, sc(range(0, 1), #{default => 0})}
     ].
 
 topic_example() ->

+ 1 - 1
apps/emqx_connector/src/mqtt/emqx_connector_mqtt_schema.erl

@@ -236,7 +236,7 @@ Template with variables is allowed."""
     ].
 
 qos() ->
-    hoconsc:union([typerefl:integer(0), typerefl:integer(1), typerefl:integer(2), binary()]).
+    hoconsc:union([emqx_schema:qos(), binary()]).
 
 sc(Type, Meta) -> hoconsc:mk(Type, Meta).
 ref(Field) -> hoconsc:ref(?MODULE, Field).

+ 3 - 3
apps/emqx_gateway/src/emqx_gateway_schema.erl

@@ -189,7 +189,7 @@ The type of delivered coap message can be set to:<br>
 3. qos: Mapping from QoS type of received message, QoS0 -> non, QoS1,2 -> con"
            })}
     , {subscribe_qos,
-       sc(hoconsc:union([qos0, qos1, qos2, coap]),
+       sc(hoconsc:enum([qos0, qos1, qos2, coap]),
           #{ default => coap
            , desc =>
 "The Default QoS Level indicator for subscribe request.<br>
@@ -202,7 +202,7 @@ The indicator can be set to:
     * qos1: If the subscribe request is confirmable"
            })}
     , {publish_qos,
-       sc(hoconsc:union([qos0, qos1, qos2, coap]),
+       sc(hoconsc:enum([qos0, qos1, qos2, coap]),
           #{ default => coap
            , desc =>
 "The Default QoS Level indicator for publish request.<br>
@@ -356,7 +356,7 @@ notifyevents via this topic, if the client reports any resource changes"
 
 fields(translator) ->
     [ {topic, sc(binary(), #{nullable => false})}
-    , {qos, sc(range(0, 2), #{default => 0})}
+    , {qos, sc(emqx_schema:qos(), #{default => 0})}
     ];
 
 fields(udp_listeners) ->

+ 1 - 2
apps/emqx_rule_engine/src/emqx_rule_api_schema.erl

@@ -207,8 +207,7 @@ fields("ctx_disconnected") ->
     ].
 
 qos() ->
-    {"qos", sc(hoconsc:union([typerefl:integer(0), typerefl:integer(1), typerefl:integer(2)]),
-        #{desc => "The Message QoS"})}.
+    {"qos", sc(emqx_schema:qos(), #{desc => "The Message QoS"})}.
 
 rule_id() ->
     {"id", sc(binary(),

+ 1 - 1
apps/emqx_rule_engine/src/emqx_rule_engine_schema.erl

@@ -194,7 +194,7 @@ outputs() ->
     ].
 
 qos() ->
-    hoconsc:union([typerefl:integer(0), typerefl:integer(1), typerefl:integer(2), binary()]).
+    hoconsc:union([emqx_schema:qos(), binary()]).
 
 validate_sql(Sql) ->
     case emqx_rule_sqlparser:parse(Sql) of

+ 1 - 1
apps/emqx_slow_subs/src/emqx_slow_subs_schema.erl

@@ -30,7 +30,7 @@ fields("slow_subs") ->
           "publish is disabled if set to 0s."
          )}
     , {notice_qos,
-       sc(range(0, 2),
+       sc(emqx_schema:qos(),
           0,
           "QoS of notification message in notice topic")}
     , {notice_batch_size,