Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

jsonschema

Package Overview
Dependencies
Maintainers
1
Versions
38
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jsonschema - npm Package Compare versions

Comparing version 0.1.4 to 0.1.5

12

lib/attribute.js

@@ -114,3 +114,3 @@ 'use strict';

} else {
return this.createError("no such schema" + this.value);
return this.createError("no such schema " + this.value);
}

@@ -146,3 +146,3 @@ };

if (!valid) {
return this.createError("does not meet minimum length of" + this.value);
return this.createError("does not meet minimum length of " + this.value);
}

@@ -158,3 +158,3 @@ };

if (!valid) {
return this.createError("does not meet maximum length of" + this.value);
return this.createError("does not meet maximum length of " + this.value);
}

@@ -170,3 +170,3 @@ };

if (!valid) {
return this.createError("does not meet minimum length of" + this.value);
return this.createError("does not meet minimum length of " + this.value);
}

@@ -182,3 +182,3 @@ };

if (!valid) {
return this.createError("does not meet maximum length of" + this.value);
return this.createError("does not meet maximum length of " + this.value);
}

@@ -208,2 +208,2 @@ };

module.exports = Attribute;
module.exports = Attribute;

@@ -184,3 +184,5 @@ 'use strict';

var i, len;
var errors = [];
var numErrors = this.errors.length;
var startingNumErrors = numErrors;
var valid = false;
for (i = 0, len = schema.type.length; i < len; i++) {

@@ -192,17 +194,14 @@ if (typeof schema.type[i] === 'string') {

}
if (this.errors.length === 0) {
// early exit one element of the union passes the test
return;
if (this.errors.length === numErrors) {
valid = true;
break;
} else {
// reset
errors = errors.concat(this.errors);
this.errors = [];
numErrors = this.errors.length - startingNumErrors;
}
}
this.errors = errors;
if (this.errors.length !== 0) {
this.addError("not any of union type");
if (valid) {
this.errors = this.errors.slice(0, startingNumErrors);
} else {
this.addError("not any of union type");
}

@@ -209,0 +208,0 @@ };

{
"author": "Tom de Grunt <tom@degrunt.nl>",
"name": "jsonschema",
"version": "0.1.4",
"version": "0.1.5",
"dependencies": {

@@ -6,0 +6,0 @@ "mocha": "~1.3",

@@ -116,4 +116,3 @@ 'use strict';

};
var validator = new Validator();
validator.validate({'wildcards': ['*']}, schema).should.be.empty;
this.validator.validate({'wildcards': ['*']}, schema).should.be.empty;
});

@@ -131,4 +130,3 @@

};
var validator = new Validator();
validator.validate({'wildcards': []}, schema).should.be.empty;
this.validator.validate({'wildcards': []}, schema).should.be.empty;
});

@@ -146,4 +144,3 @@

};
var validator = new Validator();
validator.validate({'wildcards': [{"id": "1234", "_bsontype": "test"}, '*']}, schema).should.be.empty;
this.validator.validate({'wildcards': [{"id": "1234", "_bsontype": "test"}, '*']}, schema).should.be.empty;
});

@@ -161,7 +158,48 @@

};
var validator = new Validator();
validator.validate({'wildcards': [{"id": "1234", "_bsontype": "test"}, '*']}, schema).should.be.empty;
this.validator.validate({'wildcards': [{"id": "1234", "_bsontype": "test"}, '*']}, schema).should.be.empty;
});
});
});
describe('union type in nested object array', function () {
var schema = {
type: 'object',
required: true,
properties: {
frames: {
type: 'array',
required: true,
items: {
type: 'object',
properties: {
filename: {type: 'string', required: true},
lineno: {type: ['integer', 'null']},
method: {type: ['string', 'null']}
}
}
},
exception: {
type: 'object',
required: true,
properties: {
class: {type: 'string', required: true},
message: {type: 'string'}
}
}
}
};
var exc = {class: 'testing...', message: 'this is only a test'};
it('should validate for nulls', function () {
var instance = {frames: [{filename: 'somefile.js', lineno: null}], exception: exc};
this.validator.validate(instance, schema).should.be.empty;
});
it('should validate for null and string', function () {
var instance = {frames: [{filename: 'somefile.js', lineno: null}], exception: exc};
this.validator.validate(instance, schema).should.be.empty;
});
it('should not validate for string and string', function () {
var instance = {frames: [{filename: 'somefile.js', lineno: {hello: 'world'}}], exception: exc};
this.validator.validate(instance, schema).should.not.be.empty;
});
});
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc