Skip to content

Commit

Permalink
fix: isAsyncAPIDocument not recognizing correct documents (#861)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonaslagoni authored Oct 3, 2023
1 parent 1fa1240 commit b5684de
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/document.ts
Original file line number Diff line number Diff line change
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 === 1;
return versionOfParserAPI === 2;
}
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion src/models/asyncapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import type { ServersInterface } from './servers';
import type { v2, v3 } from '../spec-types';

// https://github.com/asyncapi/parser-api/releases/tag/v2.0.0
export const ParserAPIVersion = '2.0.0';
export const ParserAPIVersion = 2;

export interface AsyncAPIDocumentInterface extends BaseModel<v2.AsyncAPIObject | v3.AsyncAPIObject>, ExtensionsMixinInterface {
version(): string;
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 1 should be AsyncAPI document', async function() {
expect(isAsyncAPIDocument({ json() { return { [xParserApiVersion]: 1 }; } })).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 1 should not be AsyncAPI document', async function() {
expect(isAsyncAPIDocument({ json() { return { [xParserApiVersion]: 1 }; } })).toEqual(false);
});

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

0 comments on commit b5684de

Please sign in to comment.