This is an automated email from the ASF dual-hosted git repository. membphis 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 a651a29 feature: allow empty `service` object, it does not contain any `upstream` and `plugin` (#2259) a651a29 is described below commit a651a29e206a11920edcbdff3054cf7bfbd27462 Author: Firstsawyou <52862365+firstsaw...@users.noreply.github.com> AuthorDate: Mon Sep 21 16:52:18 2020 +0800 feature: allow empty `service` object, it does not contain any `upstream` and `plugin` (#2259) --- apisix/schema_def.lua | 6 --- t/admin/schema.t | 23 ++++++++++-- t/admin/services.t | 94 ++++++++++++++++++++++++++++++++++++++++++++++ t/node/service-empty.t | 100 +++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 213 insertions(+), 10 deletions(-) diff --git a/apisix/schema_def.lua b/apisix/schema_def.lua index e8d4249..a277510 100644 --- a/apisix/schema_def.lua +++ b/apisix/schema_def.lua @@ -473,12 +473,6 @@ _M.service = { desc = {type = "string", maxLength = 256}, script = {type = "string", minLength = 10, maxLength = 102400}, }, - anyOf = { - {required = {"upstream"}}, - {required = {"upstream_id"}}, - {required = {"plugins"}}, - {required = {"script"}}, - }, additionalProperties = false, } diff --git a/t/admin/schema.t b/t/admin/schema.t index 1acc3f6..5f78635 100644 --- a/t/admin/schema.t +++ b/t/admin/schema.t @@ -36,11 +36,26 @@ qr/"plugins":\{"type":"object"}/ -=== TEST 2: get service schema +=== TEST 2: get service schema and check if it contains `anyOf` +--- config + location /t { + content_by_lua_block { + local core = require("apisix.core") + local t = require("lib.test_admin").test + local code, _, res_body = t('/apisix/admin/schema/service', ngx.HTTP_GET) + local res_data = core.json.decode(res_body) + if res_data["anyOf"] then + ngx.say("found `anyOf`") + return + end + + ngx.say("passed") + } + } --- request -GET /apisix/admin/schema/service ---- response_body eval -qr/"required":\["upstream"\]/ +GET /t +--- response_body +passed --- no_error_log [error] diff --git a/t/admin/services.t b/t/admin/services.t index b7ec741..5dcb8ad 100644 --- a/t/admin/services.t +++ b/t/admin/services.t @@ -1085,3 +1085,97 @@ GET /t --- error_code: 400 --- no_error_log [error] + + + +=== TEST 31: set empty service. (id: 1)(allow empty `service` object) +--- config + location /t { + content_by_lua_block { + local t = require("lib.test_admin").test + local code, body = t('/apisix/admin/services/1', + ngx.HTTP_PUT, + {}, + [[{ + "node": { + "value": {"id":"1"} + }, + "action": "set" + }]] + ) + + ngx.status = code + ngx.say(body) + } + } +--- request +GET /t +--- response_body +passed +--- no_error_log +[error] + + + +=== TEST 32: patch content to the empty service. +--- config + location /t { + content_by_lua_block { + local t = require("lib.test_admin").test + local code, body = t('/apisix/admin/services/1', + ngx.HTTP_PATCH, + [[{ + "desc": "empty service", + "plugins": { + "limit-count": { + "count": 2, + "time_window": 60, + "rejected_code": 503, + "key": "remote_addr" + } + }, + "upstream": { + "type": "roundrobin", + "nodes": { + "127.0.0.1:80": 1 + } + } + }]], + [[{ + "node":{ + "value":{ + "desc":"empty service", + "plugins":{ + "limit-count":{ + "time_window":60, + "count":2, + "rejected_code":503, + "key":"remote_addr", + "policy":"local" + } + }, + "upstream":{ + "type":"roundrobin", + "nodes":{ + "127.0.0.1:80":1 + }, + "hash_on":"vars", + "pass_host":"pass" + }, + "id":"1" + } + }, + "action":"compareAndSwap" + }]] + ) + + ngx.status = code + ngx.say(body) + } + } +--- request +GET /t +--- response_body +passed +--- no_error_log +[error] diff --git a/t/node/service-empty.t b/t/node/service-empty.t new file mode 100644 index 0000000..f32df6f --- /dev/null +++ b/t/node/service-empty.t @@ -0,0 +1,100 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +use t::APISIX 'no_plan'; + +repeat_each(1); +log_level('info'); +worker_connections(256); +no_root_location(); +no_shuffle(); + +run_tests(); + +__DATA__ + + +=== TEST 1: set empty service. (id: 1)(allow empty `service` object) +--- config + location /t { + content_by_lua_block { + local t = require("lib.test_admin").test + local code, body = t('/apisix/admin/services/1', + ngx.HTTP_PUT, + {}, + [[{ + "node": { + "value": {"id":"1"} + }, + "action": "set" + }]] + ) + + ngx.status = code + ngx.say(body) + } + } +--- request +GET /t +--- response_body +passed +--- no_error_log +[error] + + + +=== TEST 2: route binding empty service +--- config + location /t { + 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:1980": 1 + }, + "type": "roundrobin" + }, + "service_id": "1", + "uri": "/hello" + }]] + ) + + if code >= 300 then + ngx.status = code + end + ngx.say(body) + } + } +--- request +GET /t +--- response_body +passed +--- no_error_log +[error] + + + +=== TEST 3: /hello +--- request +GET /hello +--- response_body +hello world +--- no_error_log +[error]