Skip to content

Commit d847ec3

Browse files
author
Evgeny Poberezkin
authored
Merge pull request #10 from epoberezkin/v3.0.0
version 3.0.0
2 parents 0466383 + 2f6f15c commit d847ec3

File tree

7 files changed

+22
-52
lines changed

7 files changed

+22
-52
lines changed

keywords/add_keyword.js

+2-7
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
var url = require('url');
44

55
module.exports = function (ajv, keyword, jsonPatch, patchSchema) {
6-
if (!ajv._opts.v5)
7-
throw new Error('keyword ' + keyword + ' requires v5 option');
86
ajv.addKeyword(keyword, {
97
macro: function (schema, parentSchema, it) {
108
var source = schema.source;
@@ -20,10 +18,7 @@ module.exports = function (ajv, keyword, jsonPatch, patchSchema) {
2018
: $ref;
2119
var validate = ajv.getSchema(id);
2220
if (validate) return validate.schema;
23-
var err = new Error('can\'t resolve reference ' + $ref + ' from id ' + it.baseId);
24-
err.missingRef = it.resolve.url(it.baseId, $ref);
25-
err.missingSchema = it.resolve.normalizeId(it.resolve.fullPath(err.missingRef));
26-
throw err;
21+
throw new ajv.constructor.MissingRefError(it.baseId, $ref);
2722
}
2823
},
2924
metaSchema: {
@@ -44,7 +39,7 @@ module.exports = function (ajv, keyword, jsonPatch, patchSchema) {
4439
}
4540
}
4641
},
47-
{ "$ref": "https://raw.githubusercontent.com/epoberezkin/ajv/master/lib/refs/json-schema-v5.json#" }
42+
{ "$ref": "http://json-schema.org/draft-06/schema#" }
4843
]
4944
},
5045
"with": patchSchema

package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ajv-merge-patch",
3-
"version": "2.1.0",
3+
"version": "3.0.0",
44
"description": "$merge and $patch keywords for Ajv JSON-Schema validator to extend schemas",
55
"main": "index.js",
66
"scripts": {
@@ -37,7 +37,7 @@
3737
"json-merge-patch": "^0.2.3"
3838
},
3939
"devDependencies": {
40-
"ajv": "^4.6.0",
40+
"ajv": "^5.0.0",
4141
"coveralls": "^2.11.12",
4242
"eslint": "^3.3.0",
4343
"if-node-version": "^1.0.0",
@@ -46,6 +46,6 @@
4646
"pre-commit": "^1.1.3"
4747
},
4848
"peerDependencies": {
49-
"ajv": ">=4.6.0"
49+
"ajv": ">=5.0.0"
5050
}
5151
}

spec/.eslintrc.yml

+1
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ globals:
44
describe: false
55
it: false
66
beforeEach: false
7+
Promise: false

spec/async.spec.js

+13-13
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ describe('async schema loading', function() {
99
var ajv, loadCount;
1010

1111
beforeEach(function() {
12-
ajv = new Ajv({v5: true, loadSchema: loadSchema});
12+
ajv = new Ajv({loadSchema: loadSchema});
1313
addKeywords(ajv);
1414
loadCount = 0;
1515
});
1616

1717
describe('$merge', function() {
18-
it('should load missing schemas', function (done) {
18+
it('should load missing schemas', function() {
1919
var schema = {
2020
"$merge": {
2121
"source": { "$ref": "obj.json#" },
@@ -25,12 +25,12 @@ describe('async schema loading', function() {
2525
}
2626
};
2727

28-
testAsync(schema, '$merge', done);
28+
return testAsync(schema, '$merge');
2929
});
3030
});
3131

3232
describe('$patch', function() {
33-
it('should load missing schemas', function (done) {
33+
it('should load missing schemas', function() {
3434
var schema = {
3535
"$patch": {
3636
"source": { "$ref": "obj.json#" },
@@ -40,29 +40,29 @@ describe('async schema loading', function() {
4040
}
4141
};
4242

43-
testAsync(schema, '$patch', done);
43+
return testAsync(schema, '$patch');
4444
});
4545
});
4646

47-
function testAsync(schema, keyword, done) {
48-
ajv.compileAsync(schema, function (err, validate) {
49-
if (err) done(err);
47+
function testAsync(schema, keyword) {
48+
return ajv.compileAsync(schema)
49+
.then(function (validate) {
5050
assert.strictEqual(loadCount, 1);
5151
test(validate, keyword);
52-
done();
5352
});
5453
}
5554

56-
function loadSchema(ref, callback) {
55+
function loadSchema(ref) {
5756
if (ref == 'obj.json') {
5857
loadCount++;
59-
return callback(null, {
58+
var schema = {
6059
"id": "obj.json#",
6160
"type": "object",
6261
"properties": { "p": { "type": "string" } },
6362
"additionalProperties": false
64-
});
63+
};
64+
return Promise.resolve(schema);
6565
}
66-
callback(new Error('404: ' + ref));
66+
return Promise.reject(new Error('404: ' + ref));
6767
}
6868
});

spec/errors.spec.js

+1-27
Original file line numberDiff line numberDiff line change
@@ -2,40 +2,14 @@
22

33
var Ajv = require('ajv');
44
var addKeywords = require('..');
5-
var addMerge = require('../keywords/merge');
6-
var addPatch = require('../keywords/patch');
75
var assert = require('assert');
86

97
describe('errors', function() {
108
var ajv;
119

12-
describe('no v5 option', function() {
13-
beforeEach(function() {
14-
ajv = new Ajv;
15-
});
16-
17-
it('adding $merge and $patch should throw without v5 option', function() {
18-
assert.throws(function() {
19-
addKeywords(ajv);
20-
});
21-
});
22-
23-
it('adding $merge only should throw without v5 option', function() {
24-
assert.throws(function() {
25-
addMerge(ajv);
26-
});
27-
});
28-
29-
it('adding $patch only should throw without v5 option', function() {
30-
assert.throws(function() {
31-
addPatch(ajv);
32-
});
33-
});
34-
});
35-
3610
describe('missing $ref', function() {
3711
beforeEach(function() {
38-
ajv = new Ajv({ v5: true });
12+
ajv = new Ajv;
3913
addKeywords(ajv);
4014
});
4115

spec/merge.spec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ describe('keyword $merge', function() {
99
var ajvInstances;
1010

1111
beforeEach(function() {
12-
ajvInstances = [ new Ajv({v5: true}), new Ajv({v5: true}) ];
12+
ajvInstances = [ new Ajv, new Ajv ];
1313
addKeywords(ajvInstances[0]);
1414
addMerge(ajvInstances[1]);
1515
});

spec/patch.spec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ describe('keyword $patch', function() {
99
var ajvInstances;
1010

1111
beforeEach(function() {
12-
ajvInstances = [ new Ajv({v5: true}), new Ajv({v5: true}) ];
12+
ajvInstances = [ new Ajv, new Ajv ];
1313
addKeywords(ajvInstances[0]);
1414
addPatch(ajvInstances[1]);
1515
});

0 commit comments

Comments
 (0)