scottie1984 / swagger-ui-express

Adds middleware to your express app to serve the Swagger UI bound to your Swagger document. This acts as living documentation for your API hosted from within your app.
MIT License
1.41k stars 225 forks source link

How to serve SwaggerUI without using middleware (app.use) #315

Closed Hasankanso closed 1 year ago

Hasankanso commented 1 year ago

I'm implementing a controller where I'm only responsible of the get route/function and don't have access to app.

const swaggerUI = require('swagger-ui');

function getSwagger(req, res) {

//swaggerUI.serve?
//swaggerUI.serveFile?

var page = swaggerUI.generateHTML(doc);

return res.send(page);
}

This isn't working with error 404. how do I call serve correctly in the function?

P.S.: this is a pseudo code, because I don't have access to my pc at the moment, but the idea is I don't have access to app.use and app.get, I only can implement inside of the get function.

scottie1984 commented 1 year ago

I don’t think you will be able to do this as the serve is used to serve the assets therefore needs the app.use