Merge pull request #154 from strongloop/feature/add-swaggerUI-option
Add `swaggerUI` option to enable/disable UI serving
This commit is contained in:
commit
dee0c40e11
39
index.js
39
index.js
|
@ -38,7 +38,8 @@ function routes(loopbackApplication, options) {
|
||||||
|
|
||||||
options = _defaults({}, options, {
|
options = _defaults({}, options, {
|
||||||
resourcePath: 'swagger.json',
|
resourcePath: 'swagger.json',
|
||||||
apiInfo: loopbackApplication.get('apiInfo') || {}
|
apiInfo: loopbackApplication.get('apiInfo') || {},
|
||||||
|
swaggerUI: true
|
||||||
});
|
});
|
||||||
|
|
||||||
var router = new loopback.Router();
|
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
|
if (options.swaggerUI) {
|
||||||
// these folders will override those in the swagger-ui distribution.
|
// Allow specifying a static file roots for swagger files. Any files in
|
||||||
// In this way one could e.g. make changes to index.html without having
|
// these folders will override those in the swagger-ui distribution.
|
||||||
// to worry about constantly pulling in JS updates.
|
// In this way one could e.g. make changes to index.html without having
|
||||||
if (options.uiDirs) {
|
// to worry about constantly pulling in JS updates.
|
||||||
if (typeof options.uiDirs === 'string') {
|
if (options.uiDirs) {
|
||||||
router.use(loopback.static(options.uiDirs));
|
if (typeof options.uiDirs === 'string') {
|
||||||
} else if (Array.isArray(options.uiDirs)) {
|
router.use(loopback.static(options.uiDirs));
|
||||||
options.uiDirs.forEach(function(dir) {
|
} else if (Array.isArray(options.uiDirs)) {
|
||||||
router.use(loopback.static(dir));
|
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;
|
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() {
|
describe('explorer.routes API', function() {
|
||||||
var app;
|
var app;
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
|
|
Loading…
Reference in New Issue