Skip to content

Commit

Permalink
Modifiable URLs for documentation and swaggerUI
Browse files Browse the repository at this point in the history
Default would be:
swaggerUI = /docs
swaggerDocs = /api-docs
  • Loading branch information
chdanielmueller committed Jun 6, 2015
1 parent ebf2d72 commit dffb84a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 12 deletions.
4 changes: 2 additions & 2 deletions example/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ var express = require('express'),
var app = express();

swagger.init(app, {
swaggerJsonPath: '/api.json',
swaggerUiPath: '/api',
apiDocs: '/api.json',
swaggerUi: '/api',
info: {
title: 'Hello World',
version: '1.0.0'
Expand Down
17 changes: 7 additions & 10 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,6 @@ module.exports.init = function (app, options) {
if (!options) {
throw new Error('\'options\' is required.');
}
else if (!options.swaggerJsonPath) {
throw new Error('\'swaggerJsonPath\' is required.');
}
else if (!options.swaggerUiPath) {
throw new Error('\'swaggerUiPath\' is required.');
}
else if (!options.info) {
throw new Error('\'info\' is required.');
}
Expand All @@ -49,6 +43,11 @@ module.exports.init = function (app, options) {
parseApiFile(options.apis[i]);
}

var swaggerToolsUIOptions = {
apiDocs: options.apiDocs,
swaggerUi: options.swaggerUi
};

// Initialize the Swagger middleware
swaggerTools.initializeMiddleware(module.exports.swaggerObject, function (middleware) {
// Interpret Swagger resources and attach metadata to request - must be first in swagger-tools middleware chain
Expand All @@ -58,12 +57,10 @@ module.exports.init = function (app, options) {
app.use(middleware.swaggerValidator());

// Route validated requests to appropriate controller
app.use(middleware.swaggerRouter(options));
app.use(middleware.swaggerRouter());

// Serve the Swagger documents and Swagger UI
app.use(middleware.swaggerUi());


app.use(middleware.swaggerUi(swaggerToolsUIOptions));
});
};

Expand Down

0 comments on commit dffb84a

Please sign in to comment.