-
-
Notifications
You must be signed in to change notification settings - Fork 240
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 rules for validation uniqueness of tag names (#2104)
Co-authored-by: Jakub Rożek <jakub@rozek.tech>
- Loading branch information
1 parent
9acc633
commit 4447d81
Showing
10 changed files
with
441 additions
and
1 deletion.
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
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
160 changes: 160 additions & 0 deletions
160
packages/rulesets/src/asyncapi/__tests__/asyncapi-tags-uniqueness.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,160 @@ | ||
import { DiagnosticSeverity } from '@stoplight/types'; | ||
import testRule from './__helpers__/tester'; | ||
|
||
testRule('asyncapi-tags-uniqueness', [ | ||
{ | ||
name: 'valid case', | ||
document: { | ||
asyncapi: '2.0.0', | ||
tags: [{ name: 'one' }, { name: 'two' }], | ||
}, | ||
errors: [], | ||
}, | ||
|
||
{ | ||
name: 'tags has duplicated names (root)', | ||
document: { | ||
asyncapi: '2.0.0', | ||
tags: [{ name: 'one' }, { name: 'one' }], | ||
}, | ||
errors: [ | ||
{ | ||
message: '"tags" object contains duplicate tag name "one".', | ||
path: ['tags', '1', 'name'], | ||
severity: DiagnosticSeverity.Error, | ||
}, | ||
], | ||
}, | ||
|
||
{ | ||
name: 'tags has duplicated names (operation)', | ||
document: { | ||
asyncapi: '2.0.0', | ||
channels: { | ||
someChannel: { | ||
publish: { | ||
tags: [{ name: 'one' }, { name: 'one' }], | ||
}, | ||
subscribe: { | ||
tags: [{ name: 'one' }, { name: 'one' }], | ||
}, | ||
}, | ||
}, | ||
}, | ||
errors: [ | ||
{ | ||
message: '"tags" object contains duplicate tag name "one".', | ||
path: ['channels', 'someChannel', 'publish', 'tags', '1', 'name'], | ||
severity: DiagnosticSeverity.Error, | ||
}, | ||
{ | ||
message: '"tags" object contains duplicate tag name "one".', | ||
path: ['channels', 'someChannel', 'subscribe', 'tags', '1', 'name'], | ||
severity: DiagnosticSeverity.Error, | ||
}, | ||
], | ||
}, | ||
|
||
{ | ||
name: 'tags has duplicated names (operation trait)', | ||
document: { | ||
asyncapi: '2.0.0', | ||
channels: { | ||
someChannel: { | ||
publish: { | ||
traits: [ | ||
{ | ||
tags: [{ name: 'one' }, { name: 'one' }], | ||
}, | ||
], | ||
}, | ||
subscribe: { | ||
traits: [ | ||
{ | ||
tags: [{ name: 'one' }, { name: 'one' }], | ||
}, | ||
], | ||
}, | ||
}, | ||
}, | ||
}, | ||
errors: [ | ||
{ | ||
message: '"tags" object contains duplicate tag name "one".', | ||
path: ['channels', 'someChannel', 'publish', 'traits', '0', 'tags', '1', 'name'], | ||
severity: DiagnosticSeverity.Error, | ||
}, | ||
{ | ||
message: '"tags" object contains duplicate tag name "one".', | ||
path: ['channels', 'someChannel', 'subscribe', 'traits', '0', 'tags', '1', 'name'], | ||
severity: DiagnosticSeverity.Error, | ||
}, | ||
], | ||
}, | ||
|
||
{ | ||
name: 'tags has duplicated names (message)', | ||
document: { | ||
asyncapi: '2.0.0', | ||
components: { | ||
messages: { | ||
someMessage: { | ||
tags: [{ name: 'one' }, { name: 'one' }], | ||
}, | ||
}, | ||
}, | ||
}, | ||
errors: [ | ||
{ | ||
message: '"tags" object contains duplicate tag name "one".', | ||
path: ['components', 'messages', 'someMessage', 'tags', '1', 'name'], | ||
severity: DiagnosticSeverity.Error, | ||
}, | ||
], | ||
}, | ||
|
||
{ | ||
name: 'tags has duplicated names (message trait)', | ||
document: { | ||
asyncapi: '2.0.0', | ||
components: { | ||
messages: { | ||
someMessage: { | ||
traits: [ | ||
{ | ||
tags: [{ name: 'one' }, { name: 'one' }], | ||
}, | ||
], | ||
}, | ||
}, | ||
}, | ||
}, | ||
errors: [ | ||
{ | ||
message: '"tags" object contains duplicate tag name "one".', | ||
path: ['components', 'messages', 'someMessage', 'traits', '0', 'tags', '1', 'name'], | ||
severity: DiagnosticSeverity.Error, | ||
}, | ||
], | ||
}, | ||
|
||
{ | ||
name: 'tags has duplicated more that two times this same name', | ||
document: { | ||
asyncapi: '2.0.0', | ||
tags: [{ name: 'one' }, { name: 'one' }, { name: 'two' }, { name: 'one' }], | ||
}, | ||
errors: [ | ||
{ | ||
message: '"tags" object contains duplicate tag name "one".', | ||
path: ['tags', '1', 'name'], | ||
severity: DiagnosticSeverity.Error, | ||
}, | ||
{ | ||
message: '"tags" object contains duplicate tag name "one".', | ||
path: ['tags', '3', 'name'], | ||
severity: DiagnosticSeverity.Error, | ||
}, | ||
], | ||
}, | ||
]); |
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
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
48 changes: 48 additions & 0 deletions
48
packages/rulesets/src/oas/__tests__/openapi-tags-uniqueness.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,48 @@ | ||
import { DiagnosticSeverity } from '@stoplight/types'; | ||
import testRule from './__helpers__/tester'; | ||
|
||
testRule('openapi-tags-uniqueness', [ | ||
{ | ||
name: 'valid case', | ||
document: { | ||
swagger: '2.0', | ||
tags: [{ name: 'one' }, { name: 'two' }], | ||
}, | ||
errors: [], | ||
}, | ||
|
||
{ | ||
name: 'tags has duplicated names', | ||
document: { | ||
swagger: '2.0', | ||
tags: [{ name: 'one' }, { name: 'one' }], | ||
}, | ||
errors: [ | ||
{ | ||
message: '"tags" object contains duplicate tag name "one".', | ||
path: ['tags', '1', 'name'], | ||
severity: DiagnosticSeverity.Error, | ||
}, | ||
], | ||
}, | ||
|
||
{ | ||
name: 'tags has duplicated more that two times this same name', | ||
document: { | ||
swagger: '2.0', | ||
tags: [{ name: 'one' }, { name: 'one' }, { name: 'two' }, { name: 'one' }], | ||
}, | ||
errors: [ | ||
{ | ||
message: '"tags" object contains duplicate tag name "one".', | ||
path: ['tags', '1', 'name'], | ||
severity: DiagnosticSeverity.Error, | ||
}, | ||
{ | ||
message: '"tags" object contains duplicate tag name "one".', | ||
path: ['tags', '3', 'name'], | ||
severity: DiagnosticSeverity.Error, | ||
}, | ||
], | ||
}, | ||
]); |
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
Oops, something went wrong.