【发布时间】:2018-04-04 02:14:55
【问题描述】:
我正在使用 Swagger UI,并且想要删除显示在标题部分下的 API 定义 URL(指向 YAML 文件的链接),如图中突出显示的那样。这可以通过自定义 Swagger UI index.html 页面来完成吗?
【问题讨论】:
-
一个选项是用 CSS 隐藏它
标签: swagger swagger-ui
我正在使用 Swagger UI,并且想要删除显示在标题部分下的 API 定义 URL(指向 YAML 文件的链接),如图中突出显示的那样。这可以通过自定义 Swagger UI index.html 页面来完成吗?
【问题讨论】:
标签: swagger swagger-ui
<!-- index.html -->
<style>
...
.swagger-ui .info hgroup.main a {
display: none
}
</style>
Swagger UI 3.x 使用插件系统来控制渲染。您可以定义一个禁用InfoUrl 组件的自定义插件 - 这将阻止呈现 API 定义链接。此方法适用于 Swagger UI 3.13.0 及更高版本。
// index.html
window.onload = function() {
// Custom plugin to hide the API definition URL
const HideInfoUrlPartsPlugin = () => {
return {
wrapComponents: {
InfoUrl: () => () => null
}
}
}
// Build a system
const ui = SwaggerUIBundle({
...
plugins: [
SwaggerUIBundle.plugins.DownloadUrl,
HideInfoUrlPartsPlugin // <---- Apply the plugin
],
...
})
【讨论】: