swagger生成api文档

//index.js
var path=require('path')
var express=require('express')
var app=new express()

var swaggerJsDoc=require('swagger-jsdoc')

var swaggerUi=require('swagger-ui-express')

var options={definition:{openapi:'3.0.0',
        info:{title:'项目',version:'1.0.0',description:'描述'}},
        apis:[path.join(__dirname,'/routes/*.js')]
    }

var swaggers=swaggerJsDoc(options)

var userRouter=require('./routes/user')

app.use('/api-js-doc',swaggerUi.serve,swaggerUi.setup(swaggers))
app.use('/user',userRouter)
app.listen(4000)


//user.js
var express=require('express')
var router=express.Router()
/**
   * @swagger
   * /user/hello:
   *   get:
   *     description: Returns the homepage
   *     responses:
   *       200:
   *         description: hello world
   */

router.get('/hello',(req,res)=>{
    res.send('world')
})
module.exports=router

 

你可能感兴趣的:(node)