You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by GitBox <gi...@apache.org> on 2021/09/23 05:46:07 UTC

[GitHub] [apisix] leslie-tsang opened a new pull request #5122: feat: add rejected_message support for plugin request-validation

leslie-tsang opened a new pull request #5122:
URL: https://github.com/apache/apisix/pull/5122


   ### What this PR does / why we need it:
   <!--- Why is this change required? What problem does it solve? -->
   <!--- If it fixes an open issue, please link to the issue here. -->
   
   Ref #5108 
   
   ### Pre-submission checklist:
   
   * [x] Did you explain what problem does this PR solve? Or what new features have been added?
   * [x] Have you added corresponding test cases?
   * [x] Have you modified the corresponding document?
   * [x] Is this PR backward compatible? **If it is not backward compatible, please discuss on the [mailing list](https://github.com/apache/apisix/tree/master#community) first**
   


-- 
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: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix] leslie-tsang commented on a change in pull request #5122: feat: add rejected_message support for plugin request-validation

Posted by GitBox <gi...@apache.org>.
leslie-tsang commented on a change in pull request #5122:
URL: https://github.com/apache/apisix/pull/5122#discussion_r715950206



##########
File path: t/plugin/request-validation.t
##########
@@ -1449,3 +1448,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

Review comment:
       Removed.




-- 
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: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix] spacewander merged pull request #5122: feat: add rejected_message support for plugin request-validation

Posted by GitBox <gi...@apache.org>.
spacewander merged pull request #5122:
URL: https://github.com/apache/apisix/pull/5122


   


-- 
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: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix] tzssangglass commented on pull request #5122: feat: add rejected_message support for plugin request-validation

Posted by GitBox <gi...@apache.org>.
tzssangglass commented on pull request #5122:
URL: https://github.com/apache/apisix/pull/5122#issuecomment-927025243


   should add test case about hits the route with the request-validation plugin and get the rejected_message configured, such as:https://github.com/apache/apisix/blob/6162ca0ef92445fdd15b7a213655887b66cd4eea/t/plugin/uri-blocker.t#L442-L487


-- 
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: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix] tokers commented on pull request #5122: feat: add rejected_message support for plugin request-validation

Posted by GitBox <gi...@apache.org>.
tokers commented on pull request #5122:
URL: https://github.com/apache/apisix/pull/5122#issuecomment-927417869


   Changes now look good to me but what about adding some test cases to cover the use?


-- 
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: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix] leslie-tsang commented on a change in pull request #5122: feat: add rejected_message support for plugin request-validation

Posted by GitBox <gi...@apache.org>.
leslie-tsang commented on a change in pull request #5122:
URL: https://github.com/apache/apisix/pull/5122#discussion_r715950450



##########
File path: t/plugin/request-validation.t
##########
@@ -1449,3 +1448,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

Review comment:
       Removed.




-- 
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: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix] spacewander commented on a change in pull request #5122: feat: add rejected_message support for plugin request-validation

Posted by GitBox <gi...@apache.org>.
spacewander commented on a change in pull request #5122:
URL: https://github.com/apache/apisix/pull/5122#discussion_r715352701



##########
File path: t/plugin/request-validation.t
##########
@@ -1449,3 +1448,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

Review comment:
       The error_code: 200 is checked by default. We don't need to check it explicitly.

##########
File path: t/plugin/request-validation.t
##########
@@ -1449,3 +1448,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)

Review comment:
       TEST 35 & 36 are the same?




-- 
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: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix] leslie-tsang commented on a change in pull request #5122: feat: add rejected_message support for plugin request-validation

Posted by GitBox <gi...@apache.org>.
leslie-tsang commented on a change in pull request #5122:
URL: https://github.com/apache/apisix/pull/5122#discussion_r716349758



##########
File path: t/plugin/request-validation.t
##########
@@ -1445,7 +1406,255 @@ qr/table expected, got string/
 GET /t
 --- response_body
 passed
+--- 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_msg": "customize reject message for header_schema.required"
+                        }
+                    },
+                    "upstream": {
+                        "nodes": {
+                            "127.0.0.1:1982": 1
+                        },
+                        "type": "roundrobin"
+                    },
+                    "uri": "/opentracing"
+                }]])
+            if code >= 300 then
+                ngx.status = code
+            end
+            ngx.say(body)
+        }
+    }
+--- request
+GET /t
+--- response_body
+passed
+--- no_error_log
+[error]
+
+
+
+=== TEST 36: hit TEST 35 rule with empty header
+--- request
+GET /opentracing
+--- error_code: 400
+--- response_body chomp
+customize reject message for header_schema.required
+--- error_log eval
+qr/schema validation failed/
+
+
+
+=== TEST 37: hit TEST 35 rule with bad header value
+--- request
+GET /opentracing
+--- more_headers
+test: abc
+--- error_code: 400
+--- response_body chomp
+customize reject message for header_schema.required
+--- error_log eval
+qr/schema validation failed/
+
+
+
+=== TEST 38: pass TEST 35 rule

Review comment:
       We need to test it to make sure it work as expected




-- 
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: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix] leslie-tsang commented on a change in pull request #5122: feat: add rejected_message support for plugin request-validation

Posted by GitBox <gi...@apache.org>.
leslie-tsang commented on a change in pull request #5122:
URL: https://github.com/apache/apisix/pull/5122#discussion_r715268974



##########
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:
       Roger that




-- 
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: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix] leslie-tsang commented on pull request #5122: feat: add rejected_message support for plugin request-validation

Posted by GitBox <gi...@apache.org>.
leslie-tsang commented on pull request #5122:
URL: https://github.com/apache/apisix/pull/5122#issuecomment-925521983


   @tokers Any comment?


-- 
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: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix] spacewander commented on a change in pull request #5122: feat: add rejected_message support for plugin request-validation

Posted by GitBox <gi...@apache.org>.
spacewander commented on a change in pull request #5122:
URL: https://github.com/apache/apisix/pull/5122#discussion_r716344559



##########
File path: apisix/plugins/request-validation.lua
##########
@@ -94,11 +87,11 @@ function _M.rewrite(conf)
         if not body then
             local filename = ngx.req.get_body_file()
             if not filename then
-                return 500
+                return 500, conf.rejected_msg or nil

Review comment:
       ```suggestion
                   return 500, conf.rejected_msg
   ```
   
   The default value of conf.rejected_msg is nil

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

Review comment:
       ```suggestion
   **Custom rejected message:**
   ```

##########
File path: t/plugin/request-validation.t
##########
@@ -1445,7 +1406,255 @@ qr/table expected, got string/
 GET /t
 --- response_body
 passed
+--- 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_msg": "customize reject message for header_schema.required"
+                        }
+                    },
+                    "upstream": {
+                        "nodes": {
+                            "127.0.0.1:1982": 1
+                        },
+                        "type": "roundrobin"
+                    },
+                    "uri": "/opentracing"
+                }]])
+            if code >= 300 then
+                ngx.status = code
+            end
+            ngx.say(body)
+        }
+    }
+--- request
+GET /t
+--- response_body
+passed
+--- no_error_log
+[error]
+
+
+
+=== TEST 36: hit TEST 35 rule with empty header
+--- request
+GET /opentracing
+--- error_code: 400
+--- response_body chomp
+customize reject message for header_schema.required
+--- error_log eval
+qr/schema validation failed/
+
+
+
+=== TEST 37: hit TEST 35 rule with bad header value
+--- request
+GET /opentracing
+--- more_headers
+test: abc
+--- error_code: 400
+--- response_body chomp
+customize reject message for header_schema.required
+--- error_log eval
+qr/schema validation failed/
+
+
+
+=== TEST 38: pass TEST 35 rule

Review comment:
       We don't need a pass test for this feature as we don't change it?

##########
File path: docs/en/latest/plugins/request-validation.md
##########
@@ -39,10 +39,13 @@ 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   |
+> Note that at least one of `header_schema` and `body_schema` must be filled in.
+
+| 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:
       ```suggestion
   | rejected_message | string | optional    |         |       | the custom rejected message |
   ```

##########
File path: docs/zh/latest/plugins/request-validation.md
##########
@@ -38,10 +38,13 @@ title: request-validation
 
 ## 属性
 
-| Name          | Type   | Requirement | Default | Valid | Description                       |
-| ------------- | ------ | ----------- | ------- | ----- | --------------------------------- |
-| header_schema | object | 可选        |         |       | `header` 数据的 `schema` 数据结构 |
-| body_schema   | object | 可选        |         |       | `body` 数据的 `schema` 数据结构   |
+> 注意, `header_schema` 与 `body_schema` 至少填写其中一个
+
+| Name             | Type   | Requirement | Default | Valid | Description                       |
+| ---------------- | ------ | ----------- | ------- | ----- | --------------------------------- |
+| header_schema    | object | 可选        |         |       | `header` 数据的 `schema` 数据结构 |
+| body_schema      | object | 可选        |         |       | `body` 数据的 `schema` 数据结构   |
+| rejected_message | string | 可选        |         |       | 自定义拒绝信息的 `schema` 数据结构  |

Review comment:
       ```suggestion
   | rejected_message | string | 可选        |         |       | 自定义的拒绝信息  |
   ```

##########
File path: t/plugin/request-validation.t
##########
@@ -1445,7 +1406,255 @@ qr/table expected, got string/
 GET /t
 --- response_body
 passed
+--- 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_msg": "customize reject message for header_schema.required"
+                        }
+                    },
+                    "upstream": {
+                        "nodes": {
+                            "127.0.0.1:1982": 1
+                        },
+                        "type": "roundrobin"
+                    },
+                    "uri": "/opentracing"
+                }]])
+            if code >= 300 then
+                ngx.status = code
+            end
+            ngx.say(body)
+        }
+    }
+--- request
+GET /t
+--- response_body
+passed
+--- no_error_log
+[error]
+
+
+
+=== TEST 36: hit TEST 35 rule with empty header

Review comment:
       Better not use the `TEST xxx` in the title as it might be changed.




-- 
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: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix] leslie-tsang commented on a change in pull request #5122: feat: add rejected_message support for plugin request-validation

Posted by GitBox <gi...@apache.org>.
leslie-tsang commented on a change in pull request #5122:
URL: https://github.com/apache/apisix/pull/5122#discussion_r716348172



##########
File path: t/plugin/request-validation.t
##########
@@ -1445,7 +1406,255 @@ qr/table expected, got string/
 GET /t
 --- response_body
 passed
+--- 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_msg": "customize reject message for header_schema.required"
+                        }
+                    },
+                    "upstream": {
+                        "nodes": {
+                            "127.0.0.1:1982": 1
+                        },
+                        "type": "roundrobin"
+                    },
+                    "uri": "/opentracing"
+                }]])
+            if code >= 300 then
+                ngx.status = code
+            end
+            ngx.say(body)
+        }
+    }
+--- request
+GET /t
+--- response_body
+passed
+--- no_error_log
+[error]
+
+
+
+=== TEST 36: hit TEST 35 rule with empty header

Review comment:
       Make sense. I will fix it.




-- 
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: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix] leslie-tsang commented on a change in pull request #5122: feat: add rejected_message support for plugin request-validation

Posted by GitBox <gi...@apache.org>.
leslie-tsang commented on a change in pull request #5122:
URL: https://github.com/apache/apisix/pull/5122#discussion_r715950450



##########
File path: t/plugin/request-validation.t
##########
@@ -1449,3 +1448,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

Review comment:
       Removed.




-- 
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: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix] leslie-tsang commented on a change in pull request #5122: feat: add rejected_message support for plugin request-validation

Posted by GitBox <gi...@apache.org>.
leslie-tsang commented on a change in pull request #5122:
URL: https://github.com/apache/apisix/pull/5122#discussion_r715949580



##########
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:
       Done. 




-- 
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: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix] leslie-tsang commented on a change in pull request #5122: feat: add rejected_message support for plugin request-validation

Posted by GitBox <gi...@apache.org>.
leslie-tsang commented on a change in pull request #5122:
URL: https://github.com/apache/apisix/pull/5122#discussion_r715237554



##########
File path: apisix/plugins/request-validation.lua
##########
@@ -17,27 +17,20 @@
 local core          = require("apisix.core")
 local plugin_name   = "request-validation"
 local ngx           = ngx
-local io           = io
+local io            = io
 local req_read_body = ngx.req.read_body
 local req_get_body_data = ngx.req.get_body_data
 
 local schema = {
     type = "object",
+    properties = {
+        header_schema = {type = "object"},
+        body_schema = {type = "object"},
+        rejected_message = {type = "string"}

Review comment:
       Good idea.




-- 
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: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix] tzssangglass commented on pull request #5122: feat: add rejected_message support for plugin request-validation

Posted by GitBox <gi...@apache.org>.
tzssangglass commented on pull request #5122:
URL: https://github.com/apache/apisix/pull/5122#issuecomment-927028454


   BTW, I prefer to change `rejected_message` to `rejected_msg`, to keep similar as other plugins, such as `uri-blocker`, `limit-*`.


-- 
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: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix] tokers commented on a change in pull request #5122: feat: add rejected_message support for plugin request-validation

Posted by GitBox <gi...@apache.org>.
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: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix] leslie-tsang edited a comment on pull request #5122: feat: add rejected_message support for plugin request-validation

Posted by GitBox <gi...@apache.org>.
leslie-tsang edited a comment on pull request #5122:
URL: https://github.com/apache/apisix/pull/5122#issuecomment-927505242


   > The test should be submitted in the same PR of the feature.
   
   @spacewander [Test case](https://github.com/apache/apisix/pull/5122/files#diff-28ea6781a2de987036d0befc2217edc6cfc7e6c56837ddaea53fa7e726a8c3b6R1414-R1574) of feature has been added. 
   


-- 
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: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix] leslie-tsang commented on a change in pull request #5122: feat: add rejected_message support for plugin request-validation

Posted by GitBox <gi...@apache.org>.
leslie-tsang commented on a change in pull request #5122:
URL: https://github.com/apache/apisix/pull/5122#discussion_r716353019



##########
File path: t/plugin/request-validation.t
##########
@@ -1445,7 +1406,255 @@ qr/table expected, got string/
 GET /t
 --- response_body
 passed
+--- 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_msg": "customize reject message for header_schema.required"
+                        }
+                    },
+                    "upstream": {
+                        "nodes": {
+                            "127.0.0.1:1982": 1
+                        },
+                        "type": "roundrobin"
+                    },
+                    "uri": "/opentracing"
+                }]])
+            if code >= 300 then
+                ngx.status = code
+            end
+            ngx.say(body)
+        }
+    }
+--- request
+GET /t
+--- response_body
+passed
+--- no_error_log
+[error]
+
+
+
+=== TEST 36: hit TEST 35 rule with empty header

Review comment:
       @spacewander fixed.




-- 
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: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix] leslie-tsang commented on a change in pull request #5122: feat: add rejected_message support for plugin request-validation

Posted by GitBox <gi...@apache.org>.
leslie-tsang commented on a change in pull request #5122:
URL: https://github.com/apache/apisix/pull/5122#discussion_r715950032



##########
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:
       How about deal with it in another PR?




-- 
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: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix] leslie-tsang commented on pull request #5122: feat: add rejected_message support for plugin request-validation

Posted by GitBox <gi...@apache.org>.
leslie-tsang commented on pull request #5122:
URL: https://github.com/apache/apisix/pull/5122#issuecomment-927311594


   > should add test case about hits the route with the request-validation plugin and get the rejected_message configured, such as:
   > 
   > https://github.com/apache/apisix/blob/6162ca0ef92445fdd15b7a213655887b66cd4eea/t/plugin/uri-blocker.t#L442-L487
   
   Done


-- 
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: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix] tokers commented on a change in pull request #5122: feat: add rejected_message support for plugin request-validation

Posted by GitBox <gi...@apache.org>.
tokers commented on a change in pull request #5122:
URL: https://github.com/apache/apisix/pull/5122#discussion_r714675408



##########
File path: apisix/plugins/request-validation.lua
##########
@@ -17,27 +17,20 @@
 local core          = require("apisix.core")
 local plugin_name   = "request-validation"
 local ngx           = ngx
-local io           = io
+local io            = io
 local req_read_body = ngx.req.read_body
 local req_get_body_data = ngx.req.get_body_data
 
 local schema = {
     type = "object",
+    properties = {
+        header_schema = {type = "object"},
+        body_schema = {type = "object"},
+        rejected_message = {type = "string"}

Review comment:
       How about limiting its maximum length?




-- 
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: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix] leslie-tsang commented on pull request #5122: feat: add rejected_message support for plugin request-validation

Posted by GitBox <gi...@apache.org>.
leslie-tsang commented on pull request #5122:
URL: https://github.com/apache/apisix/pull/5122#issuecomment-927222267


   > should add test case about hits the route with the request-validation plugin and get the rejected_message configured, such as:
   > 
   > https://github.com/apache/apisix/blob/6162ca0ef92445fdd15b7a213655887b66cd4eea/t/plugin/uri-blocker.t#L442-L487
   
   Original test case don't cover the hit request as well. Test case issue will be fix in next commit.
   Thanks for suggestion. 


-- 
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: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix] leslie-tsang commented on pull request #5122: feat: add rejected_message support for plugin request-validation

Posted by GitBox <gi...@apache.org>.
leslie-tsang commented on pull request #5122:
URL: https://github.com/apache/apisix/pull/5122#issuecomment-927461970


   > Changes now look good to me but what about adding some test cases to cover the use?
   
   How about do it in next PR, this PR focus on add feature, next focus on use case.


-- 
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: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix] spacewander merged pull request #5122: feat: add rejected_message support for plugin request-validation

Posted by GitBox <gi...@apache.org>.
spacewander merged pull request #5122:
URL: https://github.com/apache/apisix/pull/5122


   


-- 
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: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix] leslie-tsang commented on a change in pull request #5122: feat: add rejected_message support for plugin request-validation

Posted by GitBox <gi...@apache.org>.
leslie-tsang commented on a change in pull request #5122:
URL: https://github.com/apache/apisix/pull/5122#discussion_r716031236



##########
File path: t/plugin/request-validation.t
##########
@@ -1449,3 +1448,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)

Review comment:
       Sure




-- 
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: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix] leslie-tsang commented on a change in pull request #5122: feat: add rejected_message support for plugin request-validation

Posted by GitBox <gi...@apache.org>.
leslie-tsang commented on a change in pull request #5122:
URL: https://github.com/apache/apisix/pull/5122#discussion_r715269515



##########
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:
       Roger that.




-- 
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: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix] leslie-tsang commented on a change in pull request #5122: feat: add rejected_message support for plugin request-validation

Posted by GitBox <gi...@apache.org>.
leslie-tsang commented on a change in pull request #5122:
URL: https://github.com/apache/apisix/pull/5122#discussion_r715354589



##########
File path: t/plugin/request-validation.t
##########
@@ -1449,3 +1448,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)

Review comment:
       No, TEST 35 test for `header_schema`, TEST 36 test for `body_schema`, with same properties
   




-- 
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: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix] tzssangglass commented on a change in pull request #5122: feat: add rejected_message support for plugin request-validation

Posted by GitBox <gi...@apache.org>.
tzssangglass commented on a change in pull request #5122:
URL: https://github.com/apache/apisix/pull/5122#discussion_r716003589



##########
File path: docs/zh/latest/plugins/request-validation.md
##########
@@ -38,10 +38,13 @@ title: request-validation
 
 ## 属性
 
-| Name          | Type   | Requirement | Default | Valid | Description                       |
-| ------------- | ------ | ----------- | ------- | ----- | --------------------------------- |
-| header_schema | object | 可选        |         |       | `header` 数据的 `schema` 数据结构 |
-| body_schema   | object | 可选        |         |       | `body` 数据的 `schema` 数据结构   |
+> 注意, `header_schema` 与 `body_schema` 必须至少填写其中一个

Review comment:
       ```suggestion
   > 注意, `header_schema` 与 `body_schema` 至少填写其中一个
   ```

##########
File path: t/plugin/request-validation.t
##########
@@ -1449,3 +1448,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)

Review comment:
        TEST 35 & 36 which actually checks the schema? Can we learn from this?https://github.com/apache/apisix/blob/6162ca0ef92445fdd15b7a213655887b66cd4eea/t/plugin/request-validation.t#L27-L45

##########
File path: t/plugin/request-validation.t
##########
@@ -1449,3 +1448,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)

Review comment:
       Can the following check schema be implemented in a similar way?




-- 
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: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix] leslie-tsang commented on pull request #5122: feat: add rejected_message support for plugin request-validation

Posted by GitBox <gi...@apache.org>.
leslie-tsang commented on pull request #5122:
URL: https://github.com/apache/apisix/pull/5122#issuecomment-927505242


   > The test should be submitted in the same PR of the feature.
   
   Test of feature has been added. 


-- 
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: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix] leslie-tsang commented on a change in pull request #5122: feat: add rejected_message support for plugin request-validation

Posted by GitBox <gi...@apache.org>.
leslie-tsang commented on a change in pull request #5122:
URL: https://github.com/apache/apisix/pull/5122#discussion_r715269187



##########
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:
       Good suggestion.




-- 
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: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org