From 8b5d6b3f91777f2370fd02eecb44f72078e55f01 Mon Sep 17 00:00:00 2001 From: Jonas Lagoni Date: Mon, 2 May 2022 22:42:09 +0200 Subject: [PATCH] feat(formats): support AsyncAPI 2.4 (#2146) --- 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 38f841ae8..99175e012 100644 --- a/docs/getting-started/3-rulesets.md +++ b/docs/getting-started/3-rulesets.md @@ -80,6 +80,7 @@ Formats are an optional way to specify which API description formats a rule, or - `aas2_1` (AsyncAPI v2.1.0) - `aas2_2` (AsyncAPI v2.2.0) - `aas2_3` (AsyncAPI v2.3.0) +- `aas2_4` (AsyncAPI v2.4.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 01e22c240..9e84dc790 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 } from '../asyncapi'; +import { aas2, aas2_0, aas2_1, aas2_2, aas2_3, aas2_4 } from '../asyncapi'; describe('AsyncAPI format', () => { describe('AsyncAPI 2.x', () => { @@ -75,4 +75,17 @@ describe('AsyncAPI format', () => { }, ); }); + + describe('AsyncAPI 2.4', () => { + it.each(['2.4.0', '2.4.3'])('recognizes %s version correctly', version => { + expect(aas2_4({ 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.5.0', '2.5.3'])( + 'does not recognize %s version', + version => { + expect(aas2_4({ asyncapi: version }, null)).toBe(false); + }, + ); + }); }); diff --git a/packages/formats/src/asyncapi.ts b/packages/formats/src/asyncapi.ts index 87312ac19..77b406d8d 100644 --- a/packages/formats/src/asyncapi.ts +++ b/packages/formats/src/asyncapi.ts @@ -8,6 +8,7 @@ const aas2_0Regex = /^2\.0(?:\.[0-9]*)?$/; 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 isAas2 = (document: unknown): document is { asyncapi: string } & Record => isPlainObject(document) && 'asyncapi' in document && aas2Regex.test(String((document as MaybeAAS2).asyncapi)); @@ -34,3 +35,7 @@ aas2_2.displayName = 'AsyncAPI 2.2.x'; export const aas2_3: Format = (document: unknown): boolean => isAas2(document) && aas2_3Regex.test(String((document as MaybeAAS2).asyncapi)); 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';