diff --git a/index.js b/index.js index 48843eb..23b130a 100644 --- a/index.js +++ b/index.js @@ -38,7 +38,8 @@ function routes(loopbackApplication, options) { options = _defaults({}, options, { resourcePath: 'swagger.json', - apiInfo: loopbackApplication.get('apiInfo') || {} + apiInfo: loopbackApplication.get('apiInfo') || {}, + swaggerUI: true }); var router = new loopback.Router(); @@ -60,26 +61,28 @@ function routes(loopbackApplication, options) { }); }); - // Allow specifying a static file roots for swagger files. Any files in - // these folders will override those in the swagger-ui distribution. - // In this way one could e.g. make changes to index.html without having - // to worry about constantly pulling in JS updates. - if (options.uiDirs) { - if (typeof options.uiDirs === 'string') { - router.use(loopback.static(options.uiDirs)); - } else if (Array.isArray(options.uiDirs)) { - options.uiDirs.forEach(function(dir) { - router.use(loopback.static(dir)); - }); + if (options.swaggerUI) { + // Allow specifying a static file roots for swagger files. Any files in + // these folders will override those in the swagger-ui distribution. + // In this way one could e.g. make changes to index.html without having + // to worry about constantly pulling in JS updates. + if (options.uiDirs) { + if (typeof options.uiDirs === 'string') { + router.use(loopback.static(options.uiDirs)); + } else if (Array.isArray(options.uiDirs)) { + options.uiDirs.forEach(function(dir) { + router.use(loopback.static(dir)); + }); + } } + + // File in node_modules are overridden by a few customizations + router.use(loopback.static(STATIC_ROOT)); + + // Swagger UI distribution + router.use(loopback.static(SWAGGER_UI_ROOT)); } - // File in node_modules are overridden by a few customizations - router.use(loopback.static(STATIC_ROOT)); - - // Swagger UI distribution - router.use(loopback.static(SWAGGER_UI_ROOT)); - return router; } diff --git a/test/explorer.test.js b/test/explorer.test.js index d35a454..c78392c 100644 --- a/test/explorer.test.js +++ b/test/explorer.test.js @@ -138,6 +138,39 @@ describe('explorer', function() { }); }); + describe('with swaggerUI option', function() { + var app; + beforeEach(function setupExplorerWithoutUI() { + app = loopback(); + explorer(app, { + swaggerUI: false + }); + }); + + it('overrides swagger-ui files', function(done) { + request(app).get('/explorer/swagger-ui.js') + .expect(404, done); + }); + + it('should serve config.json', function(done) { + request(app) + .get('/explorer/config.json') + .expect(200) + .end(function(err, res) { + if (err) return done(err); + expect(res.body).to + .have.property('url', '/explorer/swagger.json'); + done(); + }); + }); + + it('should serve swagger.json', function(done) { + request(app) + .get('/explorer/swagger.json') + .expect(200, done); + }); + }); + describe('explorer.routes API', function() { var app; beforeEach(function() {