This is an automated email from the ASF dual-hosted git repository.

juzhiyuan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/apisix-dashboard.git


The following commit(s) were added to refs/heads/master by this push:
     new 6c90ad3  Update schema to master (#1080)
6c90ad3 is described below

commit 6c90ad340b566590187f2ade7e26310e18da0ac6
Author: liuxiran <[email protected]>
AuthorDate: Sat Dec 19 20:02:48 2020 -0600

    Update schema to master (#1080)
    
    * debug
    
    * fix: sort schema.json
    
    * fix: unit test remote_addr validate pattern
    
    * fix: update remote_addr validate failed msg
    
    Co-authored-by: nic-chen <[email protected]>
---
 api/build-tools/schema-sync.lua          |   4 ++
 api/conf/schema.json                     | 101 +++++++++++++++++++++++--------
 api/internal/core/store/validate_test.go |   6 +-
 api/test/e2e/route_remote_addr_test.go   |   6 +-
 4 files changed, 86 insertions(+), 31 deletions(-)

diff --git a/api/build-tools/schema-sync.lua b/api/build-tools/schema-sync.lua
index f0c49b3..7e96e96 100644
--- a/api/build-tools/schema-sync.lua
+++ b/api/build-tools/schema-sync.lua
@@ -22,6 +22,8 @@ local fake_module_list = {
     'cjson.safe',
     'bit',
     'lfs',
+    'ngx.worker',
+    'ngx.errlog',
     'ngx.process',
     'ngx.re',
     'net.url',
@@ -80,10 +82,12 @@ ngx.timer = {}
 ngx.location = {}
 ngx.socket = {}
 ngx.thread = {}
+ngx.worker = {}
 ngx.re.gmatch = empty_function
 ngx.shared = {
     ["plugin-api-breaker"] = {}
 }
+ngx.shared.internal_status = {}
 
 -- additional define for management
 local time_def = {
diff --git a/api/conf/schema.json b/api/conf/schema.json
index 855d620..76560bb 100644
--- a/api/conf/schema.json
+++ b/api/conf/schema.json
@@ -88,7 +88,7 @@
                        }]
                },
                "ip_def": [{
-                       "pattern": 
"^[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}$",
+                       "format": "ipv4",
                        "title": "IPv4",
                        "type": "string"
                }, {
@@ -96,11 +96,11 @@
                        "title": "IPv4/CIDR",
                        "type": "string"
                }, {
-                       "pattern": 
"^([a-fA-F0-9]{0,4}:){0,8}(:[a-fA-F0-9]{0,4}){0,8}([a-fA-F0-9]{0,4})?$",
+                       "format": "ipv6",
                        "title": "IPv6",
                        "type": "string"
                }, {
-                       "pattern": 
"^([a-fA-F0-9]{0,4}:){0,8}(:[a-fA-F0-9]{0,4}){0,8}([a-fA-F0-9]{0,4})?/[0-9]{1,3}$",
+                       "pattern": 
"^([a-fA-F0-9]{0,4}:){1,8}(:[a-fA-F0-9]{0,4}){0,8}([a-fA-F0-9]{0,4})?/[0-9]{1,3}$",
                        "title": "IPv6/CIDR",
                        "type": "string"
                }],
@@ -147,6 +147,41 @@
                },
                "route": {
                        "additionalProperties": false,
+                       "allOf": [{
+                               "oneOf": [{
+                                       "required": ["uri"]
+                               }, {
+                                       "required": ["uris"]
+                               }]
+                       }, {
+                               "oneOf": [{
+                                       "not": {
+                                               "anyOf": [{
+                                                       "required": ["host"]
+                                               }, {
+                                                       "required": ["hosts"]
+                                               }]
+                                       }
+                               }, {
+                                       "required": ["host"]
+                               }, {
+                                       "required": ["hosts"]
+                               }]
+                       }, {
+                               "oneOf": [{
+                                       "not": {
+                                               "anyOf": [{
+                                                       "required": 
["remote_addr"]
+                                               }, {
+                                                       "required": 
["remote_addrs"]
+                                               }]
+                                       }
+                               }, {
+                                       "required": ["remote_addr"]
+                               }, {
+                                       "required": ["remote_addrs"]
+                               }]
+                       }],
                        "anyOf": [{
                                "required": ["plugins", "uri"]
                        }, {
@@ -199,6 +234,7 @@
                                                "pattern": 
"^\\*?[0-9a-zA-Z-.]+$",
                                                "type": "string"
                                        },
+                                       "minItems": 1,
                                        "type": "array",
                                        "uniqueItems": true
                                },
@@ -250,7 +286,7 @@
                                },
                                "remote_addr": {
                                        "anyOf": [{
-                                               "pattern": 
"^[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}$",
+                                               "format": "ipv4",
                                                "title": "IPv4",
                                                "type": "string"
                                        }, {
@@ -258,11 +294,11 @@
                                                "title": "IPv4/CIDR",
                                                "type": "string"
                                        }, {
-                                               "pattern": 
"^([a-fA-F0-9]{0,4}:){0,8}(:[a-fA-F0-9]{0,4}){0,8}([a-fA-F0-9]{0,4})?$",
+                                               "format": "ipv6",
                                                "title": "IPv6",
                                                "type": "string"
                                        }, {
-                                               "pattern": 
"^([a-fA-F0-9]{0,4}:){0,8}(:[a-fA-F0-9]{0,4}){0,8}([a-fA-F0-9]{0,4})?/[0-9]{1,3}$",
+                                               "pattern": 
"^([a-fA-F0-9]{0,4}:){1,8}(:[a-fA-F0-9]{0,4}){0,8}([a-fA-F0-9]{0,4})?/[0-9]{1,3}$",
                                                "title": "IPv6/CIDR",
                                                "type": "string"
                                        }],
@@ -272,7 +308,7 @@
                                "remote_addrs": {
                                        "items": {
                                                "anyOf": [{
-                                                       "pattern": 
"^[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}$",
+                                                       "format": "ipv4",
                                                        "title": "IPv4",
                                                        "type": "string"
                                                }, {
@@ -280,17 +316,18 @@
                                                        "title": "IPv4/CIDR",
                                                        "type": "string"
                                                }, {
-                                                       "pattern": 
"^([a-fA-F0-9]{0,4}:){0,8}(:[a-fA-F0-9]{0,4}){0,8}([a-fA-F0-9]{0,4})?$",
+                                                       "format": "ipv6",
                                                        "title": "IPv6",
                                                        "type": "string"
                                                }, {
-                                                       "pattern": 
"^([a-fA-F0-9]{0,4}:){0,8}(:[a-fA-F0-9]{0,4}){0,8}([a-fA-F0-9]{0,4})?/[0-9]{1,3}$",
+                                                       "pattern": 
"^([a-fA-F0-9]{0,4}:){1,8}(:[a-fA-F0-9]{0,4}){0,8}([a-fA-F0-9]{0,4})?/[0-9]{1,3}$",
                                                        "title": "IPv6/CIDR",
                                                        "type": "string"
                                                }],
                                                "description": "client IP",
                                                "type": "string"
                                        },
+                                       "minItems": 1,
                                        "type": "array",
                                        "uniqueItems": true
                                },
@@ -313,6 +350,12 @@
                                "service_protocol": {
                                        "enum": ["grpc", "http"]
                                },
+                               "status": {
+                                       "default": 1,
+                                       "description": "route status, 1 to 
enable, 0 to disable",
+                                       "enum": [0, 1],
+                                       "type": "integer"
+                               },
                                "update_time": {
                                        "type": "integer"
                                },
@@ -707,6 +750,7 @@
                                                "description": "HTTP uri",
                                                "type": "string"
                                        },
+                                       "minItems": 1,
                                        "type": "array",
                                        "uniqueItems": true
                                },
@@ -1281,7 +1325,7 @@
                                },
                                "remote_addr": {
                                        "anyOf": [{
-                                               "pattern": 
"^[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}$",
+                                               "format": "ipv4",
                                                "title": "IPv4",
                                                "type": "string"
                                        }, {
@@ -1289,11 +1333,11 @@
                                                "title": "IPv4/CIDR",
                                                "type": "string"
                                        }, {
-                                               "pattern": 
"^([a-fA-F0-9]{0,4}:){0,8}(:[a-fA-F0-9]{0,4}){0,8}([a-fA-F0-9]{0,4})?$",
+                                               "format": "ipv6",
                                                "title": "IPv6",
                                                "type": "string"
                                        }, {
-                                               "pattern": 
"^([a-fA-F0-9]{0,4}:){0,8}(:[a-fA-F0-9]{0,4}){0,8}([a-fA-F0-9]{0,4})?/[0-9]{1,3}$",
+                                               "pattern": 
"^([a-fA-F0-9]{0,4}:){1,8}(:[a-fA-F0-9]{0,4}){0,8}([a-fA-F0-9]{0,4})?/[0-9]{1,3}$",
                                                "title": "IPv6/CIDR",
                                                "type": "string"
                                        }],
@@ -1302,7 +1346,7 @@
                                },
                                "server_addr": {
                                        "anyOf": [{
-                                               "pattern": 
"^[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}$",
+                                               "format": "ipv4",
                                                "title": "IPv4",
                                                "type": "string"
                                        }, {
@@ -1310,11 +1354,11 @@
                                                "title": "IPv4/CIDR",
                                                "type": "string"
                                        }, {
-                                               "pattern": 
"^([a-fA-F0-9]{0,4}:){0,8}(:[a-fA-F0-9]{0,4}){0,8}([a-fA-F0-9]{0,4})?$",
+                                               "format": "ipv6",
                                                "title": "IPv6",
                                                "type": "string"
                                        }, {
-                                               "pattern": 
"^([a-fA-F0-9]{0,4}:){0,8}(:[a-fA-F0-9]{0,4}){0,8}([a-fA-F0-9]{0,4})?/[0-9]{1,3}$",
+                                               "pattern": 
"^([a-fA-F0-9]{0,4}:){1,8}(:[a-fA-F0-9]{0,4}){0,8}([a-fA-F0-9]{0,4})?/[0-9]{1,3}$",
                                                "title": "IPv6/CIDR",
                                                "type": "string"
                                        }],
@@ -2307,7 +2351,7 @@
                                "properties": {
                                        "allow_credential": {
                                                "default": false,
-                                               "description": "allow client 
append credential. according to CORS specification, if you set this option to 
'true', you can not use '*' for other options.",
+                                               "description": "allow client 
append credential. according to CORS specification,if you set this option to 
'true', you can not use '*' for other options.",
                                                "type": "boolean"
                                        },
                                        "allow_headers": {
@@ -2406,7 +2450,6 @@
                                "minProperties": 1,
                                "properties": {
                                        "abort": {
-                                               "minProperties": 1,
                                                "properties": {
                                                        "body": {
                                                                "minLength": 0,
@@ -2422,10 +2465,10 @@
                                                                "type": 
"integer"
                                                        }
                                                },
+                                               "required": ["http_status"],
                                                "type": "object"
                                        },
                                        "delay": {
-                                               "minProperties": 1,
                                                "properties": {
                                                        "duration": {
                                                                "minimum": 0,
@@ -2437,6 +2480,7 @@
                                                                "type": 
"integer"
                                                        }
                                                },
+                                               "required": ["duration"],
                                                "type": "object"
                                        }
                                },
@@ -2620,7 +2664,7 @@
                                                "whitelist": {
                                                        "items": {
                                                                "anyOf": [{
-                                                                       
"pattern": "^[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}$",
+                                                                       
"format": "ipv4",
                                                                        
"title": "IPv4",
                                                                        "type": 
"string"
                                                                }, {
@@ -2628,11 +2672,11 @@
                                                                        
"title": "IPv4/CIDR",
                                                                        "type": 
"string"
                                                                }, {
-                                                                       
"pattern": 
"^([a-fA-F0-9]{0,4}:){0,8}(:[a-fA-F0-9]{0,4}){0,8}([a-fA-F0-9]{0,4})?$",
+                                                                       
"format": "ipv6",
                                                                        
"title": "IPv6",
                                                                        "type": 
"string"
                                                                }, {
-                                                                       
"pattern": 
"^([a-fA-F0-9]{0,4}:){0,8}(:[a-fA-F0-9]{0,4}){0,8}([a-fA-F0-9]{0,4})?/[0-9]{1,3}$",
+                                                                       
"pattern": 
"^([a-fA-F0-9]{0,4}:){1,8}(:[a-fA-F0-9]{0,4}){0,8}([a-fA-F0-9]{0,4})?/[0-9]{1,3}$",
                                                                        
"title": "IPv6/CIDR",
                                                                        "type": 
"string"
                                                                }]
@@ -2649,7 +2693,7 @@
                                                "blacklist": {
                                                        "items": {
                                                                "anyOf": [{
-                                                                       
"pattern": "^[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}$",
+                                                                       
"format": "ipv4",
                                                                        
"title": "IPv4",
                                                                        "type": 
"string"
                                                                }, {
@@ -2657,11 +2701,11 @@
                                                                        
"title": "IPv4/CIDR",
                                                                        "type": 
"string"
                                                                }, {
-                                                                       
"pattern": 
"^([a-fA-F0-9]{0,4}:){0,8}(:[a-fA-F0-9]{0,4}){0,8}([a-fA-F0-9]{0,4})?$",
+                                                                       
"format": "ipv6",
                                                                        
"title": "IPv6",
                                                                        "type": 
"string"
                                                                }, {
-                                                                       
"pattern": 
"^([a-fA-F0-9]{0,4}:){0,8}(:[a-fA-F0-9]{0,4}){0,8}([a-fA-F0-9]{0,4})?/[0-9]{1,3}$",
+                                                                       
"pattern": 
"^([a-fA-F0-9]{0,4}:){1,8}(:[a-fA-F0-9]{0,4}){0,8}([a-fA-F0-9]{0,4})?/[0-9]{1,3}$",
                                                                        
"title": "IPv6/CIDR",
                                                                        "type": 
"string"
                                                                }]
@@ -2891,6 +2935,7 @@
                                                "type": "integer"
                                        },
                                        "key": {
+                                               "default": "remote_addr",
                                                "enum": ["consumer_name", 
"http_x_forwarded_for", "http_x_real_ip", "remote_addr", "server_addr", 
"service_id"],
                                                "type": "string"
                                        },
@@ -2910,7 +2955,7 @@
                                                "type": "integer"
                                        }
                                },
-                               "required": ["count", "key", "time_window"],
+                               "required": ["count", "time_window"],
                                "type": "object"
                        }
                },
@@ -3240,6 +3285,12 @@
                                "type": "object"
                        }
                },
+               "server-info": {
+                       "schema": {
+                               "additionalProperties": false,
+                               "type": "object"
+                       }
+               },
                "serverless-post-function": {
                        "schema": {
                                "properties": {
diff --git a/api/internal/core/store/validate_test.go 
b/api/internal/core/store/validate_test.go
index fd38dbf..b50586d 100644
--- a/api/internal/core/store/validate_test.go
+++ b/api/internal/core/store/validate_test.go
@@ -362,7 +362,7 @@ func TestAPISIXJsonSchemaValidator_Route_checkRemoteAddr(t 
*testing.T) {
                                },
                                "remote_addr": "127.0.0."
                        }`,
-                       wantValidateErr: fmt.Errorf("schema validate failed: 
remote_addr: Must validate at least one schema (anyOf)\nremote_addr: Does not 
match pattern '^[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}$'"),
+                       wantValidateErr: fmt.Errorf("schema validate failed: 
remote_addr: Must validate at least one schema (anyOf)\nremote_addr: Does not 
match format 'ipv4'"),
                },
                {
                        caseDesc: "correct remote_addrs",
@@ -395,7 +395,7 @@ func TestAPISIXJsonSchemaValidator_Route_checkRemoteAddr(t 
*testing.T) {
                                },
                                "remote_addrs": ["127.0.0.", "192.0.0.0/128", 
"::1"]
                        }`,
-                       wantValidateErr: fmt.Errorf("schema validate failed: 
remote_addrs.0: Must validate at least one schema (anyOf)\nremote_addrs.0: Does 
not match pattern 
'^[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}$'\nremote_addrs.1: Must validate 
at least one schema (anyOf)\nremote_addrs.1: Does not match pattern 
'^[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}$'"),
+                       wantValidateErr: fmt.Errorf("schema validate failed: 
remote_addrs.0: Must validate at least one schema (anyOf)\nremote_addrs.0: Does 
not match format 'ipv4'\nremote_addrs.1: Must validate at least one schema 
(anyOf)\nremote_addrs.1: Does not match format 'ipv4'"),
                },
                {
                        caseDesc: "invalid remote_addrs (an empty string item)",
@@ -412,7 +412,7 @@ func TestAPISIXJsonSchemaValidator_Route_checkRemoteAddr(t 
*testing.T) {
                                },
                                "remote_addrs": [""]
                        }`,
-                       wantValidateErr: fmt.Errorf("schema validate failed: 
invalid field remote_addrs"),
+                       wantValidateErr: fmt.Errorf("schema validate failed: 
remote_addrs.0: Must validate at least one schema (anyOf)\nremote_addrs.0: Does 
not match format 'ipv4'"),
                },
        }
 
diff --git a/api/test/e2e/route_remote_addr_test.go 
b/api/test/e2e/route_remote_addr_test.go
index 8cdf6e3..7bceed0 100644
--- a/api/test/e2e/route_remote_addr_test.go
+++ b/api/test/e2e/route_remote_addr_test.go
@@ -42,7 +42,7 @@ func TestRoute_add_with_invalid_remote_addr(t *testing.T) {
                                }`,
                        Headers:      map[string]string{"Authorization": token},
                        ExpectStatus: http.StatusBadRequest,
-                       ExpectBody:   "\"code\":10000,\"message\":\"schema 
validate failed: remote_addr: Must validate at least one schema 
(anyOf)\\nremote_addr: Does not match pattern 
'^[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}$'\"",
+                       ExpectBody:   "\"code\":10000,\"message\":\"schema 
validate failed: remote_addr: Must validate at least one schema 
(anyOf)\\nremote_addr: Does not match format 'ipv4'\"",
                },
                {
                        caseDesc:     "verify route",
@@ -72,7 +72,7 @@ func TestRoute_add_with_invalid_remote_addr(t *testing.T) {
                                }`,
                        Headers:      map[string]string{"Authorization": token},
                        ExpectStatus: http.StatusBadRequest,
-                       ExpectBody:   "\"code\":10000,\"message\":\"schema 
validate failed: remote_addr: Must validate at least one schema 
(anyOf)\\nremote_addr: Does not match pattern 
'^[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}$'\"",
+                       ExpectBody:   "\"code\":10000,\"message\":\"schema 
validate failed: remote_addr: Must validate at least one schema 
(anyOf)\\nremote_addr: Does not match format 'ipv4'\"",
                },
                {
                        caseDesc:     "verify route",
@@ -102,7 +102,7 @@ func TestRoute_add_with_invalid_remote_addr(t *testing.T) {
                                }`,
                        Headers:      map[string]string{"Authorization": token},
                        ExpectStatus: http.StatusBadRequest,
-                       ExpectBody:   "\"code\":10000,\"message\":\"schema 
validate failed: remote_addrs.1: Must validate at least one schema 
(anyOf)\\nremote_addrs.1: Does not match pattern 
'^[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}$'\"",
+                       ExpectBody:   "\"code\":10000,\"message\":\"schema 
validate failed: remote_addrs.1: Must validate at least one schema 
(anyOf)\\nremote_addrs.1: Does not match format 'ipv4'\"",
                },
                {
                        caseDesc:     "verify route",

Reply via email to