swagger-express-middleware
swagger-express-middleware copied to clipboard
When implementing integration tests, app middleware needs to be fully initialized before require the app in the test module
Hi, I'm having an issue regarding the middleware init function as it is async and I need to export the express app to use it with supertest since the code is async the app gets exported before all the modules are initialized.
middleware('src/swagger.yaml', app, function (err, middleware) {
// Add all the Swagger Express Middleware, or just the ones you need.
// NOTE: Some of these accept optional options (omitted here for brevity)
app.use(
middleware.metadata(),
middleware.CORS(),
middleware.files(),
middleware.parseRequest(),
middleware.validateRequest(),
)
app.use('/users', usersRouter)
app.use(morgan('tiny'))
app.use((err, req, res) => {
// log the error...
res.sendStatus(err.httpStatusCode).json(err)
})
})
module.exports = app
I'm having the exact same issue
https://github.com/APIDevTools/swagger-express-middleware/issues/161#issuecomment-611808239