From 0e636a34f144ab97ae12ff26eaf87b66c2699dd0 Mon Sep 17 00:00:00 2001 From: Jonas Lagoni Date: Thu, 16 Nov 2023 10:54:59 -1000 Subject: [PATCH] fix: wrong parserAPI number being checked (#902) --- src/document.ts | 4 ++-- test/document.spec.ts | 8 ++++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/document.ts b/src/document.ts index b202b1c6a..76b0f257d 100644 --- a/src/document.ts +++ b/src/document.ts @@ -1,4 +1,4 @@ -import { AsyncAPIDocumentV2, AsyncAPIDocumentV3 } from './models'; +import { AsyncAPIDocumentV2, AsyncAPIDocumentV3, ParserAPIVersion } from './models'; import { unstringify } from './stringify'; import { createDetailedAsyncAPI } from './utils'; @@ -43,7 +43,7 @@ export function isAsyncAPIDocument(maybeDoc: unknown): maybeDoc is AsyncAPIDocum } if (maybeDoc && typeof (maybeDoc as AsyncAPIDocumentInterface).json === 'function') { const versionOfParserAPI = (maybeDoc as AsyncAPIDocumentInterface).json()[xParserApiVersion]; - return versionOfParserAPI === 2; + return versionOfParserAPI === ParserAPIVersion; } return false; } diff --git a/test/document.spec.ts b/test/document.spec.ts index dfa07761d..c9fb0e5c0 100644 --- a/test/document.spec.ts +++ b/test/document.spec.ts @@ -114,8 +114,12 @@ describe('utils', function() { expect(isAsyncAPIDocument(createAsyncAPIDocument(detailed))).toEqual(true); }); - it('document with the x-parser-api-version extension set to 2 should be AsyncAPI document', async function() { - expect(isAsyncAPIDocument({ json() { return { [xParserApiVersion]: 2 }; } })).toEqual(true); + it('document with the x-parser-api-version extension set to 3 should be AsyncAPI document', async function() { + expect(isAsyncAPIDocument({ json() { return { [xParserApiVersion]: 3 }; } })).toEqual(true); + }); + + it('document with the x-parser-api-version extension set to 2 should not be AsyncAPI document', async function() { + expect(isAsyncAPIDocument({ json() { return { [xParserApiVersion]: 2 }; } })).toEqual(false); }); it('document with the x-parser-api-version extension set to 1 should not be AsyncAPI document', async function() {