I am trying to edit my express-swagger project and following this tutorial to add input validation into an express app
I used swagger-express-mw
package to generate a boilerplate using swagger project create app
but its not clear where I can add my middlewares as explained in the tutorial I mentioned above. Specifically i cant intercept my request, I get a typeError:
TypeError: req.checkBody is not a function
at saveNote
Here is my entry file. Everything apart from the bodyParser and validator function is coming from the boilerplate so I dont understand
SwaggerExpress.create(config, function(err, swaggerExpress) {
if (err) { throw err }
// install middleware
swaggerExpress.register(app)
// middleware
app.use(bodyParser.urlencoded({ extended: false })); // my code
app.use(validator()) // my d
const port = process.env.PORT || 10010
app.listen(port)
// if (swaggerExpress.runner.swagger.paths['/notes']) {
// console.log('try this:\nlocalhost:10010/notes to get all notes')
// }
})
I know this is an old question, but this might help someone along the way.Here is the simple NodeJS code showing how to integrate
swagger-tools
withswagger-express-mw
orswagger-node-runner
npm packages.