Skip to content

Commit 6f29c6b

Browse files
committed
Squashed 'json/' changes from 9567c58..86f965e
86f965e Merge pull request #209 from json-schema-org/refactor-format f056cb7 fix: incorrect relative-json-pointer test, closes #208 814eb16 refactor: split format.json to multiple files, closes #162 870b9f7 Merge pull request #207 from json-schema-org/draft-7-ajv 3d9830a feat: test draft-7 with Ajv 9ce7b4c Merge pull request #200 from handrews/draft-07 cf6e663 Apparently descriptions must be < 60 chars 1042cd6 Update draft coverage information 0680b46 Restore regex format test from draft-03 f58637d Basic relative json pointer tests for format 1b43ffa Partial IRI and IRI-reference test suite 9b020b8 Add idn-email and idn-hostname format tests ca342c9 Add tests for "date" and "time" formats 0d64501 Tests for contentMediaType and contentEncoding ea357f3 Update draft coverage information 321db9a Tests for if, then, and else keywords dedd3f1 Unmodified copy of draft6 tests to draft7 git-subtree-dir: json git-subtree-split: 86f965e53dda0b6c57e70ddd726243e1e061cf84
1 parent be19a54 commit 6f29c6b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+4299
-25
lines changed

README.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ If you're going to use this suite, you need to know how tests are laid out. The
1616
tests are contained in the `tests` directory at the root of this repository.
1717

1818
Inside that directory is a subdirectory for each draft or version of the
19-
schema. We'll use `draft3` as an example.
19+
schema.
2020

2121
If you look inside the draft directory, there are a number of `.json` files,
2222
which logically group a set of test cases together. Often the grouping is by
@@ -52,8 +52,13 @@ they should be valid or invalid.
5252
Coverage
5353
--------
5454

55-
Draft 3 and 4 should have full coverage. If you see anything missing or think
56-
there is a useful test missing, please send a pull request or open an issue.
55+
Drafts 03, 04, 06, and 07 should have full coverage, with drafts 06 and 07
56+
being considered current and actively supported. Bug fixes will be made as
57+
needed for draft-04 as it is still the most widely used, while draft-03
58+
is long since deprecated.
59+
60+
If you see anything missing from the current supported drafts, or incorrect
61+
on any draft still accepting bug fixes, please file an issue or submit a PR.
5762

5863
Who Uses the Test Suite
5964
-----------------------

index.js

Lines changed: 28 additions & 20 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: [
17+
'format/idn-email',
18+
'format/idn-hostname',
19+
'format/iri',
20+
'format/iri-reference',
21+
'optional/content'
22+
]
23+
};
1624

17-
function runTest(draft) {
18-
var opts = {
19-
format: 'full',
20-
formats: {'json-pointer': /^(?:\/(?:[^~\/]|~0|~1)*)*$/}
21-
};
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+
[4, 6, 7].forEach((draft) => {
26+
let ajv;
27+
if (draft == 7) {
28+
ajv = new Ajv({format: 'full'});
29+
} else {
30+
ajv = new Ajv({format: 'full', meta: false});
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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
},
2222
"homepage": "https://github.com/json-schema-org/JSON-Schema-Test-Suite#readme",
2323
"devDependencies": {
24-
"ajv": "^5.0.4-beta.1",
25-
"json-schema-test": "^1.3.0",
24+
"ajv": "^6.0.0-rc.0",
25+
"json-schema-test": "^2.0.0",
2626
"mocha": "^3.2.0"
2727
}
2828
}

tests/draft7/additionalItems.json

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
[
2+
{
3+
"description": "additionalItems as schema",
4+
"schema": {
5+
"items": [{}],
6+
"additionalItems": {"type": "integer"}
7+
},
8+
"tests": [
9+
{
10+
"description": "additional items match schema",
11+
"data": [ null, 2, 3, 4 ],
12+
"valid": true
13+
},
14+
{
15+
"description": "additional items do not match schema",
16+
"data": [ null, 2, 3, "foo" ],
17+
"valid": false
18+
}
19+
]
20+
},
21+
{
22+
"description": "items is schema, no additionalItems",
23+
"schema": {
24+
"items": {},
25+
"additionalItems": false
26+
},
27+
"tests": [
28+
{
29+
"description": "all items match schema",
30+
"data": [ 1, 2, 3, 4, 5 ],
31+
"valid": true
32+
}
33+
]
34+
},
35+
{
36+
"description": "array of items with no additionalItems",
37+
"schema": {
38+
"items": [{}, {}, {}],
39+
"additionalItems": false
40+
},
41+
"tests": [
42+
{
43+
"description": "fewer number of items present",
44+
"data": [ 1, 2 ],
45+
"valid": true
46+
},
47+
{
48+
"description": "equal number of items present",
49+
"data": [ 1, 2, 3 ],
50+
"valid": true
51+
},
52+
{
53+
"description": "additional items are not permitted",
54+
"data": [ 1, 2, 3, 4 ],
55+
"valid": false
56+
}
57+
]
58+
},
59+
{
60+
"description": "additionalItems as false without items",
61+
"schema": {"additionalItems": false},
62+
"tests": [
63+
{
64+
"description":
65+
"items defaults to empty schema so everything is valid",
66+
"data": [ 1, 2, 3, 4, 5 ],
67+
"valid": true
68+
},
69+
{
70+
"description": "ignores non-arrays",
71+
"data": {"foo" : "bar"},
72+
"valid": true
73+
}
74+
]
75+
},
76+
{
77+
"description": "additionalItems are allowed by default",
78+
"schema": {"items": [{"type": "integer"}]},
79+
"tests": [
80+
{
81+
"description": "only the first item is validated",
82+
"data": [1, "foo", false],
83+
"valid": true
84+
}
85+
]
86+
}
87+
]
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
[
2+
{
3+
"description":
4+
"additionalProperties being false does not allow other properties",
5+
"schema": {
6+
"properties": {"foo": {}, "bar": {}},
7+
"patternProperties": { "^v": {} },
8+
"additionalProperties": false
9+
},
10+
"tests": [
11+
{
12+
"description": "no additional properties is valid",
13+
"data": {"foo": 1},
14+
"valid": true
15+
},
16+
{
17+
"description": "an additional property is invalid",
18+
"data": {"foo" : 1, "bar" : 2, "quux" : "boom"},
19+
"valid": false
20+
},
21+
{
22+
"description": "ignores arrays",
23+
"data": [1, 2, 3],
24+
"valid": true
25+
},
26+
{
27+
"description": "ignores strings",
28+
"data": "foobarbaz",
29+
"valid": true
30+
},
31+
{
32+
"description": "ignores other non-objects",
33+
"data": 12,
34+
"valid": true
35+
},
36+
{
37+
"description": "patternProperties are not additional properties",
38+
"data": {"foo":1, "vroom": 2},
39+
"valid": true
40+
}
41+
]
42+
},
43+
{
44+
"description":
45+
"additionalProperties allows a schema which should validate",
46+
"schema": {
47+
"properties": {"foo": {}, "bar": {}},
48+
"additionalProperties": {"type": "boolean"}
49+
},
50+
"tests": [
51+
{
52+
"description": "no additional properties is valid",
53+
"data": {"foo": 1},
54+
"valid": true
55+
},
56+
{
57+
"description": "an additional valid property is valid",
58+
"data": {"foo" : 1, "bar" : 2, "quux" : true},
59+
"valid": true
60+
},
61+
{
62+
"description": "an additional invalid property is invalid",
63+
"data": {"foo" : 1, "bar" : 2, "quux" : 12},
64+
"valid": false
65+
}
66+
]
67+
},
68+
{
69+
"description":
70+
"additionalProperties can exist by itself",
71+
"schema": {
72+
"additionalProperties": {"type": "boolean"}
73+
},
74+
"tests": [
75+
{
76+
"description": "an additional valid property is valid",
77+
"data": {"foo" : true},
78+
"valid": true
79+
},
80+
{
81+
"description": "an additional invalid property is invalid",
82+
"data": {"foo" : 1},
83+
"valid": false
84+
}
85+
]
86+
},
87+
{
88+
"description": "additionalProperties are allowed by default",
89+
"schema": {"properties": {"foo": {}, "bar": {}}},
90+
"tests": [
91+
{
92+
"description": "additional properties are allowed",
93+
"data": {"foo": 1, "bar": 2, "quux": true},
94+
"valid": true
95+
}
96+
]
97+
}
98+
]

0 commit comments

Comments
 (0)