I have configured swagger for my existing application which is implemented using express nodeJS.
server.js
placed in the root folder and API's(*.js
files) inside some other directories like
In the server.js
file I declared apis as below
apis: ["./modules/data/first.js", "./modules/second.js", "./modules/config/getConfig.js"]
I added @swagger
in all .js
files and given
/first
for the first.js file/second
for the second.js file/third
for the third.js fileWhen I open swagger-UI
page, it is showing 3 APIs but when I click on anyone API then it is giving 404
response
Fixed the issue, problem is due to misconfiguration of app.use
.
Initially there is no JWT
token verification, so it worked but later JWT verification was introduced, then I faced 401 error ({"msg": "unauthorized"})
for swagger-UI
page itself, I made some changes in the swagger options. Then UI page got opened with all endpoints, but when I click on any endpoints they started giving 404
error.
When I changed app.use
to swagger first and then for my application endpoints it started working.