Swagger UI-隐藏定义URL路径

Hex*_*xie 7 swagger-ui

使用Swagger - UI3XX

我只想知道这是否可能,如果可以,如何:

当前,我们需要显示hide的定义URL路径Swagger - UI

在此处输入图片说明

我知道无法删除此URL,我也不想这样做,我只想对查看此页面的客户端隐藏/屏蔽文本框。

这里查看新的Swagger文档,您可以添加一些很棒的技巧和其他功能-与查询有关的任何内容我都看不到。

我很确定,我可以查询HTML,找到有问题的元素的ID,然后在index.html中手动更改它的显示,我更喜欢使用内置方法,如果有的话在进入之前那可能的解决方案。

即像这样的事情是可行的,并且可以工作:

<style> .download-url-input { display: none !important; } </style> 
Run Code Online (Sandbox Code Playgroud)

这有可能吗?

Hel*_*len 9

在Swagger UI 3.x中,您可以通过以下方式之一隐藏顶部栏。

选项1

编辑dist\index.html并找到以下代码:

const ui = SwaggerUIBundle({
  url: "http://petstore.swagger.io/v2/swagger.json",
  dom_id: '#swagger-ui',
  deepLinking: true,
  presets: [
    SwaggerUIBundle.presets.apis,
    SwaggerUIStandalonePreset
  ],
  plugins: [
    SwaggerUIBundle.plugins.DownloadUrl
  ],
  layout: "StandaloneLayout"
})
Run Code Online (Sandbox Code Playgroud)

删除layoutSwaggerUIStandalonePresetSwaggerUIBundle.plugins.DownloadUrl,使构造函数如下所示:

const ui = SwaggerUIBundle({
  url: "http://petstore.swagger.io/v2/swagger.json",
  dom_id: '#swagger-ui',
  deepLinking: true,
  presets: [
    SwaggerUIBundle.presets.apis
  ]
})
Run Code Online (Sandbox Code Playgroud)

来源

选项2-重新编译代码

您也可以不使用顶部栏插件重新编译Swagger UI,如此处所述并对其进行重建。您将需要Node.js 6.x和npm3.x。

  1. 编辑src/standalone/index.js并从预设中删除TopbarPlugin:

    const ui = SwaggerUIBundle({
      url: "http://petstore.swagger.io/v2/swagger.json",
      dom_id: '#swagger-ui',
      deepLinking: true,
      presets: [
        SwaggerUIBundle.presets.apis,
        SwaggerUIStandalonePreset
      ],
      plugins: [
        SwaggerUIBundle.plugins.DownloadUrl
      ],
      layout: "StandaloneLayout"
    })
    
    Run Code Online (Sandbox Code Playgroud)
  2. 重建Swagger UI –在项目的根目录中运行

    npm install
    
    Run Code Online (Sandbox Code Playgroud)

    然后

    npm run build
    
    Run Code Online (Sandbox Code Playgroud)

现在您dist\index.html没有顶部栏。