Add `swaggerUI` option to enable/disable UI serving
This commit is contained in:
parent
9192ee638b
commit
63f446511d
39
index.js
39
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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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() {
|
||||
|
|
Loading…
Reference in New Issue