From d6330b19e22c32aeab6ad991d1fb3b5fad41d424 Mon Sep 17 00:00:00 2001 From: Jorge Aguiar Martin Date: Thu, 21 Jan 2021 18:24:18 +0000 Subject: [PATCH] managing other types of error instead of only validationErrors they are passed on error through detail field --- bin/async-validator | 2 +- package.json | 6 ++++-- src/validateAsyncAPIDefinition.js | 8 ++++++-- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/bin/async-validator b/bin/async-validator index c940901..ad1a1dd 100755 --- a/bin/async-validator +++ b/bin/async-validator @@ -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 ', 'async api definition') diff --git a/package.json b/package.json index ed2124e..384b284 100644 --- a/package.json +++ b/package.json @@ -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": { @@ -21,7 +21,9 @@ "asyncapi", "validator" ], - "scripts": {}, + "scripts": { + "test": "bin/async-validator -f ../netex/lcloud/asyncapi/definitionV2.yml" + }, "author": "Jorge Aguiar Martin ", "repository": { "type" : "git", diff --git a/src/validateAsyncAPIDefinition.js b/src/validateAsyncAPIDefinition.js index 04a0024..fe02523 100644 --- a/src/validateAsyncAPIDefinition.js +++ b/src/validateAsyncAPIDefinition.js @@ -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)); + } }); }