This is an automated email from the ASF dual-hosted git repository.
baoyuan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/apisix.git
The following commit(s) were added to refs/heads/master by this push:
new b5425e1bc fix: Make protocol_name optional and default to 'MQTT' for
mqtt plugin (#12831)
b5425e1bc is described below
commit b5425e1bc3f08fcacc5ad953f9fb6084f2529bae
Author: YapWC <[email protected]>
AuthorDate: Fri Dec 26 10:52:47 2025 +0800
fix: Make protocol_name optional and default to 'MQTT' for mqtt plugin
(#12831)
---
apisix/stream/plugins/mqtt-proxy.lua | 4 ++--
docs/en/latest/plugins/mqtt-proxy.md | 2 +-
docs/zh/latest/plugins/mqtt-proxy.md | 8 ++++----
t/stream-plugin/mqtt-proxy2.t | 26 ++++++++++++++++++++++++++
4 files changed, 33 insertions(+), 7 deletions(-)
diff --git a/apisix/stream/plugins/mqtt-proxy.lua
b/apisix/stream/plugins/mqtt-proxy.lua
index f075e204d..8617cf64c 100644
--- a/apisix/stream/plugins/mqtt-proxy.lua
+++ b/apisix/stream/plugins/mqtt-proxy.lua
@@ -29,10 +29,10 @@ end)
local schema = {
type = "object",
properties = {
- protocol_name = {type = "string"},
+ protocol_name = {type = "string", default = "MQTT"},
protocol_level = {type = "integer"}
},
- required = {"protocol_name", "protocol_level"},
+ required = {"protocol_level"},
}
diff --git a/docs/en/latest/plugins/mqtt-proxy.md
b/docs/en/latest/plugins/mqtt-proxy.md
index 212fdb36a..64c4f92d2 100644
--- a/docs/en/latest/plugins/mqtt-proxy.md
+++ b/docs/en/latest/plugins/mqtt-proxy.md
@@ -37,7 +37,7 @@ This Plugin supports both the protocols
[3.1.*](http://docs.oasis-open.org/mqtt/
| Name | Type | Required | Description
|
|----------------|---------|------------|-----------------------------------------------------------------------------------|
-| protocol_name | string | True | Name of the protocol. Generally
`MQTT`. |
+| protocol_name | string | False | Name of the protocol. Defaults to
`MQTT`. |
| protocol_level | integer | True | Level of the protocol. It should be
`4` for MQTT `3.1.*` and `5` for MQTT `5.0`. |
## Enable Plugin
diff --git a/docs/zh/latest/plugins/mqtt-proxy.md
b/docs/zh/latest/plugins/mqtt-proxy.md
index d28d53d5d..193a4b396 100644
--- a/docs/zh/latest/plugins/mqtt-proxy.md
+++ b/docs/zh/latest/plugins/mqtt-proxy.md
@@ -35,10 +35,10 @@ description: 本文档介绍了 Apache APISIX mqtt-proxy 插件的信息,通
## 属性
-| 名称 | 类型 | 必选项 | 描述
|
-| -------------- | ------- | ----- |
------------------------------------------------------ |
-| protocol_name | string | 是 | 协议名称,正常情况下应为 `MQTT`。
|
-| protocol_level | integer | 是 | 协议级别,MQTT `3.1.*` 为 `4`,MQTT `5.0` 应是`5`。
|
+| 名称 | 类型 | 必选项 | 描述
|
+| -------------- | ------- | ----- |
--------------------------------------------------- |
+| protocol_name | string | 否 | 协议名称,默认为 `MQTT`。
|
+| protocol_level | integer | 是 | 协议级别,MQTT `3.1.*` 为 `4`,MQTT `5.0` 应是`5`。
|
## 启用插件
diff --git a/t/stream-plugin/mqtt-proxy2.t b/t/stream-plugin/mqtt-proxy2.t
index 35211878e..2e1e53efa 100644
--- a/t/stream-plugin/mqtt-proxy2.t
+++ b/t/stream-plugin/mqtt-proxy2.t
@@ -182,3 +182,29 @@ qr/(mqtt client id: \w+|proxy request to \S+)/
--- grep_error_log_out
mqtt client id: g
proxy request to 127.0.0.1:1995
+
+
+
+=== TEST 8: sanity
+--- config
+ location /t {
+ content_by_lua_block {
+ local test_cases = {
+ {protocol_name = "MQTT", protocol_level = 4},
+ {protocol_name = "MQTT"},
+ {protocol_level = 4},
+ }
+
+ local stream_plugin = require("apisix.stream.plugins.mqtt-proxy")
+ for _, case in ipairs(test_cases) do
+ local ok, err = stream_plugin.check_schema(case)
+ ngx.say(ok and "done" or err)
+ end
+ }
+ }
+--- request
+GET /t
+--- response_body
+done
+property "protocol_level" is required
+done