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/25 07:14:49 UTC

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

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