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() {