Skip to content

Commit 743eff9

Browse files
committed
bundle default json-schemas together with z-schema, fixes #99
1 parent 5fd275a commit 743eff9

File tree

7 files changed

+335
-3
lines changed

7 files changed

+335
-3
lines changed

Diff for: .gitmodules

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
[submodule "test/jsonSchemaTestSuite"]
22
path = test/jsonSchemaTestSuite
33
url = https://github.com/json-schema/JSON-Schema-Test-Suite.git
4+
[submodule "json-schema"]
5+
path = json-schema
6+
url = https://github.com/json-schema/json-schema.git

Diff for: Gruntfile.js

+17-1
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,27 @@
11
/*global require,module*/
22

33
var remapify = require("remapify");
4+
var path = require("path");
45

56
module.exports = function (grunt) {
67

78
// Project configuration.
89
grunt.initConfig({
910
pkg: grunt.file.readJSON("package.json"),
11+
copy: {
12+
dist: {
13+
files: [{
14+
expand: true,
15+
dot: true,
16+
cwd: ".",
17+
dest: "src/schemas/",
18+
src: ["./json-schema/draft-04/*"],
19+
rename: function(dest, src) {
20+
return dest + path.basename(src) + ".json";
21+
}
22+
}]
23+
}
24+
},
1025
lineending: {
1126
dist: {
1227
options: {
@@ -87,6 +102,7 @@ module.exports = function (grunt) {
87102
// Load the plugin that provides the "uglify" task.
88103
grunt.loadNpmTasks("grunt-lineending");
89104
grunt.loadNpmTasks("grunt-contrib-jshint");
105+
grunt.loadNpmTasks("grunt-contrib-copy");
90106
grunt.loadNpmTasks("grunt-jscs");
91107
grunt.loadNpmTasks("grunt-jasmine-node");
92108
grunt.loadNpmTasks("grunt-jasmine-node-coverage");
@@ -95,7 +111,7 @@ module.exports = function (grunt) {
95111
grunt.loadNpmTasks("grunt-contrib-uglify");
96112

97113
// Default task(s).
98-
grunt.registerTask("default", ["lineending", "jshint", "jscs", "jasmine_node", "browserify", "jasmine", "uglify"]);
114+
grunt.registerTask("default", ["copy", "lineending", "jshint", "jscs", "jasmine_node", "browserify", "jasmine", "uglify"]);
99115
grunt.registerTask("test", ["jasmine_node"]);
100116

101117
};

Diff for: json-schema

Submodule json-schema added at cc8ec81

Diff for: src/ZSchema.js

+5
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ var SchemaCache = require("./SchemaCache");
88
var SchemaCompilation = require("./SchemaCompilation");
99
var SchemaValidation = require("./SchemaValidation");
1010
var Utils = require("./Utils");
11+
var Draft4Schema = require("./schemas/schema.json");
12+
var Draft4HyperSchema = require("./schemas/hyper-schema.json");
1113

1214
/*
1315
default options
@@ -58,6 +60,9 @@ function ZSchema(options) {
5860
this.cache = {};
5961
this.referenceCache = [];
6062

63+
this.setRemoteReference("http://json-schema.org/draft-04/schema", Draft4Schema);
64+
this.setRemoteReference("http://json-schema.org/draft-04/hyper-schema", Draft4HyperSchema);
65+
6166
// options
6267
if (typeof options === "object") {
6368
var keys = Object.keys(options),

Diff for: src/schemas/hyper-schema.json

+158
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
{
2+
"$schema": "http://json-schema.org/draft-04/hyper-schema#",
3+
"id": "http://json-schema.org/draft-04/hyper-schema#",
4+
"title": "JSON Hyper-Schema",
5+
"allOf": [
6+
{
7+
"$ref": "http://json-schema.org/draft-04/schema#"
8+
}
9+
],
10+
"properties": {
11+
"additionalItems": {
12+
"anyOf": [
13+
{
14+
"type": "boolean"
15+
},
16+
{
17+
"$ref": "#"
18+
}
19+
]
20+
},
21+
"additionalProperties": {
22+
"anyOf": [
23+
{
24+
"type": "boolean"
25+
},
26+
{
27+
"$ref": "#"
28+
}
29+
]
30+
},
31+
"dependencies": {
32+
"additionalProperties": {
33+
"anyOf": [
34+
{
35+
"$ref": "#"
36+
},
37+
{
38+
"type": "array"
39+
}
40+
]
41+
}
42+
},
43+
"items": {
44+
"anyOf": [
45+
{
46+
"$ref": "#"
47+
},
48+
{
49+
"$ref": "#/definitions/schemaArray"
50+
}
51+
]
52+
},
53+
"definitions": {
54+
"additionalProperties": {
55+
"$ref": "#"
56+
}
57+
},
58+
"patternProperties": {
59+
"additionalProperties": {
60+
"$ref": "#"
61+
}
62+
},
63+
"properties": {
64+
"additionalProperties": {
65+
"$ref": "#"
66+
}
67+
},
68+
"allOf": {
69+
"$ref": "#/definitions/schemaArray"
70+
},
71+
"anyOf": {
72+
"$ref": "#/definitions/schemaArray"
73+
},
74+
"oneOf": {
75+
"$ref": "#/definitions/schemaArray"
76+
},
77+
"not": {
78+
"$ref": "#"
79+
},
80+
81+
"links": {
82+
"type": "array",
83+
"items": {
84+
"$ref": "#/definitions/linkDescription"
85+
}
86+
},
87+
"fragmentResolution": {
88+
"type": "string"
89+
},
90+
"media": {
91+
"type": "object",
92+
"properties": {
93+
"type": {
94+
"description": "A media type, as described in RFC 2046",
95+
"type": "string"
96+
},
97+
"binaryEncoding": {
98+
"description": "A content encoding scheme, as described in RFC 2045",
99+
"type": "string"
100+
}
101+
}
102+
},
103+
"pathStart": {
104+
"description": "Instances' URIs must start with this value for this schema to apply to them",
105+
"type": "string",
106+
"format": "uri"
107+
}
108+
},
109+
"definitions": {
110+
"schemaArray": {
111+
"type": "array",
112+
"items": {
113+
"$ref": "#"
114+
}
115+
},
116+
"linkDescription": {
117+
"title": "Link Description Object",
118+
"type": "object",
119+
"required": [ "href", "rel" ],
120+
"properties": {
121+
"href": {
122+
"description": "a URI template, as defined by RFC 6570, with the addition of the $, ( and ) characters for pre-processing",
123+
"type": "string"
124+
},
125+
"rel": {
126+
"description": "relation to the target resource of the link",
127+
"type": "string"
128+
},
129+
"title": {
130+
"description": "a title for the link",
131+
"type": "string"
132+
},
133+
"targetSchema": {
134+
"description": "JSON Schema describing the link target",
135+
"$ref": "#"
136+
},
137+
"mediaType": {
138+
"description": "media type (as defined by RFC 2046) describing the link target",
139+
"type": "string"
140+
},
141+
"method": {
142+
"description": "method for requesting the target of the link (e.g. for HTTP this might be \"GET\" or \"DELETE\")",
143+
"type": "string"
144+
},
145+
"encType": {
146+
"description": "The media type in which to submit data along with the request",
147+
"type": "string",
148+
"default": "application/json"
149+
},
150+
"schema": {
151+
"description": "Schema describing the data to submit along with the request",
152+
"$ref": "#"
153+
}
154+
}
155+
}
156+
}
157+
}
158+

Diff for: src/schemas/schema.json

+150
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
{
2+
"id": "http://json-schema.org/draft-04/schema#",
3+
"$schema": "http://json-schema.org/draft-04/schema#",
4+
"description": "Core schema meta-schema",
5+
"definitions": {
6+
"schemaArray": {
7+
"type": "array",
8+
"minItems": 1,
9+
"items": { "$ref": "#" }
10+
},
11+
"positiveInteger": {
12+
"type": "integer",
13+
"minimum": 0
14+
},
15+
"positiveIntegerDefault0": {
16+
"allOf": [ { "$ref": "#/definitions/positiveInteger" }, { "default": 0 } ]
17+
},
18+
"simpleTypes": {
19+
"enum": [ "array", "boolean", "integer", "null", "number", "object", "string" ]
20+
},
21+
"stringArray": {
22+
"type": "array",
23+
"items": { "type": "string" },
24+
"minItems": 1,
25+
"uniqueItems": true
26+
}
27+
},
28+
"type": "object",
29+
"properties": {
30+
"id": {
31+
"type": "string",
32+
"format": "uri"
33+
},
34+
"$schema": {
35+
"type": "string",
36+
"format": "uri"
37+
},
38+
"title": {
39+
"type": "string"
40+
},
41+
"description": {
42+
"type": "string"
43+
},
44+
"default": {},
45+
"multipleOf": {
46+
"type": "number",
47+
"minimum": 0,
48+
"exclusiveMinimum": true
49+
},
50+
"maximum": {
51+
"type": "number"
52+
},
53+
"exclusiveMaximum": {
54+
"type": "boolean",
55+
"default": false
56+
},
57+
"minimum": {
58+
"type": "number"
59+
},
60+
"exclusiveMinimum": {
61+
"type": "boolean",
62+
"default": false
63+
},
64+
"maxLength": { "$ref": "#/definitions/positiveInteger" },
65+
"minLength": { "$ref": "#/definitions/positiveIntegerDefault0" },
66+
"pattern": {
67+
"type": "string",
68+
"format": "regex"
69+
},
70+
"additionalItems": {
71+
"anyOf": [
72+
{ "type": "boolean" },
73+
{ "$ref": "#" }
74+
],
75+
"default": {}
76+
},
77+
"items": {
78+
"anyOf": [
79+
{ "$ref": "#" },
80+
{ "$ref": "#/definitions/schemaArray" }
81+
],
82+
"default": {}
83+
},
84+
"maxItems": { "$ref": "#/definitions/positiveInteger" },
85+
"minItems": { "$ref": "#/definitions/positiveIntegerDefault0" },
86+
"uniqueItems": {
87+
"type": "boolean",
88+
"default": false
89+
},
90+
"maxProperties": { "$ref": "#/definitions/positiveInteger" },
91+
"minProperties": { "$ref": "#/definitions/positiveIntegerDefault0" },
92+
"required": { "$ref": "#/definitions/stringArray" },
93+
"additionalProperties": {
94+
"anyOf": [
95+
{ "type": "boolean" },
96+
{ "$ref": "#" }
97+
],
98+
"default": {}
99+
},
100+
"definitions": {
101+
"type": "object",
102+
"additionalProperties": { "$ref": "#" },
103+
"default": {}
104+
},
105+
"properties": {
106+
"type": "object",
107+
"additionalProperties": { "$ref": "#" },
108+
"default": {}
109+
},
110+
"patternProperties": {
111+
"type": "object",
112+
"additionalProperties": { "$ref": "#" },
113+
"default": {}
114+
},
115+
"dependencies": {
116+
"type": "object",
117+
"additionalProperties": {
118+
"anyOf": [
119+
{ "$ref": "#" },
120+
{ "$ref": "#/definitions/stringArray" }
121+
]
122+
}
123+
},
124+
"enum": {
125+
"type": "array",
126+
"minItems": 1,
127+
"uniqueItems": true
128+
},
129+
"type": {
130+
"anyOf": [
131+
{ "$ref": "#/definitions/simpleTypes" },
132+
{
133+
"type": "array",
134+
"items": { "$ref": "#/definitions/simpleTypes" },
135+
"minItems": 1,
136+
"uniqueItems": true
137+
}
138+
]
139+
},
140+
"allOf": { "$ref": "#/definitions/schemaArray" },
141+
"anyOf": { "$ref": "#/definitions/schemaArray" },
142+
"oneOf": { "$ref": "#/definitions/schemaArray" },
143+
"not": { "$ref": "#" }
144+
},
145+
"dependencies": {
146+
"exclusiveMaximum": [ "maximum" ],
147+
"exclusiveMinimum": [ "minimum" ]
148+
},
149+
"default": {}
150+
}

Diff for: test/spec/ZSchemaTestSuiteSpec.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,7 @@ describe("ZSchemaTestSuite", function () {
9090
!async && it(testSuite.description + ", " + test.description, function () {
9191

9292
var validator = new ZSchema(options);
93-
validator.setRemoteReference("http://json-schema.org/draft-04/schema", require("../files/draft-04-schema.json"));
94-
validator.setRemoteReference("http://json-schema.org/draft-04/hyper-schema", require("../files/draft-04-hyper-schema.json"));
93+
9594
if (setup) { setup(validator, ZSchema); }
9695

9796
var valid = validator.validateSchema(schema);

0 commit comments

Comments
 (0)