Skip to content

Commit 870b9f7

Browse files
authored
Merge pull request #207 from json-schema-org/draft-7-ajv
feat: test draft-7 with Ajv
2 parents 9ce7b4c + 3d9830a commit 870b9f7

File tree

4 files changed

+30
-22
lines changed

4 files changed

+30
-22
lines changed

index.js

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,43 @@
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+
7: ['optional/content', 'optional/format']
17+
};
1618

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

2836
jsonSchemaTest(ajv, {
29-
description: 'Test suite draft-0' + draft,
30-
suites: {tests: './tests/draft' + draft + '/{**/,}*.json'},
31-
skip: draft == 4 ? ['optional/zeroTerminatedFloats'] : [],
37+
description: `Test suite draft-0${draft}`,
38+
suites: {tests: `./tests/draft${draft}/{**/,}*.json`},
39+
skip: SKIP[draft],
3240
cwd: __dirname,
3341
hideFolder: 'tests/'
3442
});
35-
}
43+
});

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)