Swagger Node with custom UI document path

224 views
Skip to first unread message

linchun huang

unread,
May 18, 2016, 2:18:29 AM5/18/16
to Swagger
Hello,

I am using swagger node to build my REST server, it seems by default the swagger UI web page will be displayed 

under the url of  /docs.

Instead of configuring the root path, is there any way to change this path to any value? (For example /myrest/v1/api-docs)

Thank you!

tony tam

unread,
May 18, 2016, 7:28:40 AM5/18/16
to swagger-sw...@googlegroups.com
Looks like the UI is loaded via the swagger-tools dependency, which has a configuration for the location of the route.  I’d suggest looking in there

--
You received this message because you are subscribed to the Google Groups "Swagger" group.
To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggers...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

linchun huang

unread,
May 23, 2016, 3:50:09 AM5/23/16
to Swagger
Thanks Tony! I have found the way to configure swagger-ui middleware here !

 

tony tam

unread,
May 23, 2016, 11:30:34 AM5/23/16
to swagger-sw...@googlegroups.com
Great—do you mind sharing the full solution so others can see?

On May 23, 2016, at 12:50 AM, linchun huang <vcsh...@gmail.com> wrote:

Thanks Tony! I have found the way to configure swagger-ui middleware here !

 

linchun huang

unread,
May 24, 2016, 10:51:34 PM5/24/16
to Swagger
If you are using Swagger2.0, you can pass options as the second parameter into the constructor of the swagger-ui middleware.

For now the swagger-ui and api-doc are the two options that I am concerned about, other options can be referenced here!

var SwaggerExpress = require('swagger-express-mw');
var SwaggerUi = require('swagger-tools/middleware/swagger-ui');
var app = require('express')();

...

SwaggerExpress.create(config, function(err, swaggerExpress) {

var option = {

swaggerUi:"/any_path_you_want",//swagger ui web page
apiDocs:"/any_path_you_want"//api document in json format
};

app.use(SwaggerUi(swaggerExpress.runner.swagger, option));

// install middleware
swaggerExpress.register(app);

...

});

Hope this help!
Reply all
Reply to author
Forward
0 new messages