Skip to content

Commit a35be56

Browse files
committed
feat: test draft-7 with Ajv
1 parent 9ce7b4c commit a35be56

File tree

4 files changed

+31
-22
lines changed

4 files changed

+31
-22
lines changed

index.js

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,44 @@
11
'use strict';
22

3-
var Ajv = require('ajv');
4-
var jsonSchemaTest = require('json-schema-test');
5-
var assert = require('assert');
3+
const Ajv = require('ajv');
4+
const jsonSchemaTest = require('json-schema-test');
5+
const assert = require('assert');
66

7-
var refs = {
7+
const refs = {
88
'http://localhost:1234/integer.json': require('./remotes/integer.json'),
99
'http://localhost:1234/subSchemas.json': require('./remotes/subSchemas.json'),
1010
'http://localhost:1234/folder/folderInteger.json': require('./remotes/folder/folderInteger.json'),
1111
'http://localhost:1234/name.json': require('./remotes/name.json')
1212
};
1313

14-
runTest(4);
15-
runTest(6);
14+
const SKIP = {
15+
4: ['optional/zeroTerminatedFloats'],
16+
6: [],
17+
7: ['optional/content', 'optional/format']
18+
};
1619

17-
function runTest(draft) {
18-
var opts = {
20+
[4, 6, 7].forEach((draft) => {
21+
let opts = {
1922
format: 'full',
20-
formats: {'json-pointer': /^(?:\/(?:[^~\/]|~0|~1)*)*$/}
23+
unknownFormats: ['iri', 'iri-reference', 'idn-hostname', 'idn-email']
2124
};
22-
if (draft == 4) opts.meta = false;
23-
var ajv = new Ajv(opts);
24-
ajv.addMetaSchema(require('ajv/lib/refs/json-schema-draft-04.json'));
25-
if (draft == 4) ajv._opts.defaultMeta = 'http://json-schema.org/draft-04/schema#';
26-
for (var uri in refs) ajv.addSchema(refs[uri], uri);
25+
26+
let ajv;
27+
if (draft == 7) {
28+
ajv = new Ajv(opts);
29+
} else {
30+
opts.meta = false;
31+
ajv = new Ajv(opts);
32+
ajv.addMetaSchema(require(`ajv/lib/refs/json-schema-draft-0${draft}.json`));
33+
ajv._opts.defaultMeta = `http://json-schema.org/draft-0${draft}/schema#`;
34+
}
35+
for (const uri in refs) ajv.addSchema(refs[uri], uri);
2736

2837
jsonSchemaTest(ajv, {
29-
description: 'Test suite draft-0' + draft,
30-
suites: {tests: './tests/draft' + draft + '/{**/,}*.json'},
31-
skip: draft == 4 ? ['optional/zeroTerminatedFloats'] : [],
38+
description: `Test suite draft-0${draft}`,
39+
suites: {tests: `./tests/draft${draft}/{**/,}*.json`},
40+
skip: SKIP[draft],
3241
cwd: __dirname,
3342
hideFolder: 'tests/'
3443
});
35-
}
44+
});

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
},
2222
"homepage": "https://github.com/json-schema-org/JSON-Schema-Test-Suite#readme",
2323
"devDependencies": {
24-
"ajv": "^5.0.4-beta.1",
24+
"ajv": "^6.0.0-rc.0",
2525
"json-schema-test": "^1.3.0",
2626
"mocha": "^3.2.0"
2727
}

tests/draft7/definitions.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[
22
{
33
"description": "valid definition",
4-
"schema": {"$ref": "http://json-schema.org/draft-06/schema#"},
4+
"schema": {"$ref": "http://json-schema.org/draft-07/schema#"},
55
"tests": [
66
{
77
"description": "valid definition schema",
@@ -16,7 +16,7 @@
1616
},
1717
{
1818
"description": "invalid definition",
19-
"schema": {"$ref": "http://json-schema.org/draft-06/schema#"},
19+
"schema": {"$ref": "http://json-schema.org/draft-07/schema#"},
2020
"tests": [
2121
{
2222
"description": "invalid definition schema",

tests/draft7/ref.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@
175175
},
176176
{
177177
"description": "remote ref, containing refs itself",
178-
"schema": {"$ref": "http://json-schema.org/draft-06/schema#"},
178+
"schema": {"$ref": "http://json-schema.org/draft-07/schema#"},
179179
"tests": [
180180
{
181181
"description": "remote ref valid",

0 commit comments

Comments
 (0)