Skip to content

Commit

Permalink
change: check input params schema of request-validation plugin. (#1920
Browse files Browse the repository at this point in the history
)

FIX #1881
  • Loading branch information
shuaijinchao committed Jul 29, 2020
1 parent 520ef31 commit 552d700
Show file tree
Hide file tree
Showing 3 changed files with 1,162 additions and 3 deletions.
15 changes: 13 additions & 2 deletions apisix/core/schema.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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 nil, err
end

return validator, nil
end

function _M.check(schema, json)
local validator, err = get_validator(schema)

if not validator then
return false, err
end

return validator(json)
end

_M.valid = get_validator

return _M
21 changes: 20 additions & 1 deletion apisix/plugins/request-validation.lua
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,26 @@ 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 false, err
end

if conf.body_schema then
ok, err = core.schema.valid(conf.body_schema)
if not ok then
return false, err
end
end

if conf.header_schema then
ok, err = core.schema.valid(conf.header_schema)
if not ok then
return false, err
end
end

return true, nil
end


Expand Down

0 comments on commit 552d700

Please sign in to comment.