diff --git a/apisix/core/etcd.lua b/apisix/core/etcd.lua index 793ece52bd2d..288fac791079 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 2a83d71cc152..b464dcc0673a 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 3ee4b461ec12..9eb4d63949ff 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 f5c4daf7fded..c9a11f785c34 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 1780d1155afd..cd5e9320ed9d 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 28bc2fcc31d3..3c296b79339f 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 3835dcc0f107..6ff033b52f43 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 def0ba222b68..190b9ae20faf 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 d9eb4f9165f9..668ff47a7b18 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 4fcce6069d66..cb09b5119223 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 9796a05eb499..070c8b3d2368 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":[]}}