-
-
Notifications
You must be signed in to change notification settings - Fork 242
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(rulesets): add validation ruleset for v3
- Loading branch information
1 parent
ecaffde
commit 6f55c0b
Showing
6 changed files
with
388 additions
and
83 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
157 changes: 157 additions & 0 deletions
157
packages/rulesets/src/asyncapi/__tests__/asyncapi-3-document-resolved.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,157 @@ | ||
import { DiagnosticSeverity } from '@stoplight/types'; | ||
import testRule from './__helpers__/tester'; | ||
|
||
testRule('asyncapi-3-document-resolved', [ | ||
{ | ||
name: 'valid case AsyncAPI 3', | ||
document: { | ||
asyncapi: '3.0.0', | ||
info: { | ||
title: 'Valid AsyncApi document', | ||
version: '1.0', | ||
}, | ||
}, | ||
errors: [], | ||
}, | ||
{ | ||
name: 'valid case resolved case message', | ||
document: { | ||
asyncapi: '3.0.0', | ||
info: { | ||
title: 'Valid AsyncApi document', | ||
version: '1.0', | ||
}, | ||
channels: { | ||
SomeChannel: { | ||
address: 'users/{userId}/signedUp', | ||
messages: { | ||
SomeMessage: { $ref: '#/components/messages/SomeMessage' }, | ||
}, | ||
}, | ||
}, | ||
components: { | ||
messages: { | ||
SomeMessage: { payload: { type: 'string' } }, | ||
}, | ||
}, | ||
}, | ||
errors: [], | ||
}, | ||
{ | ||
name: 'invalid AsyncAPI 3 info property is missing', | ||
document: { | ||
asyncapi: '3.0.0', | ||
}, | ||
errors: [{ message: 'Object must have required property "info"', severity: DiagnosticSeverity.Error }], | ||
}, | ||
{ | ||
name: 'invalid AsyncAPI 3 resolved case message', | ||
document: { | ||
asyncapi: '3.0.0', | ||
info: { | ||
title: 'Valid AsyncApi document', | ||
version: '1.0', | ||
}, | ||
channels: { | ||
SomeChannel: { | ||
address: 'users/{userId}/signedUp', | ||
messages: { | ||
SomeMessage: { $ref: '#/x-SomeMessage' }, | ||
}, | ||
}, | ||
}, | ||
'x-SomeMessage': { test: 'test' }, | ||
}, | ||
errors: [ | ||
{ | ||
message: 'Property "test" is not expected to be here', | ||
severity: DiagnosticSeverity.Error, | ||
path: ['channels', 'SomeChannel', 'messages', 'SomeMessage', 'test'], | ||
}, | ||
], | ||
}, | ||
{ | ||
name: 'valid case (3.0.0 version)', | ||
document: { | ||
asyncapi: '3.0.0', | ||
info: { | ||
title: 'Signup service example (internal)', | ||
version: '0.1.0', | ||
}, | ||
channels: { | ||
'user/signedup': { | ||
address: 'user/signedup', | ||
messages: { | ||
'subscribe.message': { | ||
payload: {}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
operations: { | ||
'user/signedup.subscribe': { | ||
action: 'send', | ||
channel: { | ||
address: 'user/signedup', | ||
messages: { | ||
'subscribe.message': { | ||
payload: {}, | ||
}, | ||
}, | ||
}, | ||
messages: [ | ||
{ | ||
payload: {}, | ||
}, | ||
], | ||
}, | ||
}, | ||
}, | ||
errors: [], | ||
}, | ||
|
||
{ | ||
name: 'invalid case for 3.0.0 (info.version property is missing)', | ||
document: { | ||
asyncapi: '3.0.0', | ||
info: { | ||
title: 'Valid AsyncApi document', | ||
}, | ||
}, | ||
errors: [ | ||
{ | ||
message: '"info" property must have required property "version"', | ||
severity: DiagnosticSeverity.Error, | ||
}, | ||
], | ||
}, | ||
|
||
{ | ||
name: 'valid case for 3.X.X (case validating $ref resolution works as expected)', | ||
document: { | ||
asyncapi: '3.0.0', | ||
info: { | ||
title: 'Signup service example (internal)', | ||
version: '0.1.0', | ||
}, | ||
channels: { | ||
userSignedup: { | ||
address: 'user/signedup', | ||
messages: { | ||
'subscribe.message': { | ||
$ref: '#/components/messages/testMessage', | ||
}, | ||
}, | ||
}, | ||
}, | ||
components: { | ||
messages: { | ||
testMessage: { | ||
payload: {}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
errors: [], | ||
}, | ||
]); |
89 changes: 89 additions & 0 deletions
89
packages/rulesets/src/asyncapi/__tests__/asyncapi-3-document-unresolved.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,89 @@ | ||
import { DiagnosticSeverity } from '@stoplight/types'; | ||
import testRule from './__helpers__/tester'; | ||
|
||
testRule('asyncapi-3-document-unresolved', [ | ||
{ | ||
name: 'valid case AsyncAPI 3', | ||
document: { | ||
asyncapi: '3.0.0', | ||
info: { | ||
title: 'Valid AsyncApi document', | ||
version: '1.0', | ||
}, | ||
}, | ||
errors: [], | ||
}, | ||
{ | ||
name: 'valid case unresolved case message', | ||
document: { | ||
asyncapi: '3.0.0', | ||
info: { | ||
title: 'Valid AsyncApi document', | ||
version: '1.0', | ||
}, | ||
channels: { | ||
SomeChannel: { | ||
address: 'users/{userId}/signedUp', | ||
messages: { | ||
SomeMessage: { $ref: '#/components/messages/SomeMessage' }, | ||
}, | ||
}, | ||
}, | ||
components: { | ||
messages: { | ||
SomeMessage: { payload: { type: 'string' } }, | ||
}, | ||
}, | ||
}, | ||
errors: [], | ||
}, | ||
{ | ||
name: 'valid AsyncAPI 3 unresolved case operations', | ||
document: { | ||
asyncapi: '3.0.0', | ||
info: { | ||
title: 'Valid AsyncApi document', | ||
version: '1.0', | ||
}, | ||
channels: { | ||
SomeChannel: { | ||
address: 'users/{userId}/signedUp', | ||
messages: { | ||
SomeMessage: { $ref: '#/x-SomeMessage' }, | ||
}, | ||
}, | ||
}, | ||
operations: { | ||
SomeOperation: { | ||
action: 'send', | ||
channel: { | ||
$ref: '#/channels/SomeChannel', | ||
}, | ||
messages: [{ $ref: '#/channels/SomeChannel' }], | ||
}, | ||
}, | ||
}, | ||
errors: [], | ||
}, | ||
{ | ||
name: 'invalid case for 3.0.0 (reference for info object is not allowed)', | ||
document: { | ||
asyncapi: '3.0.0', | ||
info: { | ||
$ref: '#/components/x-titles/someTitle', | ||
}, | ||
components: { | ||
'x-titles': { | ||
someTitle: 'some-title', | ||
}, | ||
}, | ||
}, | ||
errors: [ | ||
{ | ||
message: 'Referencing in this place is not allowed', | ||
path: ['info'], | ||
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.