Skip to content

Commit 94a7801

Browse files
magicmatatjahuP0lip
authored andcommitted
feat(rulesets): support AsyncAPI 2.6.0 (#2391)
1 parent 27552a7 commit 94a7801

File tree

7 files changed

+128
-29
lines changed

7 files changed

+128
-29
lines changed

packages/rulesets/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@
2121
"release": "semantic-release -e semantic-release-monorepo"
2222
},
2323
"dependencies": {
24-
"@asyncapi/specs": "^3.2.0",
24+
"@asyncapi/specs": "^4.1.0",
2525
"@stoplight/better-ajv-errors": "1.0.3",
2626
"@stoplight/json": "^3.17.0",
2727
"@stoplight/spectral-core": "^1.8.1",
28-
"@stoplight/spectral-formats": "^1.4.0",
28+
"@stoplight/spectral-formats": "^1.5.0",
2929
"@stoplight/spectral-functions": "^1.5.1",
3030
"@stoplight/spectral-runtime": "^1.1.1",
3131
"@stoplight/types": "^13.6.0",

packages/rulesets/src/asyncapi/functions/__tests__/asyncApi2DocumentSchema.test.ts

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,116 @@ describe('asyncApi2DocumentSchema', () => {
193193
});
194194
});
195195

196+
describe('given AsyncAPI 2.4.0 document', () => {
197+
test('validate messageId on message', async () => {
198+
expect(
199+
await s.run({
200+
asyncapi: '2.4.0',
201+
info: {
202+
title: 'Signup service example (internal)',
203+
version: '0.1.0',
204+
},
205+
channels: {
206+
'/user/signedup': {
207+
subscribe: {
208+
message: {
209+
messageId: 'messageId',
210+
payload: {
211+
type: 'object',
212+
properties: {
213+
email: {
214+
type: 'string',
215+
format: 'email',
216+
},
217+
},
218+
},
219+
},
220+
},
221+
},
222+
},
223+
}),
224+
).toEqual([]);
225+
});
226+
});
227+
228+
describe('given AsyncAPI 2.5.0 document', () => {
229+
test('validate tags on server', async () => {
230+
expect(
231+
await s.run({
232+
asyncapi: '2.5.0',
233+
info: {
234+
title: 'Signup service example (internal)',
235+
version: '0.1.0',
236+
},
237+
servers: {
238+
development: {
239+
url: 'https://some-server.com/example',
240+
protocol: 'kafka',
241+
tags: [
242+
{
243+
name: 'env:production',
244+
},
245+
{
246+
name: 'e-commerce',
247+
},
248+
],
249+
},
250+
},
251+
channels: {
252+
'/user/signedup': {
253+
subscribe: {
254+
message: {
255+
messageId: 'messageId',
256+
payload: {
257+
type: 'object',
258+
properties: {
259+
email: {
260+
type: 'string',
261+
format: 'email',
262+
},
263+
},
264+
},
265+
},
266+
},
267+
},
268+
},
269+
}),
270+
).toEqual([]);
271+
});
272+
});
273+
274+
describe('given AsyncAPI 2.6.0 document', () => {
275+
test('validate valid spec', async () => {
276+
expect(
277+
await s.run({
278+
asyncapi: '2.6.0',
279+
info: {
280+
title: 'Signup service example (internal)',
281+
version: '0.1.0',
282+
},
283+
channels: {
284+
'/user/signedup': {
285+
subscribe: {
286+
message: {
287+
messageId: 'messageId',
288+
payload: {
289+
type: 'object',
290+
properties: {
291+
email: {
292+
type: 'string',
293+
format: 'email',
294+
},
295+
},
296+
},
297+
},
298+
},
299+
},
300+
},
301+
}),
302+
).toEqual([]);
303+
});
304+
});
305+
196306
describe('prepareResults', () => {
197307
test('given oneOf error one of which is required $ref property missing, picks only one error', () => {
198308
const errors: ErrorObject[] = [

packages/rulesets/src/asyncapi/functions/asyncApi2DocumentSchema.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { createRulesetFunction } from '@stoplight/spectral-core';
22
import { schema as schemaFn } from '@stoplight/spectral-functions';
3-
import { aas2_0, aas2_1, aas2_2, aas2_3, aas2_4, aas2_5 } from '@stoplight/spectral-formats';
3+
import { aas2_0, aas2_1, aas2_2, aas2_3, aas2_4, aas2_5, aas2_6 } from '@stoplight/spectral-formats';
44

55
import { getCopyOfSchema } from './utils/specs';
66

@@ -92,6 +92,8 @@ function getSerializedSchema(version: AsyncAPISpecVersion): Record<string, unkno
9292

9393
function getSchema(formats: Set<Format>): Record<string, any> | void {
9494
switch (true) {
95+
case formats.has(aas2_6):
96+
return getSerializedSchema('2.6.0');
9597
case formats.has(aas2_5):
9698
return getSerializedSchema('2.5.0');
9799
case formats.has(aas2_4):

packages/rulesets/src/asyncapi/functions/utils/specs.ts

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,7 @@
1-
// import only 2.X.X AsyncAPI JSON Schemas for better treeshaking
2-
import * as asyncAPI2_0_0Schema from '@asyncapi/specs/schemas/2.0.0.json';
3-
import * as asyncAPI2_1_0Schema from '@asyncapi/specs/schemas/2.1.0.json';
4-
import * as asyncAPI2_2_0Schema from '@asyncapi/specs/schemas/2.2.0.json';
5-
import * as asyncAPI2_3_0Schema from '@asyncapi/specs/schemas/2.3.0.json';
6-
import * as asyncAPI2_4_0Schema from '@asyncapi/specs/schemas/2.4.0.json';
7-
import * as asyncAPI2_5_0Schema from '@asyncapi/specs/schemas/2.5.0.json';
1+
import specs from '@asyncapi/specs';
82

93
export type AsyncAPISpecVersion = keyof typeof specs;
104

11-
export const specs = {
12-
'2.0.0': asyncAPI2_0_0Schema,
13-
'2.1.0': asyncAPI2_1_0Schema,
14-
'2.2.0': asyncAPI2_2_0Schema,
15-
'2.3.0': asyncAPI2_3_0Schema,
16-
'2.4.0': asyncAPI2_4_0Schema,
17-
'2.5.0': asyncAPI2_5_0Schema,
18-
};
19-
205
const versions = Object.keys(specs);
216
export const latestVersion = versions[versions.length - 1];
227

packages/rulesets/src/asyncapi/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { aas2_0, aas2_1, aas2_2, aas2_3, aas2_4, aas2_5 } from '@stoplight/spectral-formats';
1+
import { aas2_0, aas2_1, aas2_2, aas2_3, aas2_4, aas2_5, aas2_6 } from '@stoplight/spectral-formats';
22
import {
33
truthy,
44
pattern,
@@ -23,7 +23,7 @@ import { latestVersion } from './functions/utils/specs';
2323

2424
export default {
2525
documentationUrl: 'https://meta.stoplight.io/docs/spectral/docs/reference/asyncapi-rules.md',
26-
formats: [aas2_0, aas2_1, aas2_2, aas2_3, aas2_4, aas2_5],
26+
formats: [aas2_0, aas2_1, aas2_2, aas2_3, aas2_4, aas2_5, aas2_6],
2727
rules: {
2828
'asyncapi-channel-no-empty-parameter': {
2929
description: 'Channel path must not have empty parameter substitution pattern.',

test-harness/scenarios/asyncapi2-streetlights.scenario

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ module.exports = asyncapi;
218218
====stdout====
219219
{document}
220220
1:1 warning asyncapi-tags AsyncAPI object must have non-empty "tags" array.
221-
1:11 information asyncapi-latest-version The latest version is not used. You should update to the "2.5.0" version. asyncapi
221+
1:11 information asyncapi-latest-version The latest version is not used. You should update to the "2.6.0" version. asyncapi
222222
2:6 warning asyncapi-info-contact Info object must have "contact" object. info
223223
45:13 warning asyncapi-operation-description Operation "description" must be present and non-empty string. channels.smartylighting/streetlights/1/0/event/{streetlightId}/lighting/measured.publish
224224
57:15 warning asyncapi-operation-description Operation "description" must be present and non-empty string. channels.smartylighting/streetlights/1/0/action/{streetlightId}/turn/on.subscribe

yarn.lock

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,12 @@ __metadata:
2727
languageName: node
2828
linkType: hard
2929

30-
"@asyncapi/specs@npm:^3.2.0":
31-
version: 3.2.1
32-
resolution: "@asyncapi/specs@npm:3.2.1"
33-
checksum: 6392d0aaa658905f67553160c725bb0b535e187a120fb2305eb1a223460244a43eea804c00f4985ecbaddb2b04527ce9db51e72117dbe694db547b734f8082dd
30+
"@asyncapi/specs@npm:^4.1.0":
31+
version: 4.1.0
32+
resolution: "@asyncapi/specs@npm:4.1.0"
33+
dependencies:
34+
"@types/json-schema": ^7.0.11
35+
checksum: 6e95f3c1ef7267480cdfc69f5a015f63b9101874289e31843a629346a3ea07490e3043b296a089bf3458e877c664d83d4b4738dcb53d37d7e13b75c7bc08c879
3436
languageName: node
3537
linkType: hard
3638

@@ -2566,7 +2568,7 @@ __metadata:
25662568
languageName: unknown
25672569
linkType: soft
25682570

2569-
"@stoplight/spectral-formats@*, @stoplight/spectral-formats@>=1, @stoplight/spectral-formats@^1.0.0, @stoplight/spectral-formats@^1.4.0, @stoplight/spectral-formats@workspace:packages/formats":
2571+
"@stoplight/spectral-formats@*, @stoplight/spectral-formats@>=1, @stoplight/spectral-formats@^1.0.0, @stoplight/spectral-formats@^1.5.0, @stoplight/spectral-formats@workspace:packages/formats":
25702572
version: 0.0.0-use.local
25712573
resolution: "@stoplight/spectral-formats@workspace:packages/formats"
25722574
dependencies:
@@ -2677,12 +2679,12 @@ __metadata:
26772679
version: 0.0.0-use.local
26782680
resolution: "@stoplight/spectral-rulesets@workspace:packages/rulesets"
26792681
dependencies:
2680-
"@asyncapi/specs": ^3.2.0
2682+
"@asyncapi/specs": ^4.1.0
26812683
"@stoplight/better-ajv-errors": 1.0.3
26822684
"@stoplight/json": ^3.17.0
26832685
"@stoplight/path": ^1.3.2
26842686
"@stoplight/spectral-core": ^1.8.1
2685-
"@stoplight/spectral-formats": ^1.4.0
2687+
"@stoplight/spectral-formats": ^1.5.0
26862688
"@stoplight/spectral-functions": ^1.5.1
26872689
"@stoplight/spectral-parsers": "*"
26882690
"@stoplight/spectral-ref-resolver": "*"

0 commit comments

Comments
 (0)