Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

change: add request-validation plugin input params schema valid. #1920

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
shuaijinchao marked this conversation as resolved.
Show resolved Hide resolved
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