Keyword error for if-clause failure

node v6.17.1
version: 2.0.0
endpointsharetweet
This is a playground to test JavaScript. It runs a completely standard copy of Node.js on a virtual server created just for you. Every one of npm’s 300,000+ packages are pre-installed, so try it out:
const Ajv = require("ajv"); const ajv = new Ajv({ "allErrors": true, "jsonPointers": true }); require('ajv-errors')(ajv); const schema = { "type":"object", "properties": { "foo": { "type":"string", "if":{ "maxLength":5 }, "then":{ "enum":["bar"], "errorMessage":{ "enum":"foo must be 'bar'" } }, "else":false, "errorMessage":{ "_":"if-clause failed." } } } } let validate = ajv.compile(schema); console.log(validate({"foo":"baz"})); console.log("Errors:",ajv.errorsText(validate.errors));
Loading…

no comments

    sign in to comment