Skip to content

Commit e2a72df

Browse files
committed
test(core): direct circular file $refs
1 parent 215ae93 commit e2a72df

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

packages/core/src/__tests__/linter.test.ts

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1637,4 +1637,49 @@ responses:: !!foo
16371637
}),
16381638
]);
16391639
});
1640+
1641+
test.concurrent('should handle direct circular file $refs', async () => {
1642+
const spectral = new Spectral();
1643+
spectral.setRuleset({
1644+
rules: {
1645+
'valid-type': {
1646+
given: '$..type',
1647+
then: {
1648+
function() {
1649+
return [
1650+
{
1651+
message: 'Restricted type',
1652+
},
1653+
];
1654+
},
1655+
},
1656+
},
1657+
},
1658+
});
1659+
1660+
const documentUri = path.join(__dirname, './__fixtures__/test.json');
1661+
const document = new Document(
1662+
JSON.stringify({
1663+
oneOf: [
1664+
{
1665+
type: 'number',
1666+
},
1667+
{
1668+
$ref: './test.json',
1669+
},
1670+
],
1671+
}),
1672+
Parsers.Json,
1673+
documentUri,
1674+
);
1675+
const results = spectral.run(document);
1676+
1677+
await expect(results).resolves.toEqual([
1678+
expect.objectContaining({
1679+
code: 'valid-type',
1680+
path: ['oneOf', '0', 'type'],
1681+
severity: DiagnosticSeverity.Warning,
1682+
}),
1683+
]);
1684+
});
16401685
});

0 commit comments

Comments
 (0)