Skip to content

Commit

Permalink
optimize: updated the error message after updated new jsonschema. (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
membphis authored and moonming committed Jan 2, 2020
1 parent 1069c3d commit f22f494
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 11 deletions.
4 changes: 4 additions & 0 deletions lua/apisix/schema_def.lua
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,10 @@ local health_checker = {
}
},
additionalProperties = false,
anyOf = {
{required = {"active"}},
{required = {"active", "passive"}},
},
}


Expand Down
2 changes: 1 addition & 1 deletion rockspec/apisix-master-0.rockspec
Original file line number Diff line number Diff line change
Expand Up @@ -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",
}

Expand Down
48 changes: 48 additions & 0 deletions t/admin/health-check.t
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down Expand Up @@ -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]
8 changes: 4 additions & 4 deletions t/admin/routes.t
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down Expand Up @@ -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]

Expand All @@ -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]

Expand Down Expand Up @@ -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]

Expand Down
6 changes: 3 additions & 3 deletions t/admin/services.t
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand All @@ -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]

Expand Down Expand Up @@ -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]

Expand Down
4 changes: 2 additions & 2 deletions t/admin/upstream.t
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down Expand Up @@ -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]

Expand Down
2 changes: 1 addition & 1 deletion t/plugin/ip-restriction.t
Original file line number Diff line number Diff line change
Expand Up @@ -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]

0 comments on commit f22f494

Please sign in to comment.