tokers commented on a change in pull request #5122:
URL: https://github.com/apache/apisix/pull/5122#discussion_r715250062



##########
File path: docs/en/latest/plugins/request-validation.md
##########
@@ -39,10 +39,11 @@ For more information on schema, refer to [JSON 
schema](https://github.com/api7/j
 
 ## Attributes
 
-| Name          | Type   | Requirement | Default | Valid | Description         
       |
-| ------------- | ------ | ----------- | ------- | ----- | 
-------------------------- |
-| header_schema | object | optional    |         |       | schema for the 
header data |
-| body_schema   | object | optional    |         |       | schema for the body 
data   |
+| Name             | Type   | Requirement | Default | Valid | Description      
          |
+| ---------------- | ------ | ----------- | ------- | ----- | 
-------------------------- |
+| header_schema    | object | optional    |         |       | schema for the 
header data |
+| body_schema      | object | optional    |         |       | schema for the 
body data   |
+| rejected_message | string | optional    |         |       | schema for the 
customize reject message |

Review comment:
       It's better to remind users that at least one of `header_schema` and 
`body_schema` should be specified.

##########
File path: docs/en/latest/plugins/request-validation.md
##########
@@ -82,7 +84,7 @@ curl --header "Content-Type: application/json" \
   http://127.0.0.1:9080/get
 ```
 
-If the schema is violated the plugin will yield a `400` bad request.
+If the schema is violated the plugin will yield a `400` bad request with 
reject response.

Review comment:
       ```suggestion
   If the schema is violated the plugin will yield a `400` bad request with the 
rejected response.
   ```

##########
File path: t/plugin/request-validation.t
##########
@@ -1449,3 +1449,147 @@ passed
 200
 --- no_error_log
 [error]
+
+
+
+=== TEST 35: add route (test request validation `header_schema.required` 
success with custom reject message)
+--- config
+    location /t {
+        content_by_lua_block {
+            local t = require("lib.test_admin").test
+            local code, body = t('/apisix/admin/routes/1',
+                 ngx.HTTP_PUT,
+                 [[{
+                    "plugins": {
+                        "request-validation": {
+                            "header_schema": {
+                                "type": "object",
+                                "properties": {
+                                    "test": {
+                                        "type": "string",
+                                        "enum": ["a", "b", "c"]
+                                    }
+                                },
+                                "required": ["test"]
+                            },
+                            "rejected_message": "customize reject message"
+                        }
+                    },
+                    "upstream": {
+                        "nodes": {
+                            "127.0.0.1:1982": 1
+                        },
+                        "type": "roundrobin"
+                    },
+                    "uri": "/plugin/request/validation"
+                }]])
+            if code >= 300 then
+                ngx.status = code
+            end
+            ngx.say(body)
+        }
+    }
+--- request
+GET /t
+--- response_body
+passed
+--- error_code chomp
+200
+--- no_error_log
+[error]
+
+
+
+=== TEST 36: add route (test request validation `body_schema.required` success 
with custom reject message)
+--- config
+    location /t {
+        content_by_lua_block {
+            local t = require("lib.test_admin").test
+            local code, body = t('/apisix/admin/routes/1',
+                 ngx.HTTP_PUT,
+                 [[{
+                    "plugins": {
+                        "request-validation": {
+                            "body_schema": {
+                                "type": "object",
+                                "properties": {
+                                    "test": {
+                                        "type": "string",
+                                        "enum": ["a", "b", "c"]
+                                    }
+                                },
+                                "required": ["test"]
+                            },
+                            "rejected_message": "customize reject message"
+                        }
+                    },
+                    "upstream": {
+                        "nodes": {
+                            "127.0.0.1:1982": 1
+                        },
+                        "type": "roundrobin"
+                    },
+                    "uri": "/plugin/request/validation"
+                }]])
+            if code >= 300 then
+                ngx.status = code
+            end
+            ngx.say(body)
+        }
+    }
+--- request
+GET /t
+--- response_body
+passed
+--- error_code chomp
+200
+--- no_error_log
+[error]
+
+
+
+=== TEST 37: add route (test request validation `header_schema.required` 
failure with custom reject message)

Review comment:
       Better add more test cases to test these routes.

##########
File path: docs/en/latest/plugins/request-validation.md
##########
@@ -252,3 +254,30 @@ curl http://127.0.0.1:9080/apisix/admin/routes/5 -H 
'X-API-KEY: edd1c9f034335f13
     }
 }
 ```
+
+**Custom reject message:**

Review comment:
       What about giving a request/response example for the custom rejected 
message?




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to