swagger-express-middleware icon indicating copy to clipboard operation
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

Open MohamedHajr opened this issue 6 years ago • 2 comments

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

MohamedHajr avatar May 15 '18 16:05 MohamedHajr

I'm having the exact same issue

aromansh avatar Aug 16 '19 01:08 aromansh

https://github.com/APIDevTools/swagger-express-middleware/issues/161#issuecomment-611808239

ajcrews avatar Apr 09 '20 23:04 ajcrews