Skip to content

Commit bad0885

Browse files
Fixed a bug with the $Refs.circular property
1 parent 7fb22e6 commit bad0885

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

lib/dereference.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ function crawl(obj, path, parents, $refs, options) {
4646

4747
// Check for circular references
4848
var circular = pointer.circular || parents.indexOf(pointer.value) !== -1;
49-
$refs.circular = $refs.circular || true;
50-
if (!options.$refs.circular) {
49+
$refs.circular = $refs.circular || circular;
50+
if ($refs.circular && !options.$refs.circular) {
5151
throw ono.reference('Circular $ref pointer found at %s', keyPath);
5252
}
5353

tests/specs/deep-circular/deep-circular.spec.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,14 @@ describe('Schema with deeply-nested circular $refs', function() {
5757
// A ReferenceError should have been thrown
5858
expect(err).to.be.an.instanceOf(ReferenceError);
5959
expect(err.message).to.contain('Circular $ref pointer found at ');
60-
expect(err.message).to.contain('specs/deep-circular/deep-circular.yaml#/properties/name/type');
60+
expect(err.message).to.contain(
61+
'specs/deep-circular/deep-circular.yaml#/properties/level1/properties/level2/properties/' +
62+
'level3/properties/level4/properties/level5/properties/level6/properties/level7/properties/' +
63+
'level8/properties/level9/properties/level10/properties/level11/properties/level12/properties/' +
64+
'level13/properties/level14/properties/level15/properties/level16/properties/level17/properties/' +
65+
'level18/properties/level19/properties/level20/properties/level21/properties/level22/properties/' +
66+
'level23/properties/level24/properties/level25/properties/level26/properties/level27/properties/' +
67+
'level28/properties/level29/properties/level30');
6168

6269
// $Refs.circular should be true
6370
expect(parser.$refs.circular).to.equal(true);

0 commit comments

Comments
 (0)