Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,12 @@ function mountSwagger(loopbackApplication, swaggerApp, opts) {
swaggerObject = createSwaggerObject(loopbackApplication, opts);
});

// listening to remoteMethodDisabled event for updating the swaggerObject
// when a remote method is disabled to hide that method in the Swagger UI.
loopbackApplication.on('remoteMethodDisabled', function() {
swaggerObject = createSwaggerObject(loopbackApplication, opts);
});

var resourcePath = opts && opts.resourcePath || 'swagger.json';
if (resourcePath[0] !== '/') resourcePath = '/' + resourcePath;

Expand Down
31 changes: 31 additions & 0 deletions test/explorer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,37 @@ describe('explorer', function() {
});
});

it('updates swagger object when a remote method is disabled', function(done) {
var app = loopback();
configureRestApiAndExplorer(app, '/explorer');

// Ensure the swagger object was built
request(app)
.get('/explorer/swagger.json')
.expect(200)
.end(function(err, res) {
if (err) return done(err);

// Check the method that will be disabled
var paths = Object.keys(res.body.paths);
expect(paths).to.contain('/products/findOne');

var Product = app.models.Product;
Product.disableRemoteMethod('findOne', true);

// Request swagger.json again
request(app)
.get('/explorer/swagger.json')
.expect(200)
.end(function(err, res) {
if (err) return done(err);
var paths = Object.keys(res.body.paths);
expect(paths).to.not.contain('/products/findOne');
done();
});
});
});

function givenLoopBackAppWithExplorer(explorerBase) {
return function(done) {
var app = this.app = loopback();
Expand Down