diff --git a/apisix/schema_def.lua b/apisix/schema_def.lua index 1ec0ea6026c8..f7b117af93da 100644 --- a/apisix/schema_def.lua +++ b/apisix/schema_def.lua @@ -437,6 +437,7 @@ local upstream_schema = { type = { description = "algorithms of load balancing", type = "string", + default = "roundrobin", }, checks = health_checker, hash_on = { @@ -498,8 +499,8 @@ local upstream_schema = { id = id_schema, }, oneOf = { - {required = {"type", "nodes"}}, - {required = {"type", "service_name", "discovery_type"}}, + {required = {"nodes"}}, + {required = {"service_name", "discovery_type"}}, } } diff --git a/t/admin/upstream.t b/t/admin/upstream.t index 12681780cd17..e47bc526fcd4 100644 --- a/t/admin/upstream.t +++ b/t/admin/upstream.t @@ -727,3 +727,42 @@ GET /t {"error_msg":"failed to fetch ssl info by ssl id [1], wrong ssl type"} --- no_error_log [error] + + + +=== TEST 22: type with default vale +--- config + location /t { + content_by_lua_block { + local t = require("lib.test_admin").test + local etcd = require("apisix.core.etcd") + local code, body = t('/apisix/admin/upstreams/admin_up', + ngx.HTTP_PUT, + [[{ + "nodes": { + "127.0.0.1:8080": 1 + }, + "desc": "new upstream" + }]], + [[{ + "value": { + "nodes": { + "127.0.0.1:8080": 1 + }, + "type": "roundrobin", + "desc": "new upstream" + }, + "key": "/apisix/upstreams/admin_up" + }]] + ) + + ngx.status = code + ngx.say(body) + } + } +--- request +GET /t +--- response_body +passed +--- no_error_log +[error]