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 2020/07/29 07:14:32 UTC

[GitHub] [incubator-apisix] shuaijinchao opened a new pull request #1920: change: add request-validation plugin input params schema valid.

shuaijinchao opened a new pull request #1920:
URL: https://github.com/apache/incubator-apisix/pull/1920


   ### What this PR does / why we need it:
   FIX #1881 
   
   ### 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] Is this PR backward compatible?
   


----------------------------------------------------------------
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.

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



[GitHub] [incubator-apisix] membphis merged pull request #1920: change: add request-validation plugin input params schema valid.

Posted by GitBox <gi...@apache.org>.
membphis merged pull request #1920:
URL: https://github.com/apache/incubator-apisix/pull/1920


   


----------------------------------------------------------------
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.

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



[GitHub] [incubator-apisix] shuaijinchao commented on pull request #1920: change: add request-validation plugin input params schema valid.

Posted by GitBox <gi...@apache.org>.
shuaijinchao commented on pull request #1920:
URL: https://github.com/apache/incubator-apisix/pull/1920#issuecomment-665152246


   @membphis already fixed, please recheck.


----------------------------------------------------------------
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.

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



[GitHub] [incubator-apisix] membphis commented on a change in pull request #1920: change: add request-validation plugin input params schema valid.

Posted by GitBox <gi...@apache.org>.
membphis commented on a change in pull request #1920:
URL: https://github.com/apache/incubator-apisix/pull/1920#discussion_r461700477



##########
File path: apisix/plugins/request-validation.lua
##########
@@ -42,7 +42,28 @@ local _M = {
 
 
 function _M.check_schema(conf)
-    return core.schema.check(schema, conf)
+    local ok, err = core.schema.check(schema, conf)
+    if not ok then
+        return nil, err
+    end
+
+    if conf.body_schema then

Review comment:
       this style is better.
   
   ```lua
   if conf.body_schema then
       local ok, err = ....
       if not ok then
           return ....
       end
   end
   ```

##########
File path: apisix/core/schema.lua
##########
@@ -36,16 +36,27 @@ local function create_validator(schema)
     return nil, res -- error message
 end
 
-
-function _M.check(schema, json)
+local function get_validator(schema)
     local validator, err = cached_validator(schema, nil,
                                 create_validator, schema)
+
+    if not validator then
+        return false, err

Review comment:
       `false` -> `nil` is better

##########
File path: apisix/plugins/request-validation.lua
##########
@@ -42,7 +42,28 @@ local _M = {
 
 
 function _M.check_schema(conf)
-    return core.schema.check(schema, conf)
+    local ok, err = core.schema.check(schema, conf)
+    if not ok then
+        return nil, err
+    end
+
+    if conf.body_schema then
+        ok, err = core.schema.valid(conf.body_schema)
+    end
+
+    if not ok then
+        return nil, err

Review comment:
       we should use `false` here




----------------------------------------------------------------
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.

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



[GitHub] [incubator-apisix] membphis commented on pull request #1920: change: add request-validation plugin input params schema valid.

Posted by GitBox <gi...@apache.org>.
membphis commented on pull request #1920:
URL: https://github.com/apache/incubator-apisix/pull/1920#issuecomment-665393769


   @shuaijinchao merged, many thx


----------------------------------------------------------------
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.

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