Skip to content

Commit

Permalink
fix: Updated changes to restrict updated version to ajv v8
Browse files Browse the repository at this point in the history
  • Loading branch information
rpl committed May 5, 2021
1 parent e424bf1 commit 479fa59
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 16 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"json-merge-patch": "^0.2.3"
},
"devDependencies": {
"ajv": "^7.2.4",
"ajv": "^8.2.0",
"coveralls": "^2.11.12",
"eslint": "^3.3.0",
"if-node-version": "^1.0.0",
Expand All @@ -46,6 +46,6 @@
"pre-commit": "^1.1.3"
},
"peerDependencies": {
"ajv": ">=7.0.0"
"ajv": ">=8.0.0"
}
}
18 changes: 4 additions & 14 deletions spec/test_validate.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,15 @@ var assert = require('assert');
module.exports = function (validate, keyword) {
assert.strictEqual(validate({ p: 'abc', q: 1 }), true);

// In ajv <= v7 the property is dataPath, while on ajv >= v8 is instancePath.
var assertDataOrInstancePath = function (err, expectedValue) {
assert.equal(
'dataPath' in err
? err.dataPath
: err.instancePath,
expectedValue
);
};

// property q should be a number
assert.strictEqual(validate({ p: 'foo', q: 'bar' }), false);
var errs = validate.errors;
assert.equal(errs.length, 2);
assert.equal(errs[0].keyword, 'type');
assert.equal(errs[0].schemaPath, '#/' + keyword + '/properties/q/type');
assertDataOrInstancePath(errs[0], '/q');
assert.equal(errs[0].instancePath, '/q');
assert.equal(errs[1].keyword, keyword);
assertDataOrInstancePath(errs[1], '');
assert.equal(errs[1].instancePath, '');
assert.equal(errs[1].schemaPath, '#/' + keyword);

// an object without q should fail
Expand All @@ -33,8 +23,8 @@ module.exports = function (validate, keyword) {
assert.equal(errs[0].keyword, 'required');
assert.equal(errs[0].schemaPath, '#/' + keyword + '/required');
assert.deepEqual(errs[0].params, { missingProperty: 'q' });
assertDataOrInstancePath(errs[0], '');
assert.equal(errs[0].instancePath, '');
assert.equal(errs[1].keyword, keyword);
assert.equal(errs[1].schemaPath, '#/' + keyword);
assertDataOrInstancePath(errs[1], '');
assert.equal(errs[1].instancePath, '');
};

0 comments on commit 479fa59

Please sign in to comment.