Skip to content

Commit 2dbe838

Browse files
committed
feat(apidom-ls): add asyncapi channels and servers rules
1 parent 337f118 commit 2dbe838

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+1429
-35
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import ApilintCodes from '../../../codes';
2+
import { LinterMeta } from '../../../../apidom-language-types';
3+
4+
const channelsMembersLint: LinterMeta = {
5+
code: ApilintCodes.CHANNELS_CHANNEL_MEMBERS,
6+
source: 'apilint',
7+
message: 'channels members must be of type `channel`',
8+
severity: 1,
9+
linterFunction: 'apilintChildrenOfElementsOrClasess',
10+
linterParams: ['channelItem'],
11+
marker: 'key',
12+
markerTarget: 'channels',
13+
target: 'channels',
14+
data: {},
15+
};
16+
17+
export default channelsMembersLint;

packages/apidom-ls/src/config/asyncapi/asyncapi2/lint/lints.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ import componentsObjectLint from './components-object';
1010
import tagsObjectLint from './tags-object';
1111
import externaldocsObjectLint from './externaldocs-object';
1212
import rootDefaultContentTypeLint from './defaultcontenttype';
13+
import serversLint from './servers';
14+
import serversKeyLint from './servers-key';
15+
import channelsMembersLint from './channels-members';
1316

1417
const asyncapiRootLints = [
1518
rootIdLint,
@@ -24,6 +27,9 @@ const asyncapiRootLints = [
2427
tagsObjectLint,
2528
externaldocsObjectLint,
2629
rootDefaultContentTypeLint,
30+
serversLint,
31+
serversKeyLint,
32+
channelsMembersLint,
2733
];
2834

2935
export default asyncapiRootLints;
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import ApilintCodes from '../../../codes';
2+
import { LinterMeta } from '../../../../apidom-language-types';
3+
4+
const serversKeyLint: LinterMeta = {
5+
code: ApilintCodes.SERVERS_KEYS,
6+
source: 'apilint',
7+
message: 'servers keys must be valid regex',
8+
severity: 1,
9+
linterFunction: 'apilintKeyIsRegex',
10+
marker: 'key',
11+
target: 'servers',
12+
markerTarget: 'servers',
13+
data: {},
14+
};
15+
16+
export default serversKeyLint;
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import ApilintCodes from '../../../codes';
2+
import { LinterMeta } from '../../../../apidom-language-types';
3+
4+
const serversLint: LinterMeta = {
5+
code: ApilintCodes.SERVERS_SERVER_MEMBERS,
6+
source: 'apilint',
7+
message: 'servers members must be of type `server`',
8+
severity: 1,
9+
linterFunction: 'apilintChildrenOfElementsOrClasess',
10+
linterParams: ['server'],
11+
marker: 'key',
12+
markerTarget: 'servers',
13+
target: 'servers',
14+
data: {},
15+
};
16+
17+
export default serversLint;
Lines changed: 243 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,243 @@
1+
import {
2+
ApidomCompletionItem,
3+
CompletionFormat,
4+
CompletionType,
5+
} from '../../../../apidom-language-types';
6+
7+
const channelCompleteJson: ApidomCompletionItem[] = [
8+
{
9+
label: '$ref',
10+
insertText: '\\$ref',
11+
kind: 14,
12+
format: CompletionFormat.QUOTED,
13+
type: CompletionType.PROPERTY,
14+
insertTextFormat: 2,
15+
documentation: {
16+
kind: 'markdown',
17+
value:
18+
"Allows for an external definition of this channel item.\n\n ---- \n\nThe referenced structure **MUST** be in the format of a [Channel Item Object](https://www.asyncapi.com/docs/specifications/v2.2.0#channelItemObject). \n\n ---- \n\nIf there are conflicts between the referenced definition and this Channel Item's definition, the behavior is _undefined_.",
19+
},
20+
},
21+
{
22+
label: 'description',
23+
insertText: 'description',
24+
kind: 14,
25+
format: CompletionFormat.QUOTED,
26+
type: CompletionType.PROPERTY,
27+
insertTextFormat: 2,
28+
documentation: {
29+
kind: 'markdown',
30+
value:
31+
'An optional description of this channel item. [CommonMark syntax](https://spec.commonmark.org/) can be used for rich text representation.',
32+
},
33+
},
34+
{
35+
label: 'servers',
36+
insertText: 'servers',
37+
kind: 14,
38+
format: CompletionFormat.ARRAY,
39+
type: CompletionType.PROPERTY,
40+
insertTextFormat: 2,
41+
documentation: {
42+
kind: 'markdown',
43+
value:
44+
'The servers on which this channel is available, specified as an optional unordered list of names (string keys) of [Server Objects](https://www.asyncapi.com/docs/specifications/v2.2.0#serverObject) defined in the [Servers Object](https://www.asyncapi.com/docs/specifications/v2.2.0#serversObject) (a map). If `servers` is absent or empty then this channel must be available on all servers defined in the [Servers Object](https://www.asyncapi.com/docs/specifications/v2.2.0#serversObject).',
45+
},
46+
},
47+
{
48+
label: 'subscribe',
49+
insertText: 'subscribe',
50+
kind: 14,
51+
format: CompletionFormat.OBJECT,
52+
type: CompletionType.PROPERTY,
53+
insertTextFormat: 2,
54+
documentation: {
55+
kind: 'markdown',
56+
value:
57+
'[Operation Object](https://www.asyncapi.com/docs/specifications/v2.2.0#operationObject)\n\n ---- \n\nA definition of the SUBSCRIBE operation, which defines the messages produced by the application and sent to the channel.',
58+
},
59+
},
60+
{
61+
label: 'parameters',
62+
insertText: 'parameters',
63+
kind: 14,
64+
format: CompletionFormat.OBJECT,
65+
type: CompletionType.PROPERTY,
66+
insertTextFormat: 2,
67+
documentation: {
68+
kind: 'markdown',
69+
value:
70+
'[Parameters Object](https://www.asyncapi.com/docs/specifications/v2.2.0#parametersObject)\n\n ---- \n\nA map of the parameters included in the channel name. It **SHOULD** be present only when using channels with expressions (as defined by [RFC 6570 section 2.2](https://tools.ietf.org/html/rfc6570#section-2.2)).',
71+
},
72+
},
73+
{
74+
label: 'bindings',
75+
insertText: 'bindings',
76+
kind: 14,
77+
format: CompletionFormat.OBJECT,
78+
type: CompletionType.PROPERTY,
79+
insertTextFormat: 2,
80+
documentation: {
81+
kind: 'markdown',
82+
value:
83+
'[Channel Bindings Object](https://www.asyncapi.com/docs/specifications/v2.2.0#channelBindingsObject) | [Reference Object](https://www.asyncapi.com/docs/specifications/v2.2.0#referenceObject)\n\n ---- \n\nA map where the keys describe the name of the protocol and the values describe protocol-specific definitions for the channel.\n\n ---- \n\nThis object can be extended with [Specification Extensions](https://www.asyncapi.com/docs/specifications/v2.2.0#specificationExtensions).',
84+
},
85+
},
86+
{
87+
target: 'servers',
88+
label: 'servers',
89+
insertText: '?',
90+
arrayMember: true,
91+
kind: 12,
92+
format: CompletionFormat.UNQUOTED,
93+
type: CompletionType.VALUE,
94+
function: 'apicompleteChannelServers',
95+
insertTextFormat: 2,
96+
},
97+
{
98+
target: 'bindings',
99+
label: 'amqp',
100+
insertText: 'amqp',
101+
kind: 12,
102+
format: CompletionFormat.OBJECT,
103+
type: CompletionType.PROPERTY,
104+
insertTextFormat: 2,
105+
},
106+
{
107+
target: 'bindings',
108+
label: 'amqps',
109+
insertText: 'amqps',
110+
kind: 12,
111+
format: CompletionFormat.OBJECT,
112+
type: CompletionType.PROPERTY,
113+
insertTextFormat: 2,
114+
},
115+
{
116+
target: 'bindings',
117+
label: 'http',
118+
insertText: 'http',
119+
kind: 12,
120+
format: CompletionFormat.OBJECT,
121+
type: CompletionType.PROPERTY,
122+
insertTextFormat: 2,
123+
},
124+
{
125+
target: 'bindings',
126+
label: 'https',
127+
insertText: 'https',
128+
kind: 12,
129+
format: CompletionFormat.OBJECT,
130+
type: CompletionType.PROPERTY,
131+
insertTextFormat: 2,
132+
},
133+
{
134+
target: 'bindings',
135+
label: 'ibmmq',
136+
insertText: 'ibmmq',
137+
kind: 12,
138+
format: CompletionFormat.OBJECT,
139+
type: CompletionType.PROPERTY,
140+
insertTextFormat: 2,
141+
},
142+
{
143+
target: 'bindings',
144+
label: 'jms',
145+
insertText: 'jms',
146+
kind: 12,
147+
format: CompletionFormat.OBJECT,
148+
type: CompletionType.PROPERTY,
149+
insertTextFormat: 2,
150+
},
151+
{
152+
target: 'bindings',
153+
label: 'kafka',
154+
insertText: 'kafka',
155+
kind: 12,
156+
format: CompletionFormat.OBJECT,
157+
type: CompletionType.PROPERTY,
158+
insertTextFormat: 2,
159+
},
160+
{
161+
target: 'bindings',
162+
label: 'kafka-secure',
163+
insertText: 'kafka-secure',
164+
kind: 12,
165+
format: CompletionFormat.OBJECT,
166+
type: CompletionType.PROPERTY,
167+
insertTextFormat: 2,
168+
},
169+
{
170+
target: 'bindings',
171+
label: 'anypointmq',
172+
insertText: 'anypointmq',
173+
kind: 12,
174+
format: CompletionFormat.OBJECT,
175+
type: CompletionType.PROPERTY,
176+
insertTextFormat: 2,
177+
},
178+
{
179+
target: 'bindings',
180+
label: 'mqtt',
181+
insertText: 'mqtt',
182+
kind: 12,
183+
format: CompletionFormat.OBJECT,
184+
type: CompletionType.PROPERTY,
185+
insertTextFormat: 2,
186+
},
187+
{
188+
target: 'bindings',
189+
label: 'secure-mqtt',
190+
insertText: 'secure-mqtt',
191+
kind: 12,
192+
format: CompletionFormat.OBJECT,
193+
type: CompletionType.PROPERTY,
194+
insertTextFormat: 2,
195+
},
196+
{
197+
target: 'bindings',
198+
label: 'stomp',
199+
insertText: 'stomp',
200+
kind: 12,
201+
format: CompletionFormat.OBJECT,
202+
type: CompletionType.PROPERTY,
203+
insertTextFormat: 2,
204+
},
205+
{
206+
target: 'bindings',
207+
label: 'stomps',
208+
insertText: 'stomps',
209+
kind: 12,
210+
format: CompletionFormat.OBJECT,
211+
type: CompletionType.PROPERTY,
212+
insertTextFormat: 2,
213+
},
214+
{
215+
target: 'bindings',
216+
label: 'ws',
217+
insertText: 'ws',
218+
kind: 12,
219+
format: CompletionFormat.OBJECT,
220+
type: CompletionType.PROPERTY,
221+
insertTextFormat: 2,
222+
},
223+
{
224+
target: 'bindings',
225+
label: 'wss',
226+
insertText: 'wss',
227+
kind: 12,
228+
format: CompletionFormat.OBJECT,
229+
type: CompletionType.PROPERTY,
230+
insertTextFormat: 2,
231+
},
232+
{
233+
target: 'bindings',
234+
label: 'mercure',
235+
insertText: 'mercure',
236+
kind: 12,
237+
format: CompletionFormat.OBJECT,
238+
type: CompletionType.PROPERTY,
239+
insertTextFormat: 2,
240+
},
241+
];
242+
243+
export default channelCompleteJson;
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
const channelDocs = [
2+
{
3+
target: '$ref',
4+
docs: "Allows for an external definition of this channel item.\n\n ---- \n\nThe referenced structure **MUST** be in the format of a [Channel Item Object](https://www.asyncapi.com/docs/specifications/v2.2.0#channelItemObject). \n\n ---- \n\nIf there are conflicts between the referenced definition and this Channel Item's definition, the behavior is _undefined_.",
5+
},
6+
{
7+
target: 'description',
8+
docs: 'An optional description of this channel item. [CommonMark syntax](https://spec.commonmark.org/) can be used for rich text representation.',
9+
},
10+
{
11+
target: 'servers',
12+
docs: 'The servers on which this channel is available, specified as an optional unordered list of names (string keys) of [Server Objects](https://www.asyncapi.com/docs/specifications/v2.2.0#serverObject) defined in the [Servers Object](https://www.asyncapi.com/docs/specifications/v2.2.0#serversObject) (a map). If `servers` is absent or empty then this channel must be available on all servers defined in the [Servers Object](https://www.asyncapi.com/docs/specifications/v2.2.0#serversObject).',
13+
},
14+
{
15+
target: 'subscribe',
16+
docs: '[Operation Object](https://www.asyncapi.com/docs/specifications/v2.2.0#operationObject)\n\n ---- \n\nA definition of the SUBSCRIBE operation, which defines the messages produced by the application and sent to the channel.',
17+
},
18+
{
19+
target: 'publish',
20+
docs: '[Operation Object](https://www.asyncapi.com/docs/specifications/v2.2.0#operationObject)\n\n ---- \n\nA definition of the PUBLISH operation, which defines the messages consumed by the application from the channel.',
21+
},
22+
{
23+
target: 'parameters',
24+
docs: '[Parameters Object](https://www.asyncapi.com/docs/specifications/v2.2.0#parametersObject)\n\n ---- \n\nA map of the parameters included in the channel name. It **SHOULD** be present only when using channels with expressions (as defined by [RFC 6570 section 2.2](https://tools.ietf.org/html/rfc6570#section-2.2)).',
25+
},
26+
{
27+
target: 'bindings',
28+
docs: '[Channel Bindings Object](https://www.asyncapi.com/docs/specifications/v2.2.0#channelBindingsObject) | [Reference Object](https://www.asyncapi.com/docs/specifications/v2.2.0#referenceObject)\n\n ---- \n\nA map where the keys describe the name of the protocol and the values describe protocol-specific definitions for the channel.\n\n ---- \n\nThis object can be extended with [Specification Extensions](https://www.asyncapi.com/docs/specifications/v2.2.0#specificationExtensions).',
29+
},
30+
{
31+
docs: 'Describes the operations available on a single channel.\n\n ---- \n\nThis object can be extended with [Specification Extensions](https://www.asyncapi.com/docs/specifications/v2.2.0#specificationExtensions).',
32+
},
33+
];
34+
export default channelDocs;
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import ApilintCodes from '../../../codes';
2+
import { LinterMeta } from '../../../../apidom-language-types';
3+
4+
const channelBindingsLint: LinterMeta = {
5+
code: ApilintCodes.CHANNEL_BINDINGS,
6+
source: 'apilint',
7+
message: 'bindings members must be binding objects',
8+
severity: 1,
9+
linterFunction: 'apilintChildrenOfElementsOrClasess',
10+
linterParams: ['channel-binding'],
11+
marker: 'key',
12+
markerTarget: 'bindings',
13+
target: 'bindings',
14+
data: {},
15+
};
16+
17+
export default channelBindingsLint;
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import ApilintCodes from '../../../codes';
2+
import { LinterMeta } from '../../../../apidom-language-types';
3+
4+
const channelDescriptionLint: LinterMeta = {
5+
code: ApilintCodes.CHANNEL_DESCRIPTION,
6+
source: 'apilint',
7+
message: "description' value must be a string",
8+
severity: 1,
9+
linterFunction: 'apilintType',
10+
linterParams: ['string'],
11+
marker: 'value',
12+
target: 'description',
13+
data: {},
14+
};
15+
16+
export default channelDescriptionLint;

0 commit comments

Comments
 (0)