jsonschema
Advanced tools
Comparing version 0.1.0 to 0.1.1
@@ -160,15 +160,24 @@ 'use strict'; | ||
var i, len; | ||
var invalid; | ||
var errors = []; | ||
for (i = 0, len = schema.type.length; i < len; i++) { | ||
if (typeof schema.type[i] === 'string') { | ||
invalid = this.validateSchema(instance, {'type': schema.type[i]}, {'addError': false}); | ||
this.validateSchema(instance, {'type': schema.type[i]}); | ||
} else { | ||
invalid = this.validateSchema(instance, schema.type[i], {'addError': false}); | ||
this.validateSchema(instance, schema.type[i]); | ||
} | ||
if (!helpers.isDefined(invalid)) { | ||
break; | ||
if (this.errors.length === 0) { | ||
// early exit one element of the union passes the test | ||
return; | ||
} else { | ||
// reset | ||
errors = errors.concat(this.errors); | ||
this.errors = []; | ||
} | ||
} | ||
if (helpers.isDefined(invalid)) { | ||
this.addError("not any of union type"); | ||
this.errors = errors; | ||
if (this.errors.length !== 0) { | ||
this.addError("not any of union type"); | ||
} | ||
@@ -175,0 +184,0 @@ }; |
{ | ||
"author": "Tom de Grunt <tom@degrunt.nl>", | ||
"name": "jsonschema", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"dependencies": { | ||
@@ -6,0 +6,0 @@ "mocha": "~1.3.0", |
@@ -148,3 +148,17 @@ 'use strict'; | ||
it('should validate for objectid and ignore title and description', function () { | ||
var schema = { | ||
"type": "object", | ||
"properties": { | ||
"wildcards": { | ||
"type": "array", | ||
"items": {"type": [{"$ref": "MongoDb#ObjectId", "title": "test", "description": "test"}, {"type": "string", "pattern": "^\\*$"}]} | ||
} | ||
} | ||
}; | ||
var validator = new Validator(); | ||
validator.validate({'wildcards': [{"id": "1234", "_bsontype": "test"}, '*']}, schema).should.be.empty; | ||
}); | ||
}); | ||
}); |
50097
1181