From 33e3e4cfbbbb211e642c55c70c71928770143b4d Mon Sep 17 00:00:00 2001 From: Yuansheng Date: Thu, 2 Jan 2020 13:57:01 +0800 Subject: [PATCH] optimize: updated the error message after updated new `jsonschema`. --- lua/apisix/schema_def.lua | 4 +++ rockspec/apisix-master-0.rockspec | 2 +- t/admin/health-check.t | 48 +++++++++++++++++++++++++++++++ t/admin/routes.t | 8 +++--- t/admin/services.t | 6 ++-- t/admin/upstream.t | 4 +-- t/plugin/ip-restriction.t | 2 +- 7 files changed, 63 insertions(+), 11 deletions(-) diff --git a/lua/apisix/schema_def.lua b/lua/apisix/schema_def.lua index 1406c49e46bf..c4ab6273d02b 100644 --- a/lua/apisix/schema_def.lua +++ b/lua/apisix/schema_def.lua @@ -218,6 +218,10 @@ local health_checker = { } }, additionalProperties = false, + anyOf = { + {required = {"active"}}, + {required = {"active", "passive"}}, + }, } diff --git a/rockspec/apisix-master-0.rockspec b/rockspec/apisix-master-0.rockspec index b7c2c25f4b28..f8cd330b84bd 100644 --- a/rockspec/apisix-master-0.rockspec +++ b/rockspec/apisix-master-0.rockspec @@ -46,7 +46,7 @@ dependencies = { "luafilesystem = 1.7.0-2", "lua-tinyyaml = 0.1", "lua-resty-prometheus = 1.0", - "jsonschema = 0.4", + "jsonschema = 0.5", "lua-resty-ipmatcher = 0.3", } diff --git a/t/admin/health-check.t b/t/admin/health-check.t index c05606244dae..8680768e75cd 100644 --- a/t/admin/health-check.t +++ b/t/admin/health-check.t @@ -106,6 +106,14 @@ passed local t = require("lib.test_admin").test req_data.upstream.checks = json.decode([[{ + "active": { + "http_path": "/status", + "host": "foo.com", + "healthy": { + "interval": 2, + "successes": 1 + } + }, "passive": { "healthy": { "http_statuses": [200, 201], @@ -428,3 +436,43 @@ GET /t {"error_msg":"invalid configuration: property \"upstream\" validation failed: property \"checks\" validation failed: property \"active\" validation failed: property \"req_headers\" validation failed: failed to validate item 2: wrong type: expected string, got number"} --- no_error_log [error] + + + +=== TEST 12: only passive +--- config + location /t { + content_by_lua_block { + local t = require("lib.test_admin").test + + req_data.upstream.checks = json.decode([[{ + "passive": { + "healthy": { + "http_statuses": [200, 201], + "successes": 1 + }, + "unhealthy": { + "http_statuses": [500], + "http_failures": 2 + } + } + }]]) + exp_data.node.value.upstream.checks = req_data.upstream.checks + + local code, body = t('/apisix/admin/routes/1', + ngx.HTTP_PUT, + req_data, + exp_data + ) + + ngx.status = code + ngx.print(body) + } + } +--- request +GET /t +--- error_code: 400 +--- response_body +{"error_msg":"invalid configuration: property \"upstream\" validation failed: property \"checks\" validation failed: object matches none of the requireds: [\"active\"] or [\"active\",\"passive\"]"} +--- no_error_log +[error] diff --git a/t/admin/routes.t b/t/admin/routes.t index 48051c2674aa..57bf61452e9b 100644 --- a/t/admin/routes.t +++ b/t/admin/routes.t @@ -447,7 +447,7 @@ GET /t GET /t --- error_code: 400 --- response_body -{"error_msg":"invalid configuration: property \"service_id\" validation failed: object matches none of the alternatives"} +{"error_msg":"invalid configuration: property \"service_id\" validation failed: object matches none of the requireds"} --- no_error_log [error] @@ -555,7 +555,7 @@ passed GET /t --- error_code: 400 --- response_body -{"error_msg":"invalid configuration: property \"id\" validation failed: object matches none of the alternatives"} +{"error_msg":"invalid configuration: property \"id\" validation failed: object matches none of the requireds"} --- no_error_log [error] @@ -582,7 +582,7 @@ GET /t GET /t --- error_code: 400 --- response_body -{"error_msg":"invalid configuration: property \"upstream_id\" validation failed: object matches none of the alternatives"} +{"error_msg":"invalid configuration: property \"upstream_id\" validation failed: object matches none of the requireds"} --- no_error_log [error] @@ -949,7 +949,7 @@ passed GET /t --- error_code: 400 --- response_body -{"error_msg":"invalid configuration: property \"remote_addr\" validation failed: object matches none of the alternatives"} +{"error_msg":"invalid configuration: property \"remote_addr\" validation failed: object matches none of the requireds"} --- no_error_log [error] diff --git a/t/admin/services.t b/t/admin/services.t index e5629757c847..d9e2f9e02771 100644 --- a/t/admin/services.t +++ b/t/admin/services.t @@ -461,7 +461,7 @@ passed GET /t --- error_code: 400 --- response_body -{"error_msg":"invalid configuration: property \"id\" validation failed: object matches none of the alternatives"} +{"error_msg":"invalid configuration: property \"id\" validation failed: object matches none of the requireds"} --- no_error_log [error] @@ -488,7 +488,7 @@ GET /t GET /t --- error_code: 400 --- response_body -{"error_msg":"invalid configuration: property \"id\" validation failed: object matches none of the alternatives"} +{"error_msg":"invalid configuration: property \"id\" validation failed: object matches none of the requireds"} --- no_error_log [error] @@ -542,7 +542,7 @@ GET /t GET /t --- error_code: 400 --- response_body -{"error_msg":"invalid configuration: property \"upstream_id\" validation failed: object matches none of the alternatives"} +{"error_msg":"invalid configuration: property \"upstream_id\" validation failed: object matches none of the requireds"} --- no_error_log [error] diff --git a/t/admin/upstream.t b/t/admin/upstream.t index 9b0d7f309473..6ca7308927f7 100644 --- a/t/admin/upstream.t +++ b/t/admin/upstream.t @@ -360,7 +360,7 @@ passed GET /t --- error_code: 400 --- response_body -{"error_msg":"invalid configuration: property \"id\" validation failed: object matches none of the alternatives"} +{"error_msg":"invalid configuration: property \"id\" validation failed: object matches none of the requireds"} --- no_error_log [error] @@ -390,7 +390,7 @@ GET /t GET /t --- error_code: 400 --- response_body -{"error_msg":"invalid configuration: property \"id\" validation failed: object matches none of the alternatives"} +{"error_msg":"invalid configuration: property \"id\" validation failed: object matches none of the requireds"} --- no_error_log [error] diff --git a/t/plugin/ip-restriction.t b/t/plugin/ip-restriction.t index ac2371c5508b..94038194f282 100644 --- a/t/plugin/ip-restriction.t +++ b/t/plugin/ip-restriction.t @@ -565,6 +565,6 @@ GET /hello GET /t --- response_body invalid ip address: ::1/129 -property "whitelist" validation failed: failed to validate item 1: object matches none of the alternatives +property "whitelist" validation failed: failed to validate item 1: object matches none of the requireds --- no_error_log [error]