You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by me...@apache.org on 2020/08/10 02:00:04 UTC

[apisix] branch master updated: doc: update example syntax error for request-validation plugin. (#2030)

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 da08265  doc: update example syntax error for request-validation plugin. (#2030)
da08265 is described below

commit da082650c9ea8d1a26e13072edb01af27dd71e25
Author: Janko <sh...@gmail.com>
AuthorDate: Mon Aug 10 09:59:56 2020 +0800

    doc: update example syntax error for request-validation plugin. (#2030)
---
 doc/plugins/request-validation.md       | 138 +++++++++++++++++++++++++++-----
 doc/zh-cn/plugins/request-validation.md |  86 ++++++++++----------
 2 files changed, 162 insertions(+), 62 deletions(-)

diff --git a/doc/plugins/request-validation.md b/doc/plugins/request-validation.md
index e402fb2..b655b9a 100644
--- a/doc/plugins/request-validation.md
+++ b/doc/plugins/request-validation.md
@@ -105,7 +105,7 @@ curl http://127.0.0.1:9080/apisix/admin/routes/5 -H 'X-API-KEY: edd1c9f034335f13
 
 ## Examples:
 
-**Using ENUMS:**
+**`Enum` validate:**
 
 ```json
 {
@@ -124,30 +124,130 @@ curl http://127.0.0.1:9080/apisix/admin/routes/5 -H 'X-API-KEY: edd1c9f034335f13
 ```
 
 
-**JSON with multiple levels:**
+**`Boolean` validate:**
 
 ```json
 {
     "body_schema": {
         "type": "object",
-        "required": ["required_payload"],
+        "required": ["bool_payload"],
         "properties": {
-            "boolean_payload": {"type": "boolean"},
-            "child_element_name": {
-                "type": "object",
-                "properties": {
-                    "http_statuses": {
-                        "type": "array",
-                        "minItems": 1,
-                        "items": {
-                            "type": "integer",
-                            "minimum": 200,
-                            "maximum": 599
-                        },
-                        "uniqueItems": true,
-                        "default": [200, 201, 202, 203]
-                    }
-                }
+            "bool_payload": {
+                "type": "boolean",
+                "default": true
+            }
+        }
+    }
+}
+```
+
+**`Number` or `Integer` validate:**
+
+```json
+{
+    "body_schema": {
+        "type": "object",
+        "required": ["integer_payload"],
+        "properties": {
+            "integer_payload": {
+                "type": "integer",
+                "minimum": 1,
+                "maximum": 65535
+            }
+        }
+    }
+}
+```
+
+**`String` validate:**
+
+```json
+{
+    "body_schema": {
+        "type": "object",
+        "required": ["string_payload"],
+        "properties": {
+            "string_payload": {
+                "type": "string",
+                "minLength": 1,
+                "maxLength": 32
+            }
+        }
+    }
+}
+```
+
+**`Regex` validate:**
+
+```json
+{
+    "body_schema": {
+        "type": "object",
+        "required": ["regex_payload"],
+        "properties": {
+            "regex_payload": {
+                "type": "string",
+                "minLength": 1,
+                "maxLength": 32,
+                "pattern": "[[^[a-zA-Z0-9_]+$]]"
+            }
+        }
+    }
+}
+```
+
+
+**`Array` validate:**
+
+```json
+{
+    "body_schema": {
+        "type": "object",
+        "required": ["array_payload"],
+        "properties": {
+            "array_payload": {
+                "type": "array",
+                "minItems": 1,
+                "items": {
+                    "type": "integer",
+                    "minimum": 200,
+                    "maximum": 599
+                },
+                "uniqueItems": true,
+                "default": [200, 302]
+            }
+        }
+    }
+}
+```
+
+**Multi-field combination verification:**
+
+```json
+{
+    "body_schema": {
+        "type": "object",
+        "required": ["boolean_payload", "array_payload", "regex_payload"],
+        "properties": {
+            "boolean_payload": {
+                "type": "boolean"
+            },
+            "array_payload": {
+                "type": "array",
+                "minItems": 1,
+                "items": {
+                    "type": "integer",
+                    "minimum": 200,
+                    "maximum": 599
+                },
+                "uniqueItems": true,
+                "default": [200, 302]
+            },
+            "regex_payload": {
+                "type": "string",
+                "minLength": 1,
+                "maxLength": 32,
+                "pattern": "[[^[a-zA-Z0-9_]+$]]"
             }
         }
     }
diff --git a/doc/zh-cn/plugins/request-validation.md b/doc/zh-cn/plugins/request-validation.md
index 9882495..3418c1d 100644
--- a/doc/zh-cn/plugins/request-validation.md
+++ b/doc/zh-cn/plugins/request-validation.md
@@ -108,16 +108,16 @@ curl http://127.0.0.1:9080/apisix/admin/routes/5 -H 'X-API-KEY: edd1c9f034335f13
 
 **枚举(Enums)验证:**
 
-```shell
+```json
 {
     "body_schema": {
         "type": "object",
-        "required": ["emum_payload"],
+        "required": ["enum_payload"],
         "properties": {
-            "emum_payload": {
+            "enum_payload": {
                 "type": "string",
-                enum: ["enum_string_1", "enum_string_2"]
-                default = "enum_string_1"
+                "enum": ["enum_string_1", "enum_string_2"],
+                "default": "enum_string_1"
             }
         }
     }
@@ -126,15 +126,15 @@ curl http://127.0.0.1:9080/apisix/admin/routes/5 -H 'X-API-KEY: edd1c9f034335f13
 
 **布尔(Boolean)验证:**
 
-```shell
+```json
 {
     "body_schema": {
         "type": "object",
         "required": ["bool_payload"],
         "properties": {
             "bool_payload": {
-                type = "boolean",
-                default = true
+                "type": "boolean",
+                "default": true
             }
         }
     }
@@ -143,16 +143,16 @@ curl http://127.0.0.1:9080/apisix/admin/routes/5 -H 'X-API-KEY: edd1c9f034335f13
 
 **数字范围(Number or Integer)验证:**
 
-```shell
+```json
 {
     "body_schema": {
         "type": "object",
         "required": ["integer_payload"],
         "properties": {
             "integer_payload": {
-                type = "integer",
-                minimum = 1,
-                maximum = 65535
+                "type": "integer",
+                "minimum": 1,
+                "maximum": 65535
             }
         }
     }
@@ -161,16 +161,16 @@ curl http://127.0.0.1:9080/apisix/admin/routes/5 -H 'X-API-KEY: edd1c9f034335f13
 
 **字符串长度(String)验证:**
 
-```shell
+```json
 {
     "body_schema": {
         "type": "object",
         "required": ["string_payload"],
         "properties": {
             "string_payload": {
-                type = "string",
-                minLength = 1,
-                maxLength = 32
+                "type": "string",
+                "minLength": 1,
+                "maxLength": 32
             }
         }
     }
@@ -179,17 +179,17 @@ curl http://127.0.0.1:9080/apisix/admin/routes/5 -H 'X-API-KEY: edd1c9f034335f13
 
 **正则表达式(Regex)验证:**
 
-```shell
+```json
 {
     "body_schema": {
         "type": "object",
         "required": ["regex_payload"],
         "properties": {
             "regex_payload": {
-                type = "string",
-                minLength = 1,
-                maxLength = 32,
-                pattern = [[^[a-zA-Z0-9_]+$]]
+                "type": "string",
+                "minLength": 1,
+                "maxLength": 32,
+                "pattern": "[[^[a-zA-Z0-9_]+$]]"
             }
         }
     }
@@ -199,22 +199,22 @@ curl http://127.0.0.1:9080/apisix/admin/routes/5 -H 'X-API-KEY: edd1c9f034335f13
 
 **数组(Array)验证:**
 
-```shell
+```json
 {
     "body_schema": {
         "type": "object",
         "required": ["array_payload"],
         "properties": {
             "array_payload": {
-                type = "array",
-                minItems = 1,
-                items = {
-                    type = "integer",
-                    minimum = 200,
-                    maximum = 599
+                "type": "array",
+                "minItems": 1,
+                "items": {
+                    "type": "integer",
+                    "minimum": 200,
+                    "maximum": 599
                 },
-                uniqueItems = true,
-                default = {200, 302}
+                "uniqueItems": true,
+                "default": [200, 302]
             }
         }
     }
@@ -223,7 +223,7 @@ curl http://127.0.0.1:9080/apisix/admin/routes/5 -H 'X-API-KEY: edd1c9f034335f13
 
 **多字段组合(Multiple Fields)验证:**
 
-```shell
+```json
 {
     "body_schema": {
         "type": "object",
@@ -233,21 +233,21 @@ curl http://127.0.0.1:9080/apisix/admin/routes/5 -H 'X-API-KEY: edd1c9f034335f13
                 "type": "boolean"
             },
             "array_payload": {
-                type = "array",
-                minItems = 1,
-                items = {
-                    type = "integer",
-                    minimum = 200,
-                    maximum = 599
+                "type": "array",
+                "minItems": 1,
+                "items": {
+                    "type": "integer",
+                    "minimum": 200,
+                    "maximum": 599
                 },
-                uniqueItems = true,
-                default = {200, 302}
+                "uniqueItems": true,
+                "default": [200, 302]
             },
             "regex_payload": {
-                type = "string",
-                minLength = 1,
-                maxLength = 32,
-                pattern = [[^[a-zA-Z0-9_]+$]]
+                "type": "string",
+                "minLength": 1,
+                "maxLength": 32,
+                "pattern": "[[^[a-zA-Z0-9_]+$]]"
             }
         }
     }