Skip to main content

Command Palette

Search for a command to run...

setup multiple swagger url in node js application

Updated
2 min read
A

Self taught developer working on Angular, Vue, Typescript, Node JS, MongoDB, Express JS, LoopBack API, Laravel, Laravel Lumen, mysql. write packages for angular/vue. Part time youtuber

When we start work on some type of large application and we are going to setup swagger in our application in this case we require different endpoints in our swagger to look each end point in a better way. Like we have user/mobiles and some other endpoints in our application in this case we can setup our swagger with different url's for different end points.

Please refer below video to understand how we can setup a swagger in node/express js application:

app.use('/usersswagger', swaggerUi.serve, swaggerUi.setup(swaggerUsersConfig));

above code will work fine in case we need single swagger url in our application and we will display all the data in the same page.

Note: above code only work for single swagger route. in case you will pass two different routes and config in the two statements like this.

app.use('/usersswagger', swaggerUi.serve, swaggerUi.setup(swaggerUsersConfig));
app.use('/mobilesswagger', swaggerUi.serve, swaggerUi.setup(swaggerMobilesConfig));

above code will create a single reference of both of the statements and we will see the same contents in both of the swagger url.

in case we want different swagger routes in our application like for user it will be /usersswagger and for mobile end point it will be /mobilesswagger. we will have to follow below code it will create different reference of our configuration we are passing swaggerUsersConfig and swaggerMobilesConfig in the setup method and we will be able to see the different content in our swagger url.

app.use("/usersswagger", swaggerUi.serve, (...args) => swaggerUi.setup(swaggerUsersConfig)(...args));
app.use("/mobilesswagger", swaggerUi.serve, (...args) => swaggerUi.setup(swaggerMobilesConfig)(...args));

More from this blog

Angular, TypeScript, Vue, Node JS, Express JS, MongoDB, MongoDB Cloud, PHP, Laravel, Slim Framework, Mysql, JavaScript, PWA

24 posts

I'm a Full Stack Developer, Open Source Contributor, Blogger, npm packages developer, Youtuber. My hobbies are Contribution in open source projects, blogging, develop npm packages, part time youtuber