removeSchema called with id without matching schema does not throw error

master
Evgeny Poberezkin 2016-02-13 20:14:04 +00:00
parent 79d16b3dee
commit a0a172c90a
4 changed files with 55 additions and 2 deletions

View File

@ -187,7 +187,7 @@ function Ajv(opts) {
switch (typeof schemaKeyRef) {
case 'string':
var schemaObj = _getSchemaObj(schemaKeyRef);
self._cache.del(schemaObj.jsonStr);
if (schemaObj) self._cache.del(schemaObj.jsonStr);
delete self._schemas[schemaKeyRef];
delete self._refs[schemaKeyRef];
break;

View File

@ -1,6 +1,6 @@
{
"name": "ajv",
"version": "3.5.4",
"version": "3.6.0",
"description": "Another JSON Schema Validator",
"main": "lib/ajv.js",
"files": [

View File

@ -261,6 +261,13 @@ describe('Ajv', function () {
// should.not.exist(ajv.getSchema('//e.com/int.json'));
should.not.exist(ajv._cache.get(str));
});
it('should not throw if there is no schema with passed id', function() {
should.not.exist(ajv.getSchema('//e.com/int.json'));
should.not.throw(function() {
ajv.removeSchema('//e.com/int.json');
});
});
});

View File

@ -146,5 +146,51 @@
"valid": true
}
]
},
{
"description": "property value is contained in array",
"schema": {
"properties": {
"name": { "type": "string" },
"list": {
"type": "array",
"contains": { "constant": { "$data": "2/name" } }
}
}
},
"tests": [
{
"description": "1 item array containing property is valid",
"data": {
"name": "foo",
"list": [ "foo" ]
},
"valid": true
},
{
"description": "2 item array containing property is valid",
"data": {
"name": "foo",
"list": [ "foo", "bar" ]
},
"valid": true
},
{
"description": "array not containing property is invalid",
"data": {
"name": "foo",
"list": [ "bar" ]
},
"valid": false
},
{
"description": "empty array is invalid",
"data": {
"name": "foo",
"list": []
},
"valid": false
}
]
}
]