Merge pull request #804 from epoberezkin/fix-compile-async

Fix compile async
master
Evgeny Poberezkin 2018-06-10 11:44:05 +01:00 committed by GitHub
commit aa5ab8dfc7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 39 additions and 0 deletions

View File

@ -351,6 +351,10 @@ function _compile(schemaObj, root) {
var v;
try { v = compileSchema.call(this, schemaObj.schema, root, schemaObj.localRefs); }
catch(e) {
delete schemaObj.validate;
throw e;
}
finally {
schemaObj.compiling = false;
if (schemaObj.meta) this._opts = currentOpts;

View File

@ -60,6 +60,24 @@ describe('compileAsync method', function() {
"enum": ["foo", "bar"]
}
}
},
"http://example.com/foo.json": {
"$id": "http://example.com/foo.json",
"type": "object",
"properties": {
"bar": {"$ref": "bar.json"},
"other": {"$ref": "other.json"}
}
},
"http://example.com/bar.json": {
"$id": "http://example.com/bar.json",
"type": "object",
"properties": {
"foo": {"$ref": "foo.json"}
}
},
"http://example.com/other.json": {
"$id": "http://example.com/other.json"
}
};
@ -412,6 +430,23 @@ describe('compileAsync method', function() {
});
describe('schema with multiple remote properties, the first is recursive schema (#801)', function() {
it('should validate data', function() {
var schema = {
"$id": "http://example.com/list.json",
"type": "object",
"properties": {
"foo": {"$ref": "foo.json"}
}
};
return ajv.compileAsync(schema).then(function (validate) {
validate({foo: {}}) .should.equal(true);
});
});
});
function loadSchema(uri) {
loadCallCount++;
return new Promise(function (resolve, reject) {