Ajv: strictKeywords true causes array items false schema to incorrectly validate non-empty array

Created on 3 Sep 2020  路  5Comments  路  Source: ajv-validator/ajv

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.

bug report

All 5 comments

@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?

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

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

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.

it was actually fixed in 7402f98008c85a733c5d3ee48bac3fd3d648b16a, about to publish

Was this page helpful?
0 / 5 - 0 ratings

Related issues

busticated picture busticated  路  6Comments

vivekgalatage picture vivekgalatage  路  5Comments

vankop picture vankop  路  4Comments

gpietro picture gpietro  路  4Comments

sundriver picture sundriver  路  3Comments