z-schema 3.18.4 → 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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "z-schema",
3
- "version": "3.18.4",
3
+ "version": "3.19.0",
4
4
  "description": "JSON schema validator",
5
5
  "homepage": "https://github.com/zaggino/z-schema",
6
6
  "authors": [
@@ -60,26 +60,26 @@
60
60
  "dependencies": {
61
61
  "lodash.get": "^4.0.0",
62
62
  "lodash.isequal": "^4.0.0",
63
- "validator": "^8.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": "latest",
69
+ "coveralls": "^3.0.0",
70
70
  "grunt": "^1.0.1",
71
- "grunt-cli": "latest",
72
71
  "grunt-browserify": "^5.2.0",
73
- "grunt-contrib-copy": "latest",
74
- "grunt-contrib-jasmine": "latest",
75
- "grunt-contrib-jshint": "latest",
76
- "grunt-contrib-uglify": "latest",
77
- "grunt-jasmine-node": "latest",
78
- "grunt-jasmine-node-coverage": "^1.2.0",
79
- "grunt-jscs": "latest",
80
- "grunt-lineending": "latest",
81
- "jasmine-node": "latest",
82
- "jasmine-reporters": "latest",
83
- "remapify": "latest"
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
  }
@@ -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
- SchemaValidation.validateSchema.call(this, remoteReport, result);
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
- constructor
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
- this.options = options;
90
+ normalized = options;
98
91
  } else {
99
- this.options = Utils.clone(defaultOptions);
92
+ normalized = Utils.clone(defaultOptions);
100
93
  }
101
94
 
102
- if (this.options.strictMode === true) {
103
- this.options.forceAdditional = true;
104
- this.options.forceItems = true;
105
- this.options.forceMaxLength = true;
106
- this.options.forceProperties = true;
107
- this.options.noExtraKeywords = true;
108
- this.options.noTypeless = true;
109
- this.options.noEmptyStrings = true;
110
- this.options.noEmptyArrays = true;
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) {