Skip to content

Commit

Permalink
change(admin): empty nodes should be encoded as array (#6384)
Browse files Browse the repository at this point in the history
  • Loading branch information
spacewander committed Feb 21, 2022
1 parent 682f8cc commit e279dff
Show file tree
Hide file tree
Showing 11 changed files with 15 additions and 12 deletions.
4 changes: 3 additions & 1 deletion apisix/core/etcd.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions apisix/core/json.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions docs/en/latest/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down
2 changes: 1 addition & 1 deletion docs/en/latest/internal/testing-framework.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions docs/zh/latest/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down
2 changes: 1 addition & 1 deletion t/admin/consumers2.t
Original file line number Diff line number Diff line change
Expand Up @@ -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":[]}}
Expand Down
2 changes: 1 addition & 1 deletion t/admin/global-rules2.t
Original file line number Diff line number Diff line change
Expand Up @@ -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":[]}}
Expand Down
2 changes: 1 addition & 1 deletion t/admin/plugin-metadata2.t
Original file line number Diff line number Diff line change
Expand Up @@ -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":[]}}
2 changes: 1 addition & 1 deletion t/admin/routes3.t
Original file line number Diff line number Diff line change
Expand Up @@ -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":[]}}
Expand Down
2 changes: 1 addition & 1 deletion t/admin/ssl3.t
Original file line number Diff line number Diff line change
Expand Up @@ -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":[]}}
2 changes: 1 addition & 1 deletion t/admin/upstream3.t
Original file line number Diff line number Diff line change
Expand Up @@ -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":[]}}
Expand Down

0 comments on commit e279dff

Please sign in to comment.