Skip to content

Commit

Permalink
managing other types of error instead of only validationErrors
Browse files Browse the repository at this point in the history
they are passed on error through detail field
  • Loading branch information
jotamusik committed Jan 21, 2021
1 parent 8b2bd28 commit d6330b1
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
2 changes: 1 addition & 1 deletion bin/async-validator
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const { Command } = require('commander');
const { asyncValidator } = require('../src');

const program = new Command();
program.version('1.0.2');
program.version('1.0.3');

program
.requiredOption('-f, --file <file>', 'async api definition')
Expand Down
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@jotamusik/async-validator",
"version": "1.0.2",
"version": "1.0.3",
"description": "An AsyncAPI schema validator that shows the errors on a definition",
"main": "src/index.js",
"bin": {
Expand All @@ -21,7 +21,9 @@
"asyncapi",
"validator"
],
"scripts": {},
"scripts": {
"test": "bin/async-validator -f ../netex/lcloud/asyncapi/definitionV2.yml"
},
"author": "Jorge Aguiar Martin <[email protected]>",
"repository": {
"type" : "git",
Expand Down
8 changes: 6 additions & 2 deletions src/validateAsyncAPIDefinition.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,12 @@ function validateAsyncAPIDefinition(file) {
parser.parse(apiDefinition)
.then(() => success('The definition file is correct!!'))
.catch(err => {
const errorMessages = err.validationErrors.map(e => `${e.title} ${e.location.startLine}:${e.location.startColumn}`);
errorMessages.forEach(item => error(item));
if (err.detail) {
error(err.detail);
} else {
const errorMessages = err.validationErrors.map(e => `${e.title} ${e.location.startLine}:${e.location.startColumn}`);
errorMessages.forEach(item => error(item));
}
});
}

Expand Down

0 comments on commit d6330b1

Please sign in to comment.