【问题标题】:How to remove the API definition URL under title in Swagger UI?如何在 Swagger UI 中删除标题下的 API 定义 URL?
【发布时间】:2018-04-04 02:14:55
【问题描述】:

我正在使用 Swagger UI,并且想要删除显示在标题部分下的 API 定义 URL(指向 YAML 文件的链接),如图中突出显示的那样。这可以通过自定义 Swagger UI index.html 页面来完成吗?

【问题讨论】:

  • 一个选项是用 CSS 隐藏它

标签: swagger swagger-ui


【解决方案1】:

选项 1:使用 CSS 隐藏

<!-- index.html -->

<style>
...

.swagger-ui .info hgroup.main a {
  display: none
}
</style>

选项 2:使用 JavaScript 隐藏 (v.3.13.0+)

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
    ],
    ...
  })

Source

【讨论】:

  • 更改 js 并为我重建捆绑包工作。谢谢!
猜你喜欢
  • 2019-10-26
  • 2022-10-15
  • 1970-01-01
  • 1970-01-01
  • 2021-06-01
  • 2016-11-09
  • 1970-01-01
  • 2019-11-06
  • 1970-01-01
相关资源
最近更新 更多