为 NodeJS 自定义 Swagger UI 标签标题和图标

Sam*_*HAI 0 node.js swagger

有没有办法用 NodeJS 自定义 Swagger UI?,我一直在处理“node_modules/swagger-ui-dist”目录中包含的“swagger-ui.css”文件,我设法更改了标签栏背景颜色并替换了栏标志,但我不能t 精确定位 index.html 文件以更改选项卡标题和 favicon,请记住前面提到的目录中确实有一个“index.html”文件,但似乎 swagger 每次都在动态生成一个新的索引文件路由被访问。

谢谢你。

小智 8

要自定义 swagger 页面的样式,您可以将自定义 CSS 作为选项的 Favicon 属性的 'customCss' 和 'customfavIcon' 传递给设置函数。

const express = require('express');
const app = express();
const swaggerUi = require('swagger-ui-express');
const swaggerDocument = require('./swagger.json');

var options = {
  customCss: '.swagger-ui .topbar { display: none }',
  customSiteTitle: "New Title",
  customfavIcon: "/assets/favicon.ico"
};

app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(swaggerDocument, options));
Run Code Online (Sandbox Code Playgroud)