Skip to content

Commit

Permalink
fix: wrong parserAPI number being checked (#902)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonaslagoni authored Nov 16, 2023
1 parent b3d9005 commit 0e636a3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/document.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AsyncAPIDocumentV2, AsyncAPIDocumentV3 } from './models';
import { AsyncAPIDocumentV2, AsyncAPIDocumentV3, ParserAPIVersion } from './models';
import { unstringify } from './stringify';
import { createDetailedAsyncAPI } from './utils';

Expand Down Expand Up @@ -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;
}
Expand Down
8 changes: 6 additions & 2 deletions test/document.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit 0e636a3

Please sign in to comment.