api7 / jsonschema

Pure Lua JSON schema validator for Lua/LuaJIT
https://www.apiseven.com/
Apache License 2.0
120 stars 28 forks source link

propertyNames validation is missing #38

Open ypnos opened 4 years ago

ypnos commented 4 years ago

Currently it always returns true.

I cannot help out with this right now, this issue is to document the shortcoming so other users are aware.

membphis commented 4 years ago

please provide a mini example, we need it to confirm this issue

ypnos commented 4 years ago

Example LUA code:

local schema = {
  type = 'object',
  propertyNames = {
    minLength = 4
  },
}
local model = {
  Foo = true
}
local options = {match_pattern=function () return true end, name="Test"}
local validator = JsonSchema.generate_validator(schema, options)
local isValid, errorStr = validator(model)
print(isValid, errorStr)

Expected output: false property name too short Observed output: true nil

When using online validators, I receive the expected output with the following input.

JSON schema:

{
  "type": "object",
  "propertyNames": { "minLength": 4 }
}

JSON model:

{
  "Foo": true
}
membphis commented 4 years ago

@ypnos that is a todo feature, take a look at:

https://github.com/api7/jsonschema/blob/f8d2f40f9a3489a0c9430b81a40483982fdaa5f0/t/draft6.lua#L32 https://github.com/api7/jsonschema/blob/09dc6ed0524791c26772746a14cb4f83caeefc36/t/draft7.lua#L32

welcome PR to fix it