z-schema 3.21.0 → 3.22.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.
@@ -6384,12 +6384,19 @@ var JsonValidators = {
6384
6384
  report.addError(error, [json], null, schema.description);
6385
6385
  }
6386
6386
  },
6387
- /*
6388
6387
  type: function (report, schema, json) {
6389
6388
  // http://json-schema.org/latest/json-schema-validation.html#rfc.section.5.5.2.2
6390
- // type is handled before this is called so ignore
6389
+ var jsonType = Utils.whatIs(json);
6390
+ if (typeof schema.type === "string") {
6391
+ if (jsonType !== schema.type && (jsonType !== "integer" || schema.type !== "number")) {
6392
+ report.addError("INVALID_TYPE", [schema.type, jsonType], null, schema.description);
6393
+ }
6394
+ } else {
6395
+ if (schema.type.indexOf(jsonType) === -1 && (jsonType !== "integer" || schema.type.indexOf("number") === -1)) {
6396
+ report.addError("INVALID_TYPE", [schema.type, jsonType], null, schema.description);
6397
+ }
6398
+ }
6391
6399
  },
6392
- */
6393
6400
  allOf: function (report, schema, json) {
6394
6401
  // http://json-schema.org/latest/json-schema-validation.html#rfc.section.5.5.3.2
6395
6402
  var idx = schema.allOf.length;
@@ -6616,23 +6623,12 @@ exports.validate = function (report, schema, json) {
6616
6623
  }
6617
6624
 
6618
6625
  // type checking first
6619
- // http://json-schema.org/latest/json-schema-validation.html#rfc.section.5.5.2.2
6620
6626
  var jsonType = Utils.whatIs(json);
6621
6627
  if (schema.type) {
6622
- if (typeof schema.type === "string") {
6623
- if (jsonType !== schema.type && (jsonType !== "integer" || schema.type !== "number")) {
6624
- report.addError("INVALID_TYPE", [schema.type, jsonType], null, schema.description);
6625
- if (this.options.breakOnFirstError) {
6626
- return false;
6627
- }
6628
- }
6629
- } else {
6630
- if (schema.type.indexOf(jsonType) === -1 && (jsonType !== "integer" || schema.type.indexOf("number") === -1)) {
6631
- report.addError("INVALID_TYPE", [schema.type, jsonType], null, schema.description);
6632
- if (this.options.breakOnFirstError) {
6633
- return false;
6634
- }
6635
- }
6628
+ keys.splice(keys.indexOf("type"), 1);
6629
+ JsonValidators.type.call(this, report, schema, json);
6630
+ if (report.errors.length && this.options.breakOnFirstError) {
6631
+ return false;
6636
6632
  }
6637
6633
  }
6638
6634
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "z-schema",
3
- "version": "3.21.0",
3
+ "version": "3.22.0",
4
4
  "description": "JSON schema validator",
5
5
  "homepage": "https://github.com/zaggino/z-schema",
6
6
  "authors": [
@@ -262,12 +262,19 @@ var JsonValidators = {
262
262
  report.addError(error, [json], null, schema.description);
263
263
  }
264
264
  },
265
- /*
266
265
  type: function (report, schema, json) {
267
266
  // http://json-schema.org/latest/json-schema-validation.html#rfc.section.5.5.2.2
268
- // type is handled before this is called so ignore
267
+ var jsonType = Utils.whatIs(json);
268
+ if (typeof schema.type === "string") {
269
+ if (jsonType !== schema.type && (jsonType !== "integer" || schema.type !== "number")) {
270
+ report.addError("INVALID_TYPE", [schema.type, jsonType], null, schema.description);
271
+ }
272
+ } else {
273
+ if (schema.type.indexOf(jsonType) === -1 && (jsonType !== "integer" || schema.type.indexOf("number") === -1)) {
274
+ report.addError("INVALID_TYPE", [schema.type, jsonType], null, schema.description);
275
+ }
276
+ }
269
277
  },
270
- */
271
278
  allOf: function (report, schema, json) {
272
279
  // http://json-schema.org/latest/json-schema-validation.html#rfc.section.5.5.3.2
273
280
  var idx = schema.allOf.length;
@@ -494,23 +501,12 @@ exports.validate = function (report, schema, json) {
494
501
  }
495
502
 
496
503
  // type checking first
497
- // http://json-schema.org/latest/json-schema-validation.html#rfc.section.5.5.2.2
498
504
  var jsonType = Utils.whatIs(json);
499
505
  if (schema.type) {
500
- if (typeof schema.type === "string") {
501
- if (jsonType !== schema.type && (jsonType !== "integer" || schema.type !== "number")) {
502
- report.addError("INVALID_TYPE", [schema.type, jsonType], null, schema.description);
503
- if (this.options.breakOnFirstError) {
504
- return false;
505
- }
506
- }
507
- } else {
508
- if (schema.type.indexOf(jsonType) === -1 && (jsonType !== "integer" || schema.type.indexOf("number") === -1)) {
509
- report.addError("INVALID_TYPE", [schema.type, jsonType], null, schema.description);
510
- if (this.options.breakOnFirstError) {
511
- return false;
512
- }
513
- }
506
+ keys.splice(keys.indexOf("type"), 1);
507
+ JsonValidators.type.call(this, report, schema, json);
508
+ if (report.errors.length && this.options.breakOnFirstError) {
509
+ return false;
514
510
  }
515
511
  }
516
512