Skip to content

Commit 9e6da02

Browse files
feat: validate unparsed AsyncAPI document (#720)
1 parent 8951247 commit 9e6da02

File tree

2 files changed

+96
-102
lines changed

2 files changed

+96
-102
lines changed

src/ruleset/ruleset.ts

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -53,21 +53,20 @@ export const coreRuleset = {
5353
},
5454
},
5555
},
56-
// enable after fixing https://github.com/asyncapi/spec-json-schemas/issues/296
57-
// 'asyncapi-document-unresolved': {
58-
// description: 'Checking if the AsyncAPI document has valid unresolved structure.',
59-
// message: '{{error}}',
60-
// severity: 'error',
61-
// recommended: true,
62-
// resolved: false,
63-
// given: '$',
64-
// then: {
65-
// function: documentStructure,
66-
// functionOptions: {
67-
// resolved: false,
68-
// },
69-
// },
70-
// },
56+
'asyncapi-document-unresolved': {
57+
description: 'Checking if the AsyncAPI document has valid unresolved structure.',
58+
message: '{{error}}',
59+
severity: 'error',
60+
recommended: true,
61+
resolved: false,
62+
given: '$',
63+
then: {
64+
function: documentStructure,
65+
functionOptions: {
66+
resolved: false,
67+
},
68+
},
69+
},
7170
'asyncapi-internal': {
7271
description: 'That rule is internal to extend Spectral functionality for Parser purposes.',
7372
recommended: true,
Lines changed: 82 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -1,90 +1,85 @@
1-
// import { testRule, DiagnosticSeverity } from '../tester';
1+
import { testRule, DiagnosticSeverity } from '../tester';
22

3-
describe('asyncapi-document-unresolved', () => {
4-
it.todo('add tests after fixing https://github.com/asyncapi/spec-json-schemas/issues/296');
5-
});
3+
testRule('asyncapi-document-unresolved', [
4+
{
5+
name: 'valid case',
6+
document: {
7+
asyncapi: '2.0.0',
8+
info: {
9+
title: 'Valid AsyncApi document',
10+
version: '1.0',
11+
},
12+
channels: {
13+
someChannel: {
14+
publish: {
15+
message: {
16+
$ref: '#/components/messages/someMessage',
17+
},
18+
},
19+
},
20+
},
21+
components: {
22+
messages: {
23+
someMessage: {},
24+
},
25+
},
26+
},
27+
errors: [],
28+
},
629

7-
//
8-
// testRule('asyncapi-document-unresolved', [
9-
// {
10-
// name: 'valid case',
11-
// document: {
12-
// asyncapi: '2.0.0',
13-
// info: {
14-
// title: 'Valid AsyncApi document',
15-
// version: '1.0',
16-
// },
17-
// channels: {
18-
// someChannel: {
19-
// publish: {
20-
// message: {
21-
// $ref: '#/components/messages/someMessage',
22-
// },
23-
// },
24-
// },
25-
// },
26-
// components: {
27-
// messages: {
28-
// someMessage: {},
29-
// },
30-
// },
31-
// },
32-
// errors: [],
33-
// },
30+
{
31+
name: 'invalid case (reference for operation object is not allowed)',
32+
document: {
33+
asyncapi: '2.0.0',
34+
info: {
35+
title: 'Valid AsyncApi document',
36+
version: '1.0',
37+
},
38+
channels: {
39+
someChannel: {
40+
publish: {
41+
$ref: '#/components/x-operations/someOperation',
42+
},
43+
},
44+
},
45+
components: {
46+
'x-operations': {
47+
someOperation: {},
48+
},
49+
},
50+
},
51+
errors: [
52+
{
53+
message: 'Referencing in this place is not allowed',
54+
path: ['channels', 'someChannel', 'publish'],
55+
severity: DiagnosticSeverity.Error,
56+
},
57+
],
58+
},
3459

35-
// {
36-
// name: 'invalid case (reference for operation object is not allowed)',
37-
// document: {
38-
// asyncapi: '2.0.0',
39-
// info: {
40-
// title: 'Valid AsyncApi document',
41-
// version: '1.0',
42-
// },
43-
// channels: {
44-
// someChannel: {
45-
// publish: {
46-
// $ref: '#/components/x-operations/someOperation',
47-
// },
48-
// },
49-
// },
50-
// components: {
51-
// 'x-operations': {
52-
// someOperation: {},
53-
// },
54-
// },
55-
// },
56-
// errors: [
57-
// {
58-
// message: 'Referencing in this place is not allowed',
59-
// path: ['channels', 'someChannel', 'publish'],
60-
// severity: DiagnosticSeverity.Error,
61-
// },
62-
// ],
63-
// },
64-
65-
// {
66-
// name: 'invalid case (case when other errors should also occur but we filter them out - required info field is omitted)',
67-
// document: {
68-
// asyncapi: '2.0.0',
69-
// channels: {
70-
// someChannel: {
71-
// publish: {
72-
// $ref: '#/components/x-operations/someOperation',
73-
// },
74-
// },
75-
// },
76-
// components: {
77-
// 'x-operations': {
78-
// someOperation: {},
79-
// },
80-
// },
81-
// },
82-
// errors: [
83-
// {
84-
// message: 'Referencing in this place is not allowed',
85-
// path: ['channels', 'someChannel', 'publish'],
86-
// severity: DiagnosticSeverity.Error,
87-
// },
88-
// ],
89-
// },
90-
// ]);
60+
{
61+
name: 'invalid case (case when other errors should also occur but we filter them out - required info field is omitted)',
62+
document: {
63+
asyncapi: '2.0.0',
64+
channels: {
65+
someChannel: {
66+
publish: {
67+
$ref: '#/components/x-operations/someOperation',
68+
},
69+
},
70+
},
71+
components: {
72+
'x-operations': {
73+
someOperation: {},
74+
},
75+
},
76+
},
77+
errors: [
78+
{
79+
message: 'Referencing in this place is not allowed',
80+
path: ['channels', 'someChannel', 'publish'],
81+
severity: DiagnosticSeverity.Error,
82+
},
83+
],
84+
},
85+
]);

0 commit comments

Comments
 (0)