This is an automated email from the ASF dual-hosted git repository.
spacewander 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 e279dff change(admin): empty nodes should be encoded as array (#6384)
e279dff is described below
commit e279dfffef30029f050254ceac3154b21a3f419b
Author: 罗泽轩 <[email protected]>
AuthorDate: Mon Feb 21 09:51:52 2022 +0800
change(admin): empty nodes should be encoded as array (#6384)
---
apisix/core/etcd.lua | 4 +++-
apisix/core/json.lua | 1 +
docs/en/latest/getting-started.md | 4 ++--
docs/en/latest/internal/testing-framework.md | 2 +-
docs/zh/latest/getting-started.md | 4 ++--
t/admin/consumers2.t | 2 +-
t/admin/global-rules2.t | 2 +-
t/admin/plugin-metadata2.t | 2 +-
t/admin/routes3.t | 2 +-
t/admin/ssl3.t | 2 +-
t/admin/upstream3.t | 2 +-
11 files changed, 15 insertions(+), 12 deletions(-)
diff --git a/apisix/core/etcd.lua b/apisix/core/etcd.lua
index 793ece5..288fac7 100644
--- a/apisix/core/etcd.lua
+++ b/apisix/core/etcd.lua
@@ -15,10 +15,12 @@
-- limitations under the License.
--
local fetch_local_conf = require("apisix.core.config_local").local_conf
+local array_mt = require("apisix.core.json").array_mt
local etcd = require("resty.etcd")
local clone_tab = require("table.clone")
local health_check = require("resty.etcd.health_check")
local ipairs = ipairs
+local setmetatable = setmetatable
local string = string
local tonumber = tonumber
local _M = {}
@@ -88,7 +90,7 @@ _M.kvs_to_node = kvs_to_node
local function kvs_to_nodes(res)
res.body.node.dir = true
- res.body.node.nodes = {}
+ res.body.node.nodes = setmetatable({}, array_mt)
for i=2, #res.body.kvs do
res.body.node.nodes[i-1] = kvs_to_node(res.body.kvs[i])
end
diff --git a/apisix/core/json.lua b/apisix/core/json.lua
index 2a83d71..b464dcc 100644
--- a/apisix/core/json.lua
+++ b/apisix/core/json.lua
@@ -25,6 +25,7 @@ local cached_tab = {}
local _M = {
version = 0.1,
+ array_mt = require("cjson.safe").array_mt,
decode = require("cjson.safe").decode,
-- This method produces the same encoded string when the input is not
changed.
-- Different calls with cjson.encode will produce different string because
diff --git a/docs/en/latest/getting-started.md
b/docs/en/latest/getting-started.md
index 3ee4b46..9eb4d63 100644
--- a/docs/en/latest/getting-started.md
+++ b/docs/en/latest/getting-started.md
@@ -118,11 +118,11 @@ The following data is returned to indicate that Apache
APISIX was successfully s
```json
{
- "count":1,
+ "count":0,
"action":"get",
"node":{
"key":"/apisix/services",
- "nodes":{},
+ "nodes":[],
"dir":true
}
}
diff --git a/docs/en/latest/internal/testing-framework.md
b/docs/en/latest/internal/testing-framework.md
index f5c4daf..c9a11f7 100644
--- a/docs/en/latest/internal/testing-framework.md
+++ b/docs/en/latest/internal/testing-framework.md
@@ -351,7 +351,7 @@ ONLY:
--- config
...
--- response_body
-{"action":"get","count":0,"node":{"dir":true,"key":"/apisix/upstreams","nodes":{}}}
+{"action":"get","count":0,"node":{"dir":true,"key":"/apisix/upstreams","nodes":[]}}
```
### Executing Shell Commands
diff --git a/docs/zh/latest/getting-started.md
b/docs/zh/latest/getting-started.md
index 1780d11..cd5e932 100644
--- a/docs/zh/latest/getting-started.md
+++ b/docs/zh/latest/getting-started.md
@@ -116,11 +116,11 @@ curl "http://127.0.0.1:9080/apisix/admin/services/" -H
'X-API-KEY: edd1c9f034335
```json
{
- "count":1,
+ "count":0,
"action":"get",
"node":{
"key":"/apisix/services",
- "nodes":{},
+ "nodes":[],
"dir":true
}
}
diff --git a/t/admin/consumers2.t b/t/admin/consumers2.t
index 28bc2fc..3c296b7 100644
--- a/t/admin/consumers2.t
+++ b/t/admin/consumers2.t
@@ -150,7 +150,7 @@ __DATA__
}
}
--- response_body
-{"action":"get","count":0,"node":{"dir":true,"key":"/apisix/consumers","nodes":{}}}
+{"action":"get","count":0,"node":{"dir":true,"key":"/apisix/consumers","nodes":[]}}
diff --git a/t/admin/global-rules2.t b/t/admin/global-rules2.t
index 3835dcc..6ff033b 100644
--- a/t/admin/global-rules2.t
+++ b/t/admin/global-rules2.t
@@ -60,7 +60,7 @@ __DATA__
}
}
--- response_body
-{"action":"get","count":0,"node":{"dir":true,"key":"/apisix/global_rules","nodes":{}}}
+{"action":"get","count":0,"node":{"dir":true,"key":"/apisix/global_rules","nodes":[]}}
diff --git a/t/admin/plugin-metadata2.t b/t/admin/plugin-metadata2.t
index def0ba2..190b9ae 100644
--- a/t/admin/plugin-metadata2.t
+++ b/t/admin/plugin-metadata2.t
@@ -60,4 +60,4 @@ __DATA__
}
}
--- response_body
-{"action":"get","count":0,"node":{"dir":true,"key":"/apisix/plugin_metadata","nodes":{}}}
+{"action":"get","count":0,"node":{"dir":true,"key":"/apisix/plugin_metadata","nodes":[]}}
diff --git a/t/admin/routes3.t b/t/admin/routes3.t
index d9eb4f9..668ff47 100644
--- a/t/admin/routes3.t
+++ b/t/admin/routes3.t
@@ -60,7 +60,7 @@ __DATA__
}
}
--- response_body
-{"action":"get","count":0,"node":{"dir":true,"key":"/apisix/routes","nodes":{}}}
+{"action":"get","count":0,"node":{"dir":true,"key":"/apisix/routes","nodes":[]}}
diff --git a/t/admin/ssl3.t b/t/admin/ssl3.t
index 4fcce60..cb09b51 100644
--- a/t/admin/ssl3.t
+++ b/t/admin/ssl3.t
@@ -60,4 +60,4 @@ __DATA__
}
}
--- response_body
-{"action":"get","count":0,"node":{"dir":true,"key":"/apisix/ssl","nodes":{}}}
+{"action":"get","count":0,"node":{"dir":true,"key":"/apisix/ssl","nodes":[]}}
diff --git a/t/admin/upstream3.t b/t/admin/upstream3.t
index 9796a05..070c8b3 100644
--- a/t/admin/upstream3.t
+++ b/t/admin/upstream3.t
@@ -60,7 +60,7 @@ __DATA__
}
}
--- response_body
-{"action":"get","count":0,"node":{"dir":true,"key":"/apisix/upstreams","nodes":{}}}
+{"action":"get","count":0,"node":{"dir":true,"key":"/apisix/upstreams","nodes":[]}}