Add `swaggerUI` option to enable/disable UI serving
This commit is contained in:
parent
9192ee638b
commit
63f446511d
5
index.js
5
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,6 +61,7 @@ function routes(loopbackApplication, options) {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (options.swaggerUI) {
|
||||||
// Allow specifying a static file roots for swagger files. Any files in
|
// Allow specifying a static file roots for swagger files. Any files in
|
||||||
// these folders will override those in the swagger-ui distribution.
|
// these folders will override those in the swagger-ui distribution.
|
||||||
// In this way one could e.g. make changes to index.html without having
|
// In this way one could e.g. make changes to index.html without having
|
||||||
|
@ -79,6 +81,7 @@ function routes(loopbackApplication, options) {
|
||||||
|
|
||||||
// Swagger UI distribution
|
// Swagger UI distribution
|
||||||
router.use(loopback.static(SWAGGER_UI_ROOT));
|
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