使用Express.Router()进行Swagger UI设置

时间:2019-10-11 13:12:58

标签: reactjs express swagger swagger-ui

我试图用招摇的方式自动生成api文档。当我使用express时它工作正常,但当我使用express.router()时它不工作

Server.js

fixVersion in unreleasedVersions() ORDER BY priority DESC

endpoint.js

const app = express(express);
swaggerDoc(app);
endpoints(app);

麻烦的设置

var routes = require('./routes.js');
const initialEndPoint=(app)=>{
         app.use('/api',routes);
}

路线

const swaggerUi = require('swagger-ui-express');
const swaggerJsdoc = require('swagger-jsdoc');
const router = require('express').Router();
module.exports=(app)=>{
   // following line work 
   // app.use('/api-docs',swaggerUi.serve,swaggerUi.setup(specs));
  // with router its not working
    router.use('/api-doc',swaggerUi.serve);
   router.get('/api-doc',swaggerUi.setup(specs));
}

我不明白为什么大摇大摆不能与router.route一起使用。

0 个答案:

没有答案