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

strictKeywords true causes array items false schema to incorrectly validate non-empty array #1270

Closed
mfulton26 opened this issue Sep 3, 2020 · 5 comments

Comments

@mfulton26
Copy link

What version of Ajv are you using? Does the issue happen if you use the latest version?

6.12.4 (latest)

Ajv options object

{ strictKeywords: true }

JSON Schema

{ "type": "array", "items": false }

Sample data

[1]

Your code

const Ajv = require("ajv");

const ajv = new Ajv({ strictKeywords: true });

ajv.validate({ type: "array", items: false }, [1]);

console.log(ajv.errors);

Validation result, data AFTER validation, error messages

null

What results did you expect?

same validation error as when strictKeywords is false or "log"

[
  {
    "keyword": "false schema",
    "dataPath": "[0]",
    "schemaPath": "#/items/false schema",
    "params": {},
    "message": "boolean schema is false"
  }
]

Are you going to resolve the issue?

Am I going to submit a PR? Not planning on it. Am I good with closing the issue after feedback? Yes.

@epoberezkin
Copy link
Member

@mfulton26 thanks for the report - reproduced here: https://runkit.com/esp/5f51452a3e8d0f001abfa741.

I am wondering - are you using items: false to require an empty array?

@Relequestual
Copy link
Contributor

They were, but we discussed the correct way to determine that on the mentioned issue which is now closed from the JSON Schema github =]

@mfulton26
Copy link
Author

Yes, exactly. I know there are other ways and honestly using maxItems has grown on my as it gives an error message that fits my use case better but I was surprised that using strictKeywords was what caused the unexpected change in validation

@epoberezkin
Copy link
Member

It's the bug that has to be fixed for sure - thanks for reporting. items: false is quite concise actually - I've just never seen it before... In allErrors mode ajv is likely "to validate" each item and report many errors - I may add some optimisation to v7 for it.

@epoberezkin
Copy link
Member

it was actually fixed in 7402f98, about to publish

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

3 participants