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

API schema validation #6

Closed
membphis opened this issue May 7, 2019 · 4 comments
Closed

API schema validation #6

membphis opened this issue May 7, 2019 · 4 comments
Labels
enhancement New feature or request
Milestone

Comments

@membphis
Copy link
Member

membphis commented May 7, 2019

the goal:

  • code simplicity, we may add new feature to it
  • open source and good performance
  • pure Lua if possible

how about this:

-- JSON schema validation
https://github.com/jdesgats/ljsonschema
https://github.com/epoberezkin/ajv

@membphis membphis added the enhancement New feature or request label May 7, 2019
@membphis
Copy link
Member Author

membphis commented May 7, 2019

old version which I designed, I think we can drop it.

local schema = {
    -- num1 = 0,
    num2 = "num",
    num3 = "int",
    -- num4 = {0, max = 100, min = 10},
    num5 = {"int", range={1, 10}, max = 10, min = 1, default = 2},
    -- str1 = "",
    str2 = "string",
    str3 = {"string", default = "a", max_len = 10, min_len = 1, dict = {"a", "b", "c"}},
    -- bool1 = true,
    bool2 = "bool",
    bool3 = {"bool", default = true},
    -- table1 = {},
    table2 = "table",
    table2 = "array",
    table2 = "hash",
    table3 = {"array", elements = {"int", dict={3, 4, 5}, max_len = 10, min_len = 1}},
    table4 = {"hash", elements = {
        -- sub schema
        num2 = "num",
        num3 = "int",
    }},
}

-- white mode: 只允许 schema 中描述定义的 key 值,不允许有任何多余
-- black mode: 允许出现 schema 描述之外的 key 存在
local conf = {
    sss = 1, -- 报错
}

@tianchaijz
Copy link

Maybe you can try my https://github.com/tianchaijz/lua-resty-jsonschema validator.

@membphis
Copy link
Member Author

membphis commented Jun 9, 2019

@membphis membphis added this to the 0.5 milestone Jun 10, 2019
@membphis
Copy link
Member Author

implemented already: 1737fb7

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants