AJV inconsistent errors in different versions

node v8.17.0
version: master
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@6.9.0"); // This version will produce errors //const Ajv = require("ajv@6.5.0"); // Thiw version is just fine (Wanted result) // (un)comment lines on top -------------------------------------- const jsonSchemaDraft06 = require("ajv/lib/refs/json-schema-draft-06.json"); const ajv = new Ajv({ allErrors: true, coerceTypes: 'array', removeAdditional: 'all', useDefaults: 'shared', verbose: true, }); ajv.addMetaSchema(jsonSchemaDraft06); ajv.addKeyword('minTrimmedLength', { compile (length) { return function (sample) { return sample.trim().length >= length; }; }, }); ajv.addSchema({ $id: 'trimmedString', type: 'string', minTrimmedLength: 1, }); // Schema const schema = { type: 'object', properties: { name: { oneOf: [ { $ref: 'trimmedString' }, { type: 'null' }, ], }, }, required: [ 'name' ], }; const validate = ajv.compile(schema); const sample = { name: 1, }; validate({ name: null }); const { errors } = validate; console.log(errors);
Loading…

no comments

    sign in to comment