From a7f9fa72b80b0327fb1fca6e4ee84f9878618f4e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20Urba=C5=84czyk?= Date: Mon, 3 Oct 2022 12:39:37 +0200 Subject: [PATCH] feat(formats): add support for 2.5.0 AsyncAPI (#2292) --- docs/getting-started/3-rulesets.md | 1 + packages/formats/src/__tests__/asyncapi.test.ts | 15 ++++++++++++++- packages/formats/src/asyncapi.ts | 5 +++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/docs/getting-started/3-rulesets.md b/docs/getting-started/3-rulesets.md index babe989bb..86e195279 100644 --- a/docs/getting-started/3-rulesets.md +++ b/docs/getting-started/3-rulesets.md @@ -83,6 +83,7 @@ Formats are an optional way to specify which API description formats a rule, or - `aas2_2` (AsyncAPI v2.2.0) - `aas2_3` (AsyncAPI v2.3.0) - `aas2_4` (AsyncAPI v2.4.0) +- `aas2_5` (AsyncAPI v2.5.0) - `oas2` (OpenAPI v2.0) - `oas3` (OpenAPI v3.x) - `oas3_0` (OpenAPI v3.0.x) diff --git a/packages/formats/src/__tests__/asyncapi.test.ts b/packages/formats/src/__tests__/asyncapi.test.ts index 9e84dc790..1695b2f24 100644 --- a/packages/formats/src/__tests__/asyncapi.test.ts +++ b/packages/formats/src/__tests__/asyncapi.test.ts @@ -1,4 +1,4 @@ -import { aas2, aas2_0, aas2_1, aas2_2, aas2_3, aas2_4 } from '../asyncapi'; +import { aas2, aas2_0, aas2_1, aas2_2, aas2_3, aas2_4, aas2_5 } from '../asyncapi'; describe('AsyncAPI format', () => { describe('AsyncAPI 2.x', () => { @@ -88,4 +88,17 @@ describe('AsyncAPI format', () => { }, ); }); + + describe('AsyncAPI 2.5', () => { + it.each(['2.5.0', '2.5.2'])('recognizes %s version correctly', version => { + expect(aas2_5({ asyncapi: version }, null)).toBe(true); + }); + + it.each(['2', '2.3', '2.0.0', '2.1.0', '2.1.37', '2.2.0', '2.3.0', '2.4.0', '2.4.3', '2.6.0', '2.6.4'])( + 'does not recognize %s version', + version => { + expect(aas2_5({ asyncapi: version }, null)).toBe(false); + }, + ); + }); }); diff --git a/packages/formats/src/asyncapi.ts b/packages/formats/src/asyncapi.ts index 77b406d8d..81ab204dc 100644 --- a/packages/formats/src/asyncapi.ts +++ b/packages/formats/src/asyncapi.ts @@ -9,6 +9,7 @@ const aas2_1Regex = /^2\.1(?:\.[0-9]*)?$/; const aas2_2Regex = /^2\.2(?:\.[0-9]*)?$/; const aas2_3Regex = /^2\.3(?:\.[0-9]*)?$/; const aas2_4Regex = /^2\.4(?:\.[0-9]*)?$/; +const aas2_5Regex = /^2\.5(?:\.[0-9]*)?$/; const isAas2 = (document: unknown): document is { asyncapi: string } & Record => isPlainObject(document) && 'asyncapi' in document && aas2Regex.test(String((document as MaybeAAS2).asyncapi)); @@ -39,3 +40,7 @@ aas2_3.displayName = 'AsyncAPI 2.3.x'; export const aas2_4: Format = (document: unknown): boolean => isAas2(document) && aas2_4Regex.test(String((document as MaybeAAS2).asyncapi)); aas2_4.displayName = 'AsyncAPI 2.4.x'; + +export const aas2_5: Format = (document: unknown): boolean => + isAas2(document) && aas2_5Regex.test(String((document as MaybeAAS2).asyncapi)); +aas2_5.displayName = 'AsyncAPI 2.5.x';