-
-
Notifications
You must be signed in to change notification settings - Fork 219
/
asyncapi-payload-unsupported-schemaFormat.test.ts
75 lines (70 loc) · 2.1 KB
/
asyncapi-payload-unsupported-schemaFormat.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import { DiagnosticSeverity } from '@stoplight/types';
import produce from 'immer';
import testRule from './__helpers__/tester';
const document = {
asyncapi: '2.0.0',
channels: {
'users/{userId}/signedUp': {
publish: {
message: {},
},
subscribe: {
message: {},
},
},
},
components: {
messageTraits: {
aTrait: {},
},
messages: {
aMessage: {},
},
},
};
testRule('asyncapi-payload-unsupported-schemaFormat', [
{
name: 'valid case',
document,
errors: [],
},
{
name: 'components.messages.{message}.schemaFormat is set to a non supported value',
document: produce(document, (draft: any) => {
draft.components.messages.aMessage.schemaFormat = 'application/nope';
}),
errors: [
{
message: 'Message schema validation is only supported with default unspecified "schemaFormat".',
path: ['components', 'messages', 'aMessage', 'schemaFormat'],
severity: DiagnosticSeverity.Information,
},
],
},
{
name: 'components.messageTraits.{trait}.schemaFormat is set to a non supported value',
document: produce(document, (draft: any) => {
draft.components.messageTraits.aTrait.schemaFormat = 'application/nope';
}),
errors: [
{
message: 'Message schema validation is only supported with default unspecified "schemaFormat".',
path: ['components', 'messageTraits', 'aTrait', 'schemaFormat'],
severity: DiagnosticSeverity.Information,
},
],
},
...['publish', 'subscribe'].map(property => ({
name: `channels.{channel}.${property}.message.schemaFormat is set to a non supported value`,
document: produce(document, draft => {
draft.channels['users/{userId}/signedUp'][property].message.schemaFormat = 'application/nope';
}),
errors: [
{
message: 'Message schema validation is only supported with default unspecified "schemaFormat".',
path: ['channels', 'users/{userId}/signedUp', property, 'message', 'schemaFormat'],
severity: DiagnosticSeverity.Information,
},
],
})),
]);