Skip to content

Commit

Permalink
Add config option to supress console warning messages
Browse files Browse the repository at this point in the history
  • Loading branch information
nazarhussain committed Aug 2, 2018
1 parent 3f5c099 commit f0e691f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
8 changes: 5 additions & 3 deletions index.js
Expand Up @@ -218,7 +218,9 @@ function Runner(appJsConfig, cb) {
if (warnings && warnings.length > 0) {
var warningText = JSON.stringify(warnings);
if (self.config.swagger.startWithWarnings) {
console.error(warningText, 2);
if(!self.config.swagger.suppressWarnings) {
console.error(warningText, 2);
}
} else {
var err = new Error('Swagger validation warnings:');
err.validationWarnings = warnings;
Expand All @@ -245,7 +247,7 @@ function Runner(appJsConfig, cb) {
console.error("\t#" + i + ".: " + err.validationErrors[i].message + " in swagger config at: >" + err.validationErrors[i].path.join('/') + "<");
}
}

process.nextTick(function() { throw err; });
})
}
Expand Down Expand Up @@ -330,4 +332,4 @@ function readEnvConfig() {
});
debug('loaded env vars: %j', config);
return config;
}
}
22 changes: 20 additions & 2 deletions test/index.js
Expand Up @@ -4,6 +4,7 @@ var should = require('should');
var path = require('path');
var _ = require('lodash');
var util = require('util');
var sinon = require('sinon');

var SwaggerRunner = require('..');

Expand Down Expand Up @@ -375,7 +376,7 @@ describe('index', function() {
});
});
});

it('should accept null body from pipe interface', function(done) {
var config = _.clone(DEFAULT_PROJECT_CONFIG);
config.configDir = path.resolve(DEFAULT_PROJECT_ROOT, "config_auto");
Expand All @@ -400,7 +401,6 @@ describe('index', function() {
});
});


it('should fail without callback', function() {
(function() { SwaggerRunner.create(DEFAULT_PROJECT_CONFIG) }).should.throw('callback is required');
});
Expand Down Expand Up @@ -445,14 +445,32 @@ describe('index', function() {

it('should continue with swagger warnings if startWithWarnings is true', function(done) {
var config = _.clone(DEFAULT_PROJECT_CONFIG);
sinon.spy(console, 'error');
config.startWithWarnings = true;
config.swagger = SWAGGER_WITH_WARNINGS;
SwaggerRunner.create(config, function(err, runner) {
should.not.exist(err);
console.error.calledOnce.should.be.true();
console.error.calledWith('[{"code":"UNUSED_DEFINITION","message":"Definition is not used: #/definitions/SomeUnusedDefinition","path":["definitions","SomeUnusedDefinition"]}]').should.be.true();
console.error.restore();
done();
});
});

it('should continue with swagger warnings and not show error in console if startWithWarnings is true and suppressWarnings is true', function(done) {
var config = _.clone(DEFAULT_PROJECT_CONFIG);
sinon.spy(console, 'error');
config.startWithWarnings = true;
config.suppressWarnings = true;
config.swagger = SWAGGER_WITH_WARNINGS;
SwaggerRunner.create(config, function(err, runner) {
should.not.exist(err);
console.error.notCalled.should.be.true();
console.error.restore();
done();
});
});

it('should allow paths using global security', function(done) {
var config = _.clone(DEFAULT_PROJECT_CONFIG);
config.startWithWarnings = true;
Expand Down

0 comments on commit f0e691f

Please sign in to comment.