-
-
Notifications
You must be signed in to change notification settings - Fork 241
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(rulesets): add unused components server rule (#2097)
- Loading branch information
1 parent
2d9abaf
commit 71b312e
Showing
3 changed files
with
65 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
packages/rulesets/src/asyncapi/__tests__/asyncapi-unused-components-server.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { DiagnosticSeverity } from '@stoplight/types'; | ||
import produce from 'immer'; | ||
import testRule from './__helpers__/tester'; | ||
|
||
const document = { | ||
asyncapi: '2.0.0', | ||
servers: { | ||
test: { | ||
$ref: '#/components/servers/externallyDefinedServer', | ||
}, | ||
}, | ||
channels: {}, | ||
components: { | ||
servers: { | ||
externallyDefinedServer: {}, | ||
}, | ||
}, | ||
}; | ||
|
||
testRule('asyncapi-unused-components-server', [ | ||
{ | ||
name: 'valid case', | ||
document, | ||
errors: [], | ||
}, | ||
|
||
{ | ||
name: 'components.servers contains unreferenced objects', | ||
document: produce(document, (draft: any) => { | ||
delete draft.servers['test']; | ||
}), | ||
errors: [ | ||
{ | ||
message: 'Potentially unused components server has been detected.', | ||
path: ['components', 'servers', 'externallyDefinedServer'], | ||
severity: DiagnosticSeverity.Warning, | ||
}, | ||
], | ||
}, | ||
]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters