Skip to content

Commit

Permalink
Merge pull request #804 from epoberezkin/fix-compile-async
Browse files Browse the repository at this point in the history
Fix compile async
  • Loading branch information
epoberezkin committed Jun 10, 2018
2 parents 5e59fa2 + 32651b5 commit aa5ab8d
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/ajv.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
35 changes: 35 additions & 0 deletions spec/async.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
};

Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit aa5ab8d

Please sign in to comment.