我正在尝试找到一种解决方案,使单个 Express 应用程序拥有多个 swaggerUi 文档。
我正在使用:
"typescript": "^2.5.2",
"swagger-tools": "^0.10.1",
"express": "^4.15.3",
"express-openapi": "^1.0.1",
我的 swagger doc 文件部分是用项目文件架构生成的。
我该怎么做?
编辑---
现在我正在像这样初始化 swaggerUi :
const openapi = Openapi.initialize({
paths: openApiPaths,
expressApp,
swaggerApiDoc,
});
const openApiSpec: any = openapi.apiDoc;
app.use(swaggerUI(openApiSpec));
其中 openApiPaths
包含 swagger 文档的 paths:{}
最佳答案
自 2022 年起,您可以向同一个应用程序添加多个 swagger UI。 来自swagger-UI documents :
To run 2 swagger ui instances with different swagger documents, use the serveFiles function instead of the serve function. The serveFiles function has the same signature as the setup function.
const express = require('express');
const app = express();
const swaggerUi = require('swagger-ui-express');
const swaggerDocumentOne = require('./swagger-one.json');
const swaggerDocumentTwo = require('./swagger-two.json');
var options = {}
app.use('/api-docs-one', swaggerUi.serveFiles(swaggerDocumentOne, options), swaggerUi.setup(swaggerDocumentOne));
app.use('/api-docs-two', swaggerUi.serveFiles(swaggerDocumentTwo, options), swaggerUi.setup(swaggerDocumentTwo));
关于node.js - 多个 swaggerUi 与一个 express 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48339325/