swagger-routes-joi
v1.0.5
Published
swagger routes.
Downloads
3
Readme
swagger-routes-joi
swagger routes.
- Installation
npm install swagger-routes-joi --save
- In order to generate swagger.json in node.js express framework.
how to use?
- you should install express body-parser express-validator and swagger-routes-joi
const express = require('express')
const expressValidator = require('express-validator')
const bodyParser = require('body-parser')
const Swagger = requre('swagger-routes-joi')
const swagger = new Swagger()
const Router = express.Router
const router = new Router()
router.use(expressValidator({
validator: Swagger.validator
}))
router.use(bodyParser.json())
router
.route('/')
.spec({
get: {
summary: 'test',
parameters: [{
name: 'name',
type: 'string'
}],
resources: {
200: {}
}
}
})
.get(function (req, res) {
res.send({ such: 'data' })
})
app.use(router)
swagger
.addInfo({title: 'test', description: 'test', version: '1.0.0'})
.setBasePath('./swagger.json')
.readResources(app._router)
app.get('/swagger.json', function (req, res) {
res.json(swagger.generateDoc())
})
app.listen(3000)
- open http://127.0.0.1:3000/swagger.json