From ff5916e33fc5b15ade26e71299da21745cb2cae2 Mon Sep 17 00:00:00 2001 From: "Zaiming (Stone) Shi" Date: Fri, 10 Nov 2023 22:19:37 +0100 Subject: [PATCH 1/8] docs: fix bad html tag --- apps/emqx_dashboard/src/emqx_dashboard_swagger.erl | 11 ----------- rel/i18n/emqx_bridge_api.hocon | 2 +- rel/i18n/emqx_bridge_cassandra.hocon | 2 +- rel/i18n/emqx_bridge_clickhouse.hocon | 2 +- rel/i18n/emqx_bridge_dynamo.hocon | 2 +- rel/i18n/emqx_bridge_gcp_pubsub.hocon | 2 +- rel/i18n/emqx_bridge_greptimedb.hocon | 6 +++--- rel/i18n/emqx_bridge_greptimedb_connector.hocon | 4 ++-- rel/i18n/emqx_bridge_hstreamdb.hocon | 2 +- rel/i18n/emqx_bridge_influxdb.hocon | 6 +++--- rel/i18n/emqx_bridge_influxdb_connector.hocon | 4 ++-- rel/i18n/emqx_bridge_kinesis.hocon | 2 +- rel/i18n/emqx_bridge_mysql.hocon | 2 +- rel/i18n/emqx_bridge_oracle.hocon | 2 +- rel/i18n/emqx_bridge_pgsql.hocon | 2 +- rel/i18n/emqx_bridge_redis.hocon | 2 +- rel/i18n/emqx_bridge_rocketmq.hocon | 2 +- rel/i18n/emqx_bridge_sqlserver.hocon | 2 +- rel/i18n/emqx_bridge_tdengine.hocon | 2 +- rel/i18n/emqx_schema.hocon | 8 ++++---- 20 files changed, 28 insertions(+), 39 deletions(-) diff --git a/apps/emqx_dashboard/src/emqx_dashboard_swagger.erl b/apps/emqx_dashboard/src/emqx_dashboard_swagger.erl index 4a316e248..091e85da0 100644 --- a/apps/emqx_dashboard/src/emqx_dashboard_swagger.erl +++ b/apps/emqx_dashboard/src/emqx_dashboard_swagger.erl @@ -851,17 +851,8 @@ 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("write_syntax()", _Mod) -> - #{ - type => string, - example => - <<"${topic},clientid=${clientid}", " ", "payload=${payload},", - "${clientid}_int_value=${payload.int_key}i,", "bool=${payload.bool}">> - }; typename_to_spec("url()", _Mod) -> #{type => string, example => <<"http://127.0.0.1">>}; -typename_to_spec("connect_timeout()", Mod) -> - typename_to_spec("timeout()", Mod); typename_to_spec("timeout()", _Mod) -> #{ <<"oneOf">> => [ @@ -916,8 +907,6 @@ typename_to_spec("json_binary()", _Mod) -> #{type => string, example => <<"{\"a\": [1,true]}">>}; typename_to_spec("port_number()", _Mod) -> range("1..65535"); -typename_to_spec("secret_access_key()", _Mod) -> - #{type => string, example => <<"TW8dPwmjpjJJuLW....">>}; typename_to_spec(Name, Mod) -> try_convert_to_spec(Name, Mod, [ fun try_remote_module_type/2, diff --git a/rel/i18n/emqx_bridge_api.hocon b/rel/i18n/emqx_bridge_api.hocon index 8b7950cdc..3567f03cc 100644 --- a/rel/i18n/emqx_bridge_api.hocon +++ b/rel/i18n/emqx_bridge_api.hocon @@ -49,7 +49,7 @@ desc_api8.label: """Node Bridge Operate""" desc_api9.desc: -"""Test creating a new bridge by given ID
+"""Test creating a new bridge by given ID
The ID must be of format '{type}:{name}'""" desc_api9.label: diff --git a/rel/i18n/emqx_bridge_cassandra.hocon b/rel/i18n/emqx_bridge_cassandra.hocon index d598d3921..a96315340 100644 --- a/rel/i18n/emqx_bridge_cassandra.hocon +++ b/rel/i18n/emqx_bridge_cassandra.hocon @@ -32,7 +32,7 @@ desc_type.label: local_topic.desc: """The MQTT topic filter to be forwarded to Cassandra. All MQTT 'PUBLISH' messages with the topic -matching the local_topic will be forwarded.
+matching the local_topic will be forwarded.
NOTE: if this bridge is used as the action of a rule (EMQX rule engine), and also local_topic is configured, then both the data got from the rule and the MQTT messages that match local_topic will be forwarded.""" diff --git a/rel/i18n/emqx_bridge_clickhouse.hocon b/rel/i18n/emqx_bridge_clickhouse.hocon index 726d1eb7c..7d1961f98 100644 --- a/rel/i18n/emqx_bridge_clickhouse.hocon +++ b/rel/i18n/emqx_bridge_clickhouse.hocon @@ -32,7 +32,7 @@ desc_type.label: local_topic.desc: """The MQTT topic filter to be forwarded to Clickhouse. All MQTT 'PUBLISH' messages with the topic -matching the local_topic will be forwarded.
+matching the local_topic will be forwarded.
NOTE: if this bridge is used as the action of a rule (EMQX rule engine), and also local_topic is configured, then both the data got from the rule and the MQTT messages that match local_topic will be forwarded.""" diff --git a/rel/i18n/emqx_bridge_dynamo.hocon b/rel/i18n/emqx_bridge_dynamo.hocon index 417b43c0c..a014aae9f 100644 --- a/rel/i18n/emqx_bridge_dynamo.hocon +++ b/rel/i18n/emqx_bridge_dynamo.hocon @@ -26,7 +26,7 @@ desc_type.label: local_topic.desc: """The MQTT topic filter to be forwarded to DynamoDB. All MQTT `PUBLISH` messages with the topic -matching the `local_topic` will be forwarded.
+matching the `local_topic` will be forwarded.
NOTE: if this bridge is used as the action of a rule (EMQX rule engine), and also `local_topic` is configured, then both the data got from the rule and the MQTT messages that match `local_topic` will be forwarded.""" diff --git a/rel/i18n/emqx_bridge_gcp_pubsub.hocon b/rel/i18n/emqx_bridge_gcp_pubsub.hocon index b5dffec1f..68a6f8578 100644 --- a/rel/i18n/emqx_bridge_gcp_pubsub.hocon +++ b/rel/i18n/emqx_bridge_gcp_pubsub.hocon @@ -26,7 +26,7 @@ desc_type.label: local_topic.desc: """The MQTT topic filter to be forwarded to GCP PubSub. All MQTT 'PUBLISH' messages with the topic -matching `local_topic` will be forwarded.
+matching `local_topic` will be forwarded.
NOTE: if this bridge is used as the action of a rule (EMQX rule engine), and also local_topic is configured, then both the data got from the rule and the MQTT messages that match local_topic will be forwarded.""" diff --git a/rel/i18n/emqx_bridge_greptimedb.hocon b/rel/i18n/emqx_bridge_greptimedb.hocon index 93d783332..977e6e064 100644 --- a/rel/i18n/emqx_bridge_greptimedb.hocon +++ b/rel/i18n/emqx_bridge_greptimedb.hocon @@ -26,7 +26,7 @@ desc_type.label: local_topic.desc: """The MQTT topic filter to be forwarded to the GreptimeDB. All MQTT 'PUBLISH' messages with the topic -matching the local_topic will be forwarded.
+matching the local_topic will be forwarded.
NOTE: if this bridge is used as the action of a rule (EMQX rule engine), and also local_topic is configured, then both the data got from the rule and the MQTT messages that match local_topic will be forwarded.""" @@ -37,8 +37,8 @@ local_topic.label: write_syntax.desc: """Conf of GreptimeDB gRPC protocol to write data points. Write syntax is a text-based format that provides the measurement, tag set, field set, and timestamp of a data point, and placeholder supported, which is the same as InfluxDB line protocol. See also [InfluxDB 2.3 Line Protocol](https://docs.influxdata.com/influxdb/v2.3/reference/syntax/line-protocol/) and -[GreptimeDB 1.8 Line Protocol](https://docs.influxdata.com/influxdb/v1.8/write_protocols/line_protocol_tutorial/)
-TLDR:
+[GreptimeDB 1.8 Line Protocol](https://docs.influxdata.com/influxdb/v1.8/write_protocols/line_protocol_tutorial/)
+TLDR:
``` [,=[,=]] =[,=] [] ``` diff --git a/rel/i18n/emqx_bridge_greptimedb_connector.hocon b/rel/i18n/emqx_bridge_greptimedb_connector.hocon index 9cb10951f..0a509ebfc 100644 --- a/rel/i18n/emqx_bridge_greptimedb_connector.hocon +++ b/rel/i18n/emqx_bridge_greptimedb_connector.hocon @@ -31,8 +31,8 @@ protocol.label: """Protocol""" server.desc: -"""The IPv4 or IPv6 address or the hostname to connect to.
-A host entry has the following form: `Host[:Port]`.
+"""The IPv4 or IPv6 address or the hostname to connect to.
+A host entry has the following form: `Host[:Port]`.
The GreptimeDB default port 8086 is used if `[:Port]` is not specified.""" server.label: diff --git a/rel/i18n/emqx_bridge_hstreamdb.hocon b/rel/i18n/emqx_bridge_hstreamdb.hocon index 809c60588..de9989953 100644 --- a/rel/i18n/emqx_bridge_hstreamdb.hocon +++ b/rel/i18n/emqx_bridge_hstreamdb.hocon @@ -32,7 +32,7 @@ desc_type.label: local_topic.desc: """The MQTT topic filter to be forwarded to the HStreamDB. All MQTT 'PUBLISH' messages with the topic -matching the local_topic will be forwarded.
+matching the local_topic will be forwarded.
NOTE: if this bridge is used as the action of a rule (EMQX rule engine), and also local_topic is configured, then both the data got from the rule and the MQTT messages that match local_topic will be forwarded.""" diff --git a/rel/i18n/emqx_bridge_influxdb.hocon b/rel/i18n/emqx_bridge_influxdb.hocon index 4299f41ab..48454bbd3 100644 --- a/rel/i18n/emqx_bridge_influxdb.hocon +++ b/rel/i18n/emqx_bridge_influxdb.hocon @@ -26,7 +26,7 @@ desc_type.label: local_topic.desc: """The MQTT topic filter to be forwarded to the InfluxDB. All MQTT 'PUBLISH' messages with the topic -matching the local_topic will be forwarded.
+matching the local_topic will be forwarded.
NOTE: if this bridge is used as the action of a rule (EMQX rule engine), and also local_topic is configured, then both the data got from the rule and the MQTT messages that match local_topic will be forwarded.""" @@ -37,8 +37,8 @@ local_topic.label: write_syntax.desc: """Conf of InfluxDB line protocol to write data points. It is a text-based format that provides the measurement, tag set, field set, and timestamp of a data point, and placeholder supported. See also [InfluxDB 2.3 Line Protocol](https://docs.influxdata.com/influxdb/v2.3/reference/syntax/line-protocol/) and -[InfluxDB 1.8 Line Protocol](https://docs.influxdata.com/influxdb/v1.8/write_protocols/line_protocol_tutorial/)
-TLDR:
+[InfluxDB 1.8 Line Protocol](https://docs.influxdata.com/influxdb/v1.8/write_protocols/line_protocol_tutorial/)
+TLDR:
``` [,=[,=]] =[,=] [] ``` diff --git a/rel/i18n/emqx_bridge_influxdb_connector.hocon b/rel/i18n/emqx_bridge_influxdb_connector.hocon index 4169ce065..ce79c2a93 100644 --- a/rel/i18n/emqx_bridge_influxdb_connector.hocon +++ b/rel/i18n/emqx_bridge_influxdb_connector.hocon @@ -49,8 +49,8 @@ protocol.label: """Protocol""" server.desc: -"""The IPv4 or IPv6 address or the hostname to connect to.
-A host entry has the following form: `Host[:Port]`.
+"""The IPv4 or IPv6 address or the hostname to connect to.
+A host entry has the following form: `Host[:Port]`.
The InfluxDB default port 8086 is used if `[:Port]` is not specified.""" server.label: diff --git a/rel/i18n/emqx_bridge_kinesis.hocon b/rel/i18n/emqx_bridge_kinesis.hocon index 42329bcd6..188ab82f3 100644 --- a/rel/i18n/emqx_bridge_kinesis.hocon +++ b/rel/i18n/emqx_bridge_kinesis.hocon @@ -32,7 +32,7 @@ pool_size.label: local_topic.desc: """The MQTT topic filter to be forwarded to Amazon Kinesis. All MQTT `PUBLISH` messages with the topic -matching the `local_topic` will be forwarded.
+matching the `local_topic` will be forwarded.
NOTE: if this bridge is used as the action of a rule (EMQX rule engine), and also `local_topic` is configured, then both the data got from the rule and the MQTT messages that match `local_topic` will be forwarded.""" diff --git a/rel/i18n/emqx_bridge_mysql.hocon b/rel/i18n/emqx_bridge_mysql.hocon index 10a02589c..37326be81 100644 --- a/rel/i18n/emqx_bridge_mysql.hocon +++ b/rel/i18n/emqx_bridge_mysql.hocon @@ -26,7 +26,7 @@ desc_type.label: local_topic.desc: """The MQTT topic filter to be forwarded to MySQL. All MQTT 'PUBLISH' messages with the topic -matching the local_topic will be forwarded.
+matching the local_topic will be forwarded.
NOTE: if this bridge is used as the action of a rule (EMQX rule engine), and also local_topic is configured, then both the data got from the rule and the MQTT messages that match local_topic will be forwarded.""" diff --git a/rel/i18n/emqx_bridge_oracle.hocon b/rel/i18n/emqx_bridge_oracle.hocon index c0c8142e6..bcf41ea2c 100644 --- a/rel/i18n/emqx_bridge_oracle.hocon +++ b/rel/i18n/emqx_bridge_oracle.hocon @@ -2,7 +2,7 @@ emqx_bridge_oracle { local_topic { desc = "The MQTT topic filter to be forwarded to Oracle Database. All MQTT 'PUBLISH' messages with the topic" - " matching the local_topic will be forwarded.
" + " matching the local_topic will be forwarded.
" "NOTE: if this bridge is used as the action of a rule (EMQX rule engine), and also local_topic is" " configured, then both the data got from the rule and the MQTT messages that match local_topic" " will be forwarded." diff --git a/rel/i18n/emqx_bridge_pgsql.hocon b/rel/i18n/emqx_bridge_pgsql.hocon index 5295abb35..0a5ca2b04 100644 --- a/rel/i18n/emqx_bridge_pgsql.hocon +++ b/rel/i18n/emqx_bridge_pgsql.hocon @@ -26,7 +26,7 @@ desc_type.label: local_topic.desc: """The MQTT topic filter to be forwarded to PostgreSQL. All MQTT 'PUBLISH' messages with the topic -matching the local_topic will be forwarded.
+matching the local_topic will be forwarded.
NOTE: if this bridge is used as the action of a rule (EMQX rule engine), and also local_topic is configured, then both the data got from the rule and the MQTT messages that match local_topic will be forwarded.""" diff --git a/rel/i18n/emqx_bridge_redis.hocon b/rel/i18n/emqx_bridge_redis.hocon index 8e8c18de0..05c8d95a6 100644 --- a/rel/i18n/emqx_bridge_redis.hocon +++ b/rel/i18n/emqx_bridge_redis.hocon @@ -34,7 +34,7 @@ desc_type.label: local_topic.desc: """The MQTT topic filter to be forwarded to Redis. All MQTT 'PUBLISH' messages with the topic -matching the local_topic will be forwarded.
+matching the local_topic will be forwarded.
NOTE: if this bridge is used as the action of a rule (EMQX rule engine), and also local_topic is configured, then both the data got from the rule and the MQTT messages that match local_topic will be forwarded.""" diff --git a/rel/i18n/emqx_bridge_rocketmq.hocon b/rel/i18n/emqx_bridge_rocketmq.hocon index ac5deb757..a2449c1a9 100644 --- a/rel/i18n/emqx_bridge_rocketmq.hocon +++ b/rel/i18n/emqx_bridge_rocketmq.hocon @@ -26,7 +26,7 @@ desc_type.label: local_topic.desc: """The MQTT topic filter to be forwarded to RocketMQ. All MQTT `PUBLISH` messages with the topic -matching the `local_topic` will be forwarded.
+matching the `local_topic` will be forwarded.
NOTE: if the bridge is used as a rule action, `local_topic` should be left empty otherwise the messages will be duplicated.""" local_topic.label: diff --git a/rel/i18n/emqx_bridge_sqlserver.hocon b/rel/i18n/emqx_bridge_sqlserver.hocon index 0e0801f42..24e4615f3 100644 --- a/rel/i18n/emqx_bridge_sqlserver.hocon +++ b/rel/i18n/emqx_bridge_sqlserver.hocon @@ -32,7 +32,7 @@ driver.label: local_topic.desc: """The MQTT topic filter to be forwarded to Microsoft SQL Server. All MQTT 'PUBLISH' messages with the topic -matching the local_topic will be forwarded.
+matching the local_topic will be forwarded.
NOTE: if this bridge is used as the action of a rule (EMQX rule engine), and also local_topic is configured, then both the data got from the rule and the MQTT messages that match local_topic will be forwarded.""" diff --git a/rel/i18n/emqx_bridge_tdengine.hocon b/rel/i18n/emqx_bridge_tdengine.hocon index 2d1059d28..ec6c10779 100644 --- a/rel/i18n/emqx_bridge_tdengine.hocon +++ b/rel/i18n/emqx_bridge_tdengine.hocon @@ -26,7 +26,7 @@ desc_type.label: local_topic.desc: """The MQTT topic filter to be forwarded to TDengine. All MQTT 'PUBLISH' messages with the topic -matching the local_topic will be forwarded.
+matching the local_topic will be forwarded.
NOTE: if this bridge is used as the action of a rule (EMQX rule engine), and also local_topic is configured, then both the data got from the rule and the MQTT messages that match local_topic will be forwarded.""" diff --git a/rel/i18n/emqx_schema.hocon b/rel/i18n/emqx_schema.hocon index e1d086197..3eb816f3b 100644 --- a/rel/i18n/emqx_schema.hocon +++ b/rel/i18n/emqx_schema.hocon @@ -92,7 +92,7 @@ mqtt_max_topic_alias.label: """Max Topic Alias""" common_ssl_opts_schema_user_lookup_fun.desc: -"""EMQX-internal callback that is used to lookup pre-shared key (PSK) identity.
+"""EMQX-internal callback that is used to lookup pre-shared key (PSK) identity.
Has no effect when TLS version is configured (or negotiated) to 1.3""" common_ssl_opts_schema_user_lookup_fun.label: @@ -1207,7 +1207,7 @@ The SSL application already takes measures to counter-act such attempts, but client-initiated renegotiation can be strictly disabled by setting this option to false. The default value is true. Note that disabling renegotiation can result in long-lived connections becoming unusable due to limits on -the number of messages the underlying cipher suite can encipher.
+the number of messages the underlying cipher suite can encipher.
Has no effect when TLS version is configured (or negotiated) to 1.3""" server_ssl_opts_schema_client_renegotiation.label: @@ -1294,7 +1294,7 @@ common_ssl_opts_schema_secure_renegotiate.desc: """SSL parameter renegotiation is a feature that allows a client and a server to renegotiate the parameters of the SSL connection on the fly. RFC 5746 defines a more secure way of doing this. By enabling secure renegotiation, -you drop support for the insecure renegotiation, prone to MitM attacks.
+you drop support for the insecure renegotiation, prone to MitM attacks.
Has no effect when TLS version is configured (or negotiated) to 1.3""" common_ssl_opts_schema_secure_renegotiate.label: @@ -1330,7 +1330,7 @@ mqtt_max_packet_size.label: """Max Packet Size""" common_ssl_opts_schema_reuse_sessions.desc: -"""Enable TLS session reuse.
+"""Enable TLS session reuse.
Has no effect when TLS version is configured (or negotiated) to 1.3""" common_ssl_opts_schema_reuse_sessions.label: From 8be718b22fed172bcab990126e858712e2892937 Mon Sep 17 00:00:00 2001 From: "Zaiming (Stone) Shi" Date: Sun, 12 Nov 2023 11:27:28 +0100 Subject: [PATCH 2/8] refactor(emqx_schema): delete unused type bar_separated_list --- apps/emqx/src/emqx_schema.erl | 7 ------- 1 file changed, 7 deletions(-) diff --git a/apps/emqx/src/emqx_schema.erl b/apps/emqx/src/emqx_schema.erl index 4ed8a3107..4f4c7e481 100644 --- a/apps/emqx/src/emqx_schema.erl +++ b/apps/emqx/src/emqx_schema.erl @@ -51,7 +51,6 @@ -type comma_separated_list() :: list(). -type comma_separated_binary() :: [binary()]. -type comma_separated_atoms() :: [atom()]. --type bar_separated_list() :: list(). -type ip_port() :: tuple() | integer(). -type cipher() :: map(). -type port_number() :: 1..65535. @@ -75,7 +74,6 @@ -typerefl_from_string({percent/0, emqx_schema, to_percent}). -typerefl_from_string({comma_separated_list/0, emqx_schema, to_comma_separated_list}). -typerefl_from_string({comma_separated_binary/0, emqx_schema, to_comma_separated_binary}). --typerefl_from_string({bar_separated_list/0, emqx_schema, to_bar_separated_list}). -typerefl_from_string({ip_port/0, emqx_schema, to_ip_port}). -typerefl_from_string({cipher/0, emqx_schema, to_erl_cipher_suite}). -typerefl_from_string({comma_separated_atoms/0, emqx_schema, to_comma_separated_atoms}). @@ -118,7 +116,6 @@ to_percent/1, to_comma_separated_list/1, to_comma_separated_binary/1, - to_bar_separated_list/1, to_ip_port/1, to_erl_cipher_suite/1, to_comma_separated_atoms/1, @@ -157,7 +154,6 @@ file/0, comma_separated_list/0, comma_separated_binary/0, - bar_separated_list/0, ip_port/0, cipher/0, comma_separated_atoms/0, @@ -2564,9 +2560,6 @@ to_json_binary(Str) -> Error end. -to_bar_separated_list(Str) -> - {ok, string:tokens(Str, "| ")}. - %% @doc support the following format: %% - 127.0.0.1:1883 %% - ::1:1883 From 06e440260f6251cef526a7f09f5630900e3ad190 Mon Sep 17 00:00:00 2001 From: "Zaiming (Stone) Shi" Date: Fri, 10 Nov 2023 21:55:20 +0100 Subject: [PATCH 3/8] refactor(schema): add args to map alias --- apps/emqx_auth_http/src/emqx_authz_http_schema.erl | 4 ++-- apps/emqx_dashboard/src/emqx_dashboard_swagger.erl | 3 ++- apps/emqx_prometheus/src/emqx_prometheus_schema.erl | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/apps/emqx_auth_http/src/emqx_authz_http_schema.erl b/apps/emqx_auth_http/src/emqx_authz_http_schema.erl index 21f70de64..90a7439a2 100644 --- a/apps/emqx_auth_http/src/emqx_authz_http_schema.erl +++ b/apps/emqx_auth_http/src/emqx_authz_http_schema.erl @@ -108,7 +108,7 @@ http_common_fields() -> ). headers(type) -> - typerefl:alias("map", list({binary(), binary()})); + typerefl:alias("map", list({binary(), binary()}), #{}, [binary(), binary()]); headers(desc) -> ?DESC(?FUNCTION_NAME); headers(converter) -> @@ -121,7 +121,7 @@ headers(_) -> undefined. headers_no_content_type(type) -> - typerefl:alias("map", list({binary(), binary()})); + typerefl:alias("map", list({binary(), binary()}), #{}, [binary(), binary()]); headers_no_content_type(desc) -> ?DESC(?FUNCTION_NAME); headers_no_content_type(converter) -> diff --git a/apps/emqx_dashboard/src/emqx_dashboard_swagger.erl b/apps/emqx_dashboard/src/emqx_dashboard_swagger.erl index 091e85da0..36dfb92be 100644 --- a/apps/emqx_dashboard/src/emqx_dashboard_swagger.erl +++ b/apps/emqx_dashboard/src/emqx_dashboard_swagger.erl @@ -865,7 +865,8 @@ typename_to_spec("bytesize()", _Mod) -> #{type => string, example => <<"32MB">>}; typename_to_spec("wordsize()", _Mod) -> #{type => string, example => <<"1024KB">>}; -typename_to_spec("map()", _Mod) -> +typename_to_spec("map(" ++ Map, _Mod) -> + [$) | _MapArgs] = lists:reverse(Map), #{type => object, example => #{}}; typename_to_spec("service_account_json()", _Mod) -> #{type => object, example => #{}}; diff --git a/apps/emqx_prometheus/src/emqx_prometheus_schema.erl b/apps/emqx_prometheus/src/emqx_prometheus_schema.erl index 91d176142..3aaf4292f 100644 --- a/apps/emqx_prometheus/src/emqx_prometheus_schema.erl +++ b/apps/emqx_prometheus/src/emqx_prometheus_schema.erl @@ -57,7 +57,7 @@ fields("prometheus") -> )}, {headers, ?HOCON( - typerefl:alias("map", list({string(), string()})), + typerefl:alias("map", list({string(), string()}), #{}, [string(), string()]), #{ default => #{}, required => false, From 021f7e6b49e31b5e77b0c55d792e0671ea31550b Mon Sep 17 00:00:00 2001 From: "Zaiming (Stone) Shi" Date: Sun, 12 Nov 2023 11:32:36 +0100 Subject: [PATCH 4/8] refactor(schema): comma_separated_list is list(string()) not list(any()) --- apps/emqx/src/emqx_schema.erl | 2 +- apps/emqx_gateway/src/emqx_gateway_schema.erl | 3 --- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/apps/emqx/src/emqx_schema.erl b/apps/emqx/src/emqx_schema.erl index 4f4c7e481..1a617c6c8 100644 --- a/apps/emqx/src/emqx_schema.erl +++ b/apps/emqx/src/emqx_schema.erl @@ -48,7 +48,7 @@ -type wordsize() :: bytesize(). -type percent() :: float(). -type file() :: string(). --type comma_separated_list() :: list(). +-type comma_separated_list() :: list(string()). -type comma_separated_binary() :: [binary()]. -type comma_separated_atoms() :: [atom()]. -type ip_port() :: tuple() | integer(). diff --git a/apps/emqx_gateway/src/emqx_gateway_schema.erl b/apps/emqx_gateway/src/emqx_gateway_schema.erl index e58e552e2..ed149d1f5 100644 --- a/apps/emqx_gateway/src/emqx_gateway_schema.erl +++ b/apps/emqx_gateway/src/emqx_gateway_schema.erl @@ -32,19 +32,16 @@ -type duration() :: non_neg_integer(). -type duration_s() :: non_neg_integer(). -type bytesize() :: pos_integer(). --type comma_separated_list() :: list(). -typerefl_from_string({ip_port/0, emqx_schema, to_ip_port}). -typerefl_from_string({duration/0, emqx_schema, to_duration}). -typerefl_from_string({duration_s/0, emqx_schema, to_duration_s}). -typerefl_from_string({bytesize/0, emqx_schema, to_bytesize}). --typerefl_from_string({comma_separated_list/0, emqx_schema, to_comma_separated_list}). -reflect_type([ duration/0, duration_s/0, bytesize/0, - comma_separated_list/0, ip_port/0 ]). -elvis([{elvis_style, dont_repeat_yourself, disable}]). From a32cd20758573f46f52044f3bfdbedc112d0058e Mon Sep 17 00:00:00 2001 From: "Zaiming (Stone) Shi" Date: Sun, 12 Nov 2023 11:35:08 +0100 Subject: [PATCH 5/8] refactor(emqx_authn_jwt_schema): add alias for verify_claims verifiy_claims is a list after converted, but input is a map --- apps/emqx_auth_jwt/src/emqx_authn_jwt_schema.erl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/apps/emqx_auth_jwt/src/emqx_authn_jwt_schema.erl b/apps/emqx_auth_jwt/src/emqx_authn_jwt_schema.erl index 9118d3d1b..63da372ff 100644 --- a/apps/emqx_auth_jwt/src/emqx_authn_jwt_schema.erl +++ b/apps/emqx_auth_jwt/src/emqx_authn_jwt_schema.erl @@ -152,7 +152,8 @@ refresh_interval(validator) -> [fun(I) -> I > 0 end]; refresh_interval(_) -> undefined. verify_claims(type) -> - list(); + %% user input is a map, converted to a list of {binary(), binary()} + typerefl:alias("map", list()); verify_claims(desc) -> ?DESC(?FUNCTION_NAME); verify_claims(default) -> From b7d2c38213a86fa7800d528a8371f55ede515c0a Mon Sep 17 00:00:00 2001 From: "Zaiming (Stone) Shi" Date: Fri, 10 Nov 2023 22:06:11 +0100 Subject: [PATCH 6/8] refactor: delete stale type converters Some of the types are refactored to use typerefl alias or hoconsc:enum, no need to keep the special function clauses to translate them to swagger spec --- apps/emqx_conf/src/emqx_conf.erl | 24 ++----------------- .../src/emqx_dashboard_swagger.erl | 22 ----------------- 2 files changed, 2 insertions(+), 44 deletions(-) diff --git a/apps/emqx_conf/src/emqx_conf.erl b/apps/emqx_conf/src/emqx_conf.erl index 1fb3bab28..733cb437f 100644 --- a/apps/emqx_conf/src/emqx_conf.erl +++ b/apps/emqx_conf/src/emqx_conf.erl @@ -355,34 +355,14 @@ 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("pool_type()", _Mod) -> - #{type => enum, symbols => [random, hash]}; -typename_to_spec("log_level()", _Mod) -> - #{ - type => enum, - symbols => [ - debug, - info, - notice, - warning, - error, - critical, - alert, - emergency, - all - ] - }; -typename_to_spec("rate()", _Mod) -> - #{type => string}; typename_to_spec("capacity()", _Mod) -> #{type => string}; -typename_to_spec("burst_rate()", _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()", _Mod) -> +typename_to_spec("map(" ++ Map, _Mod) -> + [$) | _MapArgs] = lists:reverse(Map), #{type => object}; typename_to_spec("#{" ++ _, Mod) -> typename_to_spec("map()", Mod); diff --git a/apps/emqx_dashboard/src/emqx_dashboard_swagger.erl b/apps/emqx_dashboard/src/emqx_dashboard_swagger.erl index 36dfb92be..9a8b553d1 100644 --- a/apps/emqx_dashboard/src/emqx_dashboard_swagger.erl +++ b/apps/emqx_dashboard/src/emqx_dashboard_swagger.erl @@ -799,8 +799,6 @@ hocon_schema_to_spec(?UNION(Types, _DisplayName), LocalModule) -> hocon_schema_to_spec(Atom, _LocalModule) when is_atom(Atom) -> {#{type => string, enum => [Atom]}, []}. -typename_to_spec("term()", _Mod) -> - #{type => string, example => <<"any">>}; typename_to_spec("boolean()", _Mod) -> #{type => boolean}; typename_to_spec("binary()", _Mod) -> @@ -884,26 +882,6 @@ typename_to_spec("comma_separated_binary()", _Mod) -> #{type => string, example => <<"item1,item2">>}; typename_to_spec("comma_separated_atoms()", _Mod) -> #{type => string, example => <<"item1,item2">>}; -typename_to_spec("pool_type()", _Mod) -> - #{type => string, enum => [random, hash]}; -typename_to_spec("log_level()", _Mod) -> - #{ - type => string, - enum => [debug, info, notice, warning, error, critical, alert, emergency, all] - }; -typename_to_spec("rate()", _Mod) -> - #{type => string, example => <<"10MB">>}; -typename_to_spec("burst()", _Mod) -> - #{type => string, example => <<"100MB">>}; -typename_to_spec("burst_rate()", _Mod) -> - %% 0/0s = no burst - #{type => string, example => <<"10MB">>}; -typename_to_spec("failure_strategy()", _Mod) -> - #{type => string, example => <<"force">>}; -typename_to_spec("initial()", _Mod) -> - #{type => string, example => <<"0MB">>}; -typename_to_spec("bucket_name()", _Mod) -> - #{type => string, example => <<"retainer">>}; typename_to_spec("json_binary()", _Mod) -> #{type => string, example => <<"{\"a\": [1,true]}">>}; typename_to_spec("port_number()", _Mod) -> From 2fda91ec59fd12bbb5924a35d680d7a5a0e6e97f Mon Sep 17 00:00:00 2001 From: "Zaiming (Stone) Shi" Date: Fri, 10 Nov 2023 22:06:11 +0100 Subject: [PATCH 7/8] 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 --- apps/emqx_conf/src/emqx_conf.erl | 24 +++++++------------ .../src/emqx_dashboard_swagger.erl | 18 -------------- 2 files changed, 9 insertions(+), 33 deletions(-) diff --git a/apps/emqx_conf/src/emqx_conf.erl b/apps/emqx_conf/src/emqx_conf.erl index 733cb437f..6f50cf831 100644 --- a/apps/emqx_conf/src/emqx_conf.erl +++ b/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 diff --git a/apps/emqx_dashboard/src/emqx_dashboard_swagger.erl b/apps/emqx_dashboard/src/emqx_dashboard_swagger.erl index 9a8b553d1..ef10d33af 100644 --- a/apps/emqx_dashboard/src/emqx_dashboard_swagger.erl +++ b/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) -> From 65efa2672e97516069da276e85f604aef2ff8e18 Mon Sep 17 00:00:00 2001 From: "Zaiming (Stone) Shi" Date: Mon, 13 Nov 2023 08:59:22 +0100 Subject: [PATCH 8/8] test(schema): delete stale reference to emqx_schema:file() type --- apps/emqx/src/emqx_schema.erl | 2 -- apps/emqx_conf/src/emqx_conf.erl | 2 -- .../test/emqx_swagger_requestBody_SUITE.erl | 2 +- .../test/emqx_swagger_response_SUITE.erl | 10 +++++----- 4 files changed, 6 insertions(+), 10 deletions(-) diff --git a/apps/emqx/src/emqx_schema.erl b/apps/emqx/src/emqx_schema.erl index 1a617c6c8..3ad03c4d4 100644 --- a/apps/emqx/src/emqx_schema.erl +++ b/apps/emqx/src/emqx_schema.erl @@ -47,7 +47,6 @@ -type bytesize() :: integer(). -type wordsize() :: bytesize(). -type percent() :: float(). --type file() :: string(). -type comma_separated_list() :: list(string()). -type comma_separated_binary() :: [binary()]. -type comma_separated_atoms() :: [atom()]. @@ -151,7 +150,6 @@ bytesize/0, wordsize/0, percent/0, - file/0, comma_separated_list/0, comma_separated_binary/0, ip_port/0, diff --git a/apps/emqx_conf/src/emqx_conf.erl b/apps/emqx_conf/src/emqx_conf.erl index 6f50cf831..8b51c2161 100644 --- a/apps/emqx_conf/src/emqx_conf.erl +++ b/apps/emqx_conf/src/emqx_conf.erl @@ -337,8 +337,6 @@ typename_to_spec("timeout_duration_ms()", _Mod) -> #{type => duration}; typename_to_spec("percent()", _Mod) -> #{type => percent}; -typename_to_spec("file()", _Mod) -> - #{type => string}; typename_to_spec("ip_port()", _Mod) -> #{type => ip_port}; typename_to_spec("url()", _Mod) -> diff --git a/apps/emqx_dashboard/test/emqx_swagger_requestBody_SUITE.erl b/apps/emqx_dashboard/test/emqx_swagger_requestBody_SUITE.erl index 2457cd56a..b5c55622b 100644 --- a/apps/emqx_dashboard/test/emqx_swagger_requestBody_SUITE.erl +++ b/apps/emqx_dashboard/test/emqx_swagger_requestBody_SUITE.erl @@ -816,7 +816,7 @@ to_schema(Body) -> fields(good_ref) -> [ {'webhook-host', mk(emqx_schema:ip_port(), #{default => <<"127.0.0.1:80">>})}, - {log_dir, mk(emqx_schema:file(), #{example => "var/log/emqx"})}, + {log_dir, mk(string(), #{example => "var/log/emqx"})}, {tag, mk(binary(), #{desc => <<"tag">>})} ]; fields(nest_ref) -> diff --git a/apps/emqx_dashboard/test/emqx_swagger_response_SUITE.erl b/apps/emqx_dashboard/test/emqx_swagger_response_SUITE.erl index 376ace5c2..745db76f0 100644 --- a/apps/emqx_dashboard/test/emqx_swagger_response_SUITE.erl +++ b/apps/emqx_dashboard/test/emqx_swagger_response_SUITE.erl @@ -344,10 +344,9 @@ t_complex_type(_Config) -> enum := [random, hash], type := string }}, {<<"timeout">>, #{ - example := infinity, <<"oneOf">> := [ - #{example := infinity, type := string}, - #{type := integer} + #{example := _, type := string}, + #{enum := [infinity], type := string} ] }}, {<<"bytesize">>, #{ @@ -653,7 +652,8 @@ schema("/ref/complex_type") -> {server, hoconsc:mk(emqx_schema:ip_port(), #{})}, {connect_timeout, hoconsc:mk(emqx_schema:timeout_duration(), #{})}, {pool_type, hoconsc:mk(hoconsc:enum([random, hash]), #{})}, - {timeout, hoconsc:mk(timeout(), #{})}, + {timeout, + hoconsc:mk(hoconsc:union([infinity, emqx_schema:timeout_duration()]), #{})}, {bytesize, hoconsc:mk(emqx_schema:bytesize(), #{})}, {wordsize, hoconsc:mk(emqx_schema:wordsize(), #{})}, {maps, hoconsc:mk(map(), #{})}, @@ -687,7 +687,7 @@ to_schema(Object) -> fields(good_ref) -> [ {'webhook-host', mk(emqx_schema:ip_port(), #{default => <<"127.0.0.1:80">>})}, - {log_dir, mk(emqx_schema:file(), #{example => "var/log/emqx"})}, + {log_dir, mk(string(), #{example => "var/log/emqx"})}, {tag, mk(binary(), #{desc => <<"tag">>})} ]; fields(nest_ref) ->