Skip to content

Commit b5425e1

Browse files
authored
fix: Make protocol_name optional and default to 'MQTT' for mqtt plugin (#12831)
1 parent 2fb2fe7 commit b5425e1

File tree

4 files changed

+33
-7
lines changed

4 files changed

+33
-7
lines changed

apisix/stream/plugins/mqtt-proxy.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ end)
2929
local schema = {
3030
type = "object",
3131
properties = {
32-
protocol_name = {type = "string"},
32+
protocol_name = {type = "string", default = "MQTT"},
3333
protocol_level = {type = "integer"}
3434
},
35-
required = {"protocol_name", "protocol_level"},
35+
required = {"protocol_level"},
3636
}
3737

3838

docs/en/latest/plugins/mqtt-proxy.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ This Plugin supports both the protocols [3.1.*](http://docs.oasis-open.org/mqtt/
3737

3838
| Name | Type | Required | Description |
3939
|----------------|---------|------------|-----------------------------------------------------------------------------------|
40-
| protocol_name | string | True | Name of the protocol. Generally `MQTT`. |
40+
| protocol_name | string | False | Name of the protocol. Defaults to `MQTT`. |
4141
| protocol_level | integer | True | Level of the protocol. It should be `4` for MQTT `3.1.*` and `5` for MQTT `5.0`. |
4242

4343
## Enable Plugin

docs/zh/latest/plugins/mqtt-proxy.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ description: 本文档介绍了 Apache APISIX mqtt-proxy 插件的信息,通
3535

3636
## 属性
3737

38-
| 名称 | 类型 | 必选项 | 描述 |
39-
| -------------- | ------- | ----- | ------------------------------------------------------ |
40-
| protocol_name | string | | 协议名称,正常情况下应为 `MQTT`|
41-
| protocol_level | integer || 协议级别,MQTT `3.1.*``4`,MQTT `5.0` 应是`5`|
38+
| 名称 | 类型 | 必选项 | 描述 |
39+
| -------------- | ------- | ----- | --------------------------------------------------- |
40+
| protocol_name | string | | 协议名称,默认为 `MQTT` |
41+
| protocol_level | integer || 协议级别,MQTT `3.1.*``4`,MQTT `5.0` 应是`5` |
4242

4343
## 启用插件
4444

t/stream-plugin/mqtt-proxy2.t

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,3 +182,29 @@ qr/(mqtt client id: \w+|proxy request to \S+)/
182182
--- grep_error_log_out
183183
mqtt client id: g
184184
proxy request to 127.0.0.1:1995
185+
186+
187+
188+
=== TEST 8: sanity
189+
--- config
190+
location /t {
191+
content_by_lua_block {
192+
local test_cases = {
193+
{protocol_name = "MQTT", protocol_level = 4},
194+
{protocol_name = "MQTT"},
195+
{protocol_level = 4},
196+
}
197+
198+
local stream_plugin = require("apisix.stream.plugins.mqtt-proxy")
199+
for _, case in ipairs(test_cases) do
200+
local ok, err = stream_plugin.check_schema(case)
201+
ngx.say(ok and "done" or err)
202+
end
203+
}
204+
}
205+
--- request
206+
GET /t
207+
--- response_body
208+
done
209+
property "protocol_level" is required
210+
done

0 commit comments

Comments
 (0)