Skip to content
Closed
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 @@ -95,6 +95,12 @@ function routes(loopbackApplication, options) {
function mountSwagger(loopbackApplication, swaggerApp, opts) {
var swaggerObject = createSwaggerObject(loopbackApplication, opts);

//listening to modelRemoted event for updating the swaggerObject
// with the newly created model to appear in the Swagger UI.
loopbackApplication.on('modelRemoted', function() {
swaggerObject = createSwaggerObject(loopbackApplication, opts);
});

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

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

describe('when creating/adding new models', function() {
var app = loopback();
it('should allow setting up swagger explorer', function(done) {
configureRestApiAndExplorer(app, '/explorer');

request(app)
.get('/explorer/swagger.json')
.expect(200)
.end(done);
});

it('should show newly created model', function(done) {
var modelName = 'Customer';
var Model = loopback.PersistedModel.extend(modelName);
Model.attachTo(loopback.memory());
app.model(Model);

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.indexOf('/'+modelName+'s')).to.not.equal(-1);
done();
});
});
});

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