Skip to content

Commit 0e636a3

Browse files
authored
fix: wrong parserAPI number being checked (#902)
1 parent b3d9005 commit 0e636a3

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

src/document.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { AsyncAPIDocumentV2, AsyncAPIDocumentV3 } from './models';
1+
import { AsyncAPIDocumentV2, AsyncAPIDocumentV3, ParserAPIVersion } from './models';
22
import { unstringify } from './stringify';
33
import { createDetailedAsyncAPI } from './utils';
44

@@ -43,7 +43,7 @@ export function isAsyncAPIDocument(maybeDoc: unknown): maybeDoc is AsyncAPIDocum
4343
}
4444
if (maybeDoc && typeof (maybeDoc as AsyncAPIDocumentInterface).json === 'function') {
4545
const versionOfParserAPI = (maybeDoc as AsyncAPIDocumentInterface).json()[xParserApiVersion];
46-
return versionOfParserAPI === 2;
46+
return versionOfParserAPI === ParserAPIVersion;
4747
}
4848
return false;
4949
}

test/document.spec.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,12 @@ describe('utils', function() {
114114
expect(isAsyncAPIDocument(createAsyncAPIDocument(detailed))).toEqual(true);
115115
});
116116

117-
it('document with the x-parser-api-version extension set to 2 should be AsyncAPI document', async function() {
118-
expect(isAsyncAPIDocument({ json() { return { [xParserApiVersion]: 2 }; } })).toEqual(true);
117+
it('document with the x-parser-api-version extension set to 3 should be AsyncAPI document', async function() {
118+
expect(isAsyncAPIDocument({ json() { return { [xParserApiVersion]: 3 }; } })).toEqual(true);
119+
});
120+
121+
it('document with the x-parser-api-version extension set to 2 should not be AsyncAPI document', async function() {
122+
expect(isAsyncAPIDocument({ json() { return { [xParserApiVersion]: 2 }; } })).toEqual(false);
119123
});
120124

121125
it('document with the x-parser-api-version extension set to 1 should not be AsyncAPI document', async function() {

0 commit comments

Comments
 (0)