Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix parse errors #15

Merged
merged 1 commit into from
Aug 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ class ParserError extends Error {
}
}

module.exports.ParserError = ParserError;
module.exports.ParserError = ParserError;
2 changes: 1 addition & 1 deletion lib/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ async function parse(asyncapiYAMLorJSON, options = {}) {

await iterateDocument(js, options);
} catch (e) {
throw new ParserError(e);
throw new ParserError(e, e.errors);
}

return new AsyncAPIDocument(js);
Expand Down
30 changes: 30 additions & 0 deletions test/parse_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,36 @@ describe('parse()', function () {
await expect(JSON.stringify(result.json())).to.equal(outputJSON);
});

it('should forward ajv errors', async function () {
try {
await parser.parse({"asyncapi": "unstable", "info": {}});
} catch(e) {
const errors = [{
keyword: 'required',
dataPath: '.info',
schemaPath: '#/required',
params: { missingProperty: 'title' },
message: 'should have required property \'title\''
},
{
keyword: 'required',
dataPath: '.info',
schemaPath: '#/required',
params: { missingProperty: 'version' },
message: 'should have required property \'version\''
},
{
keyword: 'required',
dataPath: '',
schemaPath: '#/required',
params: { missingProperty: 'channels' },
message: 'should have required property \'channels\''
}];

await expect(e.errors).to.deep.equal(errors);
}
});

it('should not apply traits', async function () {
const result = await parser.parse(inputYAML, { path: __filename, applyTraits: false });
await expect(JSON.stringify(result.json())).to.equal(outputJsonNoApplyTraits);
Expand Down