Skip to content

Commit

Permalink
fix problem with incorrect input
Browse files Browse the repository at this point in the history
  • Loading branch information
jonaslagoni committed Sep 27, 2023
1 parent 7b08e8d commit 3dcc17a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ class Generator {
// eslint-disable-next-line sonarjs/cognitive-complexity
async generate(asyncapiDocument, parseOptions = {}) {
const isAlreadyParsedDocument = isAsyncAPIDocument(asyncapiDocument);
const isParsableCompatible = asyncapiDocument || typeof asyncapiString === 'string';
const isParsableCompatible = asyncapiDocument && typeof asyncapiDocument === 'string';
if (!isAlreadyParsedDocument && !isParsableCompatible) {
throw new Error('Parameter "asyncapiDocument" must be a non-empty string or an already parsed AsyncAPI document.');
}
Expand Down
5 changes: 5 additions & 0 deletions test/generator.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,11 @@ describe('Generator', () => {
expect(templateConfigValidator.validateTemplateConfig).toHaveBeenCalled();
expect(gen.launchHook).toHaveBeenCalledWith('generate:after');
});

it('fails if input is not a string nor a parsed AsyncAPI document', async () => {
const gen = new Generator('testTemplate', __dirname);
expect(() => gen.generate(1)).rejects.toThrow('Parameter "asyncapiDocument" must be a non-empty string or an already parsed AsyncAPI document');
});
});

describe('#generateFromString', () => {
Expand Down

0 comments on commit 3dcc17a

Please sign in to comment.