feature: supported to patch whole route content.

This commit is contained in:
Yuansheng 2019-08-04 13:15:18 +08:00 committed by YuanSheng Wang
parent 19e09b539f
commit 77e5b50591
2 changed files with 68 additions and 11 deletions

View File

@ -1,6 +1,7 @@
local core = require("apisix.core")
local schema_plugin = require("apisix.admin.plugins").check_schema
local tostring = tostring
local type = type
local _M = {
@ -198,7 +199,11 @@ function _M.patch(id, conf, sub_path)
end
local sub_name = sub_paths[#sub_paths]
sub_value[sub_name] = conf
if sub_name and sub_name ~= "" then
sub_value[sub_name] = conf
else
node_value = conf
end
core.log.info("new conf: ", core.json.delay_encode(node_value, true))
local id, err = check_conf(id, node_value, true)

View File

@ -16,17 +16,17 @@ __DATA__
content_by_lua_block {
local t = require("lib.test_admin").test
local code, body = t('/apisix/admin/routes/1',
ngx.HTTP_PUT,
[[{
"methods": ["GET"],
"upstream": {
"nodes": {
"127.0.0.1:8080": 1
},
"type": "roundrobin"
ngx.HTTP_PUT,
[[{
"methods": ["GET"],
"upstream": {
"nodes": {
"127.0.0.1:8080": 1
},
"desc": "new route",
"uri": "/index.html"
"type": "roundrobin"
},
"desc": "new route",
"uri": "/index.html"
}]],
[[{
"node": {
@ -1036,3 +1036,55 @@ GET /t
passed
--- no_error_log
[error]
=== TEST 30: patch route(whole)
--- config
location /t {
content_by_lua_block {
local t = require("lib.test_admin").test
local code, body = t('/apisix/admin/routes/1/',
ngx.HTTP_PATCH,
[[{
"methods": ["GET"],
"upstream": {
"nodes": {
"127.0.0.1:8080": 1
},
"type": "roundrobin"
},
"desc": "new route",
"uri": "/index.html"
}]],
[[{
"node": {
"value": {
"methods": [
"GET"
],
"uri": "/index.html",
"desc": "new route",
"upstream": {
"nodes": {
"127.0.0.1:8080": 1
},
"type": "roundrobin"
}
},
"key": "/apisix/routes/1"
},
"action": "set"
}]]
)
ngx.status = code
ngx.say(body)
}
}
--- request
GET /t
--- response_body
passed
--- no_error_log
[error]