z-schema 3.18.1 → 3.19.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +55 -54
- package/dist/ZSchema-browser-min.js +1 -3
- package/dist/ZSchema-browser-min.js.map +1 -1
- package/dist/ZSchema-browser-test.js +5746 -4016
- package/dist/ZSchema-browser.js +1853 -985
- package/package.json +19 -19
- package/src/SchemaCache.js +9 -1
- package/src/ZSchema.js +36 -21
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "z-schema",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.19.0",
|
|
4
4
|
"description": "JSON schema validator",
|
|
5
5
|
"homepage": "https://github.com/zaggino/z-schema",
|
|
6
6
|
"authors": [
|
|
@@ -58,28 +58,28 @@
|
|
|
58
58
|
]
|
|
59
59
|
},
|
|
60
60
|
"dependencies": {
|
|
61
|
-
"lodash.get": "^4.
|
|
62
|
-
"lodash.isequal": "^4.
|
|
63
|
-
"validator": "^
|
|
61
|
+
"lodash.get": "^4.0.0",
|
|
62
|
+
"lodash.isequal": "^4.0.0",
|
|
63
|
+
"validator": "^9.0.0"
|
|
64
64
|
},
|
|
65
65
|
"optionalDependencies": {
|
|
66
66
|
"commander": "^2.7.1"
|
|
67
67
|
},
|
|
68
68
|
"devDependencies": {
|
|
69
|
-
"coveralls": "
|
|
70
|
-
"grunt": "^0.
|
|
71
|
-
"grunt-
|
|
72
|
-
"grunt-
|
|
73
|
-
"grunt-contrib-copy": "
|
|
74
|
-
"grunt-contrib-jasmine": "
|
|
75
|
-
"grunt-contrib-jshint": "
|
|
76
|
-
"grunt-contrib-uglify": "
|
|
77
|
-
"grunt-jasmine-node": "
|
|
78
|
-
"grunt-jasmine-node-coverage": "^0.
|
|
79
|
-
"grunt-jscs": "
|
|
80
|
-
"grunt-lineending": "
|
|
81
|
-
"jasmine-node": "
|
|
82
|
-
"jasmine-reporters": "
|
|
83
|
-
"remapify": "
|
|
69
|
+
"coveralls": "^3.0.0",
|
|
70
|
+
"grunt": "^1.0.1",
|
|
71
|
+
"grunt-browserify": "^5.2.0",
|
|
72
|
+
"grunt-cli": "^1.2.0",
|
|
73
|
+
"grunt-contrib-copy": "^1.0.0",
|
|
74
|
+
"grunt-contrib-jasmine": "^1.1.0",
|
|
75
|
+
"grunt-contrib-jshint": "^1.1.0",
|
|
76
|
+
"grunt-contrib-uglify": "^3.1.0",
|
|
77
|
+
"grunt-jasmine-node": "^0.3.1",
|
|
78
|
+
"grunt-jasmine-node-coverage": "^2.0.1",
|
|
79
|
+
"grunt-jscs": "^3.0.1",
|
|
80
|
+
"grunt-lineending": "^1.0.0",
|
|
81
|
+
"jasmine-node": "^1.14.5",
|
|
82
|
+
"jasmine-reporters": "^2.2.1",
|
|
83
|
+
"remapify": "^2.1.0"
|
|
84
84
|
}
|
|
85
85
|
}
|
package/src/SchemaCache.js
CHANGED
|
@@ -121,7 +121,15 @@ exports.getSchemaByUri = function (report, uri, root) {
|
|
|
121
121
|
|
|
122
122
|
var remoteReport = new Report(report);
|
|
123
123
|
if (SchemaCompilation.compileSchema.call(this, remoteReport, result)) {
|
|
124
|
-
|
|
124
|
+
var savedOptions = this.options;
|
|
125
|
+
try {
|
|
126
|
+
// If custom validationOptions were provided to setRemoteReference(),
|
|
127
|
+
// use them instead of the default options
|
|
128
|
+
this.options = result.__$validationOptions || this.options;
|
|
129
|
+
SchemaValidation.validateSchema.call(this, remoteReport, result);
|
|
130
|
+
} finally {
|
|
131
|
+
this.options = savedOptions;
|
|
132
|
+
}
|
|
125
133
|
}
|
|
126
134
|
var remoteReportIsValid = remoteReport.isValid();
|
|
127
135
|
if (!remoteReportIsValid) {
|
package/src/ZSchema.js
CHANGED
|
@@ -60,15 +60,8 @@ var defaultOptions = {
|
|
|
60
60
|
customValidator: null
|
|
61
61
|
};
|
|
62
62
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
*/
|
|
66
|
-
function ZSchema(options) {
|
|
67
|
-
this.cache = {};
|
|
68
|
-
this.referenceCache = [];
|
|
69
|
-
|
|
70
|
-
this.setRemoteReference("http://json-schema.org/draft-04/schema", Draft4Schema);
|
|
71
|
-
this.setRemoteReference("http://json-schema.org/draft-04/hyper-schema", Draft4HyperSchema);
|
|
63
|
+
function normalizeOptions(options) {
|
|
64
|
+
var normalized;
|
|
72
65
|
|
|
73
66
|
// options
|
|
74
67
|
if (typeof options === "object") {
|
|
@@ -94,22 +87,39 @@ function ZSchema(options) {
|
|
|
94
87
|
}
|
|
95
88
|
}
|
|
96
89
|
|
|
97
|
-
|
|
90
|
+
normalized = options;
|
|
98
91
|
} else {
|
|
99
|
-
|
|
92
|
+
normalized = Utils.clone(defaultOptions);
|
|
100
93
|
}
|
|
101
94
|
|
|
102
|
-
if (
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
95
|
+
if (normalized.strictMode === true) {
|
|
96
|
+
normalized.forceAdditional = true;
|
|
97
|
+
normalized.forceItems = true;
|
|
98
|
+
normalized.forceMaxLength = true;
|
|
99
|
+
normalized.forceProperties = true;
|
|
100
|
+
normalized.noExtraKeywords = true;
|
|
101
|
+
normalized.noTypeless = true;
|
|
102
|
+
normalized.noEmptyStrings = true;
|
|
103
|
+
normalized.noEmptyArrays = true;
|
|
111
104
|
}
|
|
112
105
|
|
|
106
|
+
return normalized;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/*
|
|
110
|
+
constructor
|
|
111
|
+
*/
|
|
112
|
+
function ZSchema(options) {
|
|
113
|
+
this.cache = {};
|
|
114
|
+
this.referenceCache = [];
|
|
115
|
+
|
|
116
|
+
this.options = normalizeOptions(options);
|
|
117
|
+
|
|
118
|
+
// Disable strict validation for the built-in schemas
|
|
119
|
+
var metaschemaOptions = normalizeOptions({ });
|
|
120
|
+
|
|
121
|
+
this.setRemoteReference("http://json-schema.org/draft-04/schema", Draft4Schema, metaschemaOptions);
|
|
122
|
+
this.setRemoteReference("http://json-schema.org/draft-04/hyper-schema", Draft4HyperSchema, metaschemaOptions);
|
|
113
123
|
}
|
|
114
124
|
|
|
115
125
|
/*
|
|
@@ -257,12 +267,17 @@ ZSchema.prototype.getMissingRemoteReferences = function () {
|
|
|
257
267
|
}
|
|
258
268
|
return missingRemoteReferences;
|
|
259
269
|
};
|
|
260
|
-
ZSchema.prototype.setRemoteReference = function (uri, schema) {
|
|
270
|
+
ZSchema.prototype.setRemoteReference = function (uri, schema, validationOptions) {
|
|
261
271
|
if (typeof schema === "string") {
|
|
262
272
|
schema = JSON.parse(schema);
|
|
263
273
|
} else {
|
|
264
274
|
schema = Utils.cloneDeep(schema);
|
|
265
275
|
}
|
|
276
|
+
|
|
277
|
+
if (validationOptions) {
|
|
278
|
+
schema.__$validationOptions = normalizeOptions(validationOptions);
|
|
279
|
+
}
|
|
280
|
+
|
|
266
281
|
SchemaCache.cacheSchemaByUri.call(this, uri, schema);
|
|
267
282
|
};
|
|
268
283
|
ZSchema.prototype.getResolvedSchema = function (schema) {
|