Skip to content
This repository was archived by the owner on Nov 2, 2023. It is now read-only.

Commit 6506024

Browse files
committed
Merge git://github.com/laurie71/json-schema
Conflicts: package.json
2 parents bc21a1d + 0a52e1e commit 6506024

File tree

3 files changed

+112
-14
lines changed

3 files changed

+112
-14
lines changed

draft-03/hyper-schema

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,60 @@
11
{
22
"$schema" : "http://json-schema.org/draft-03/hyper-schema#",
3-
"extends" : {"$ref" : "http://json-schema.org/draft-03/schema#"}
3+
"extends" : {"$ref" : "http://json-schema.org/draft-03/schema#"},
44
"id" : "http://json-schema.org/draft-03/hyper-schema#",
55

66
"properties" : {
77
"links" : {
88
"type" : "array",
99
"items" : {"$ref" : "http://json-schema.org/draft-03/links#"}
1010
},
11-
11+
1212
"fragmentResolution" : {
1313
"type" : "string",
1414
"default" : "slash-delimited"
1515
},
16-
16+
1717
"root" : {
1818
"type" : "boolean",
1919
"default" : false
2020
},
21-
21+
2222
"readonly" : {
2323
"type" : "boolean",
2424
"default" : false
2525
},
26-
26+
2727
"contentEncoding" : {
2828
"type" : "string"
2929
},
30-
30+
3131
"pathStart" : {
3232
"type" : "string",
3333
"format" : "uri"
3434
},
35-
35+
3636
"mediaType" : {
3737
"type" : "string",
3838
"format" : "media-type"
3939
}
4040
},
41-
41+
4242
"links" : [
4343
{
4444
"href" : "{id}",
4545
"rel" : "self"
4646
},
47-
47+
4848
{
4949
"href" : "{$ref}",
5050
"rel" : "full"
5151
},
52-
52+
5353
{
5454
"href" : "{$schema}",
5555
"rel" : "describedby"
5656
}
5757
],
58-
58+
5959
"fragmentResolution" : "slash-delimited"
60-
}
60+
}

package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,8 @@
2323
"url":"http://github.com/kriszyp/json-schema"
2424
},
2525
"directories": { "lib": "./lib" },
26-
"main": "./lib/validate.js"
27-
}
26+
"main": "./lib/validate.js",
27+
"devDependencies": { "vows": "*" },
28+
"scripts": { "test": "echo TESTS DISABLED vows --spec test/*.js" }
29+
}
30+

test/tests.js

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
var assert = require('assert');
2+
var vows = require('vows');
3+
var path = require('path');
4+
var fs = require('fs');
5+
6+
var validate = require('../lib/validate').validate;
7+
8+
9+
var revision = 'draft-03';
10+
var schemaRoot = path.join(__dirname, '..', revision);
11+
var schemaNames = ['schema', 'hyper-schema', 'links', 'json-ref' ];
12+
var schemas = {};
13+
14+
schemaNames.forEach(function(name) {
15+
var file = path.join(schemaRoot, name);
16+
schemas[name] = loadSchema(file);
17+
});
18+
19+
schemaNames.forEach(function(name) {
20+
var s, n = name+'-nsd', f = path.join(schemaRoot, name);
21+
schemas[n] = loadSchema(f);
22+
s = schemas[n];
23+
delete s['$schema'];
24+
});
25+
26+
function loadSchema(path) {
27+
var data = fs.readFileSync(path, 'utf-8');
28+
var schema = JSON.parse(data);
29+
return schema;
30+
}
31+
32+
function resultIsValid() {
33+
return function(result) {
34+
assert.isObject(result);
35+
//assert.isBoolean(result.valid);
36+
assert.equal(typeof(result.valid), 'boolean');
37+
assert.isArray(result.errors);
38+
for (var i = 0; i < result.errors.length; i++) {
39+
assert.notEqual(result.errors[i], null, 'errors['+i+'] is null');
40+
}
41+
}
42+
}
43+
44+
function assertValidates(doc, schema) {
45+
var context = {};
46+
47+
context[': validate('+doc+', '+schema+')'] = {
48+
topic: validate(schemas[doc], schemas[schema]),
49+
'returns valid result': resultIsValid(),
50+
'with valid=true': function(result) { assert.equal(result.valid, true); },
51+
'and no errors': function(result) {
52+
// XXX work-around for bug in vows: [null] chokes it
53+
if (result.errors[0] == null) assert.fail('(errors contains null)');
54+
assert.length(result.errors, 0);
55+
}
56+
};
57+
58+
return context;
59+
}
60+
61+
function assertSelfValidates(doc) {
62+
var context = {};
63+
64+
context[': validate('+doc+')'] = {
65+
topic: validate(schemas[doc]),
66+
'returns valid result': resultIsValid(),
67+
'with valid=true': function(result) { assert.equal(result.valid, true); },
68+
'and no errors': function(result) { assert.length(result.errors, 0); }
69+
};
70+
71+
return context;
72+
}
73+
74+
var suite = vows.describe('JSON Schema').addBatch({
75+
'Core-NSD self-validates': assertSelfValidates('schema-nsd'),
76+
'Core-NSD/Core-NSD': assertValidates('schema-nsd', 'schema-nsd'),
77+
'Core-NSD/Core': assertValidates('schema-nsd', 'schema'),
78+
79+
'Core self-validates': assertSelfValidates('schema'),
80+
'Core/Core': assertValidates('schema', 'schema'),
81+
82+
'Hyper-NSD self-validates': assertSelfValidates('hyper-schema-nsd'),
83+
'Hyper self-validates': assertSelfValidates('hyper-schema'),
84+
'Hyper/Hyper': assertValidates('hyper-schema', 'hyper-schema'),
85+
'Hyper/Core': assertValidates('hyper-schema', 'schema'),
86+
87+
'Links-NSD self-validates': assertSelfValidates('links-nsd'),
88+
'Links self-validates': assertSelfValidates('links'),
89+
'Links/Hyper': assertValidates('links', 'hyper-schema'),
90+
'Links/Core': assertValidates('links', 'schema'),
91+
92+
'Json-Ref self-validates': assertSelfValidates('json-ref'),
93+
'Json-Ref/Hyper': assertValidates('json-ref', 'hyper-schema'),
94+
'Json-Ref/Core': assertValidates('json-ref', 'schema')
95+
}).export(module);

0 commit comments

Comments
 (0)