我是一名有用的助手,可以进行文本翻译。
我有一个使用Typescript编写的Node.js服务器,并且正在尝试为不同的控制器定义不同的Swagger路径,但是swagger-ui-express模块似乎只会在特定路由中显示最后定义的文档。
X组控制器的index.ts文件。
我有一个使用Typescript编写的Node.js服务器,并且正在尝试为不同的控制器定义不同的Swagger路径,但是swagger-ui-express模块似乎只会在特定路由中显示最后定义的文档。
X组控制器的index.ts文件。
import express from 'express';
import passport from 'passport';
const router = express.Router();
// import all bot routes
import { authRoute } from './auth';
import { botCrudRoute } from './bot-crud';
import { aiRoutes } from './ai';
import { categoryCrudRoute } from './categories-crud';
const swaggerUi = require('swagger-ui-express');
import { botSwaggerDoc } from './swagger';
const swaggerDoc = botSwaggerDoc;
const swaggerUiOpts = {
explorer: false
};
// Swagger setup
router.use('/api-docs', swaggerUi.serve);
router.get('/api-docs', swaggerUi.setup(swaggerDoc, swaggerUiOpts));
Y控制器组的index.ts
import express from 'express';
const router = express.Router();
// import all bot routes
const swaggerUi = require('swagger-ui-express');
import { adminSwaggerDoc } from './swagger';
const swaggerDoc = adminSwaggerDoc;
const swaggerUiOpts = {
explorer: false
};
// Swagger setup
router.use('/api-docs', swaggerUi.serve);
router.get('/api-docs', swaggerUi.setup(swaggerDoc, swaggerUiOpts));
export const adminRoutes = router;
api.ts将所有控制器分组
'use strict';
import express from 'express';
import { Response, Request, NextFunction } from 'express';
import { adminRoutes } from './admin';
import { botRoutes } from './bot';
// import { onboardRoutes } from './onboard';
const router = express.Router();
// router.use('/onboard', onboardRoutes);
router.use('/bot', botRoutes);
router.use('/admin', adminRoutes);
export const apiRoutes = router;
server.ts
/**
* Primary app routes.
*/
app.use('/api', apiRoutes);
swaggerDoc的示例之一
export const botSwaggerDoc = {
'swagger': '2.0',
'info': {
'version': '1.0.0',
'title': 'Cupo embed chat bot API',
'license': {
'name': 'Internal use only'
}
swagger-ui-express模块仅使用最后定义的文档,好像服务器保留对该文档的引用...