【问题标题】:How can I display the current url in swagger ui?如何在 swagger ui 中显示当前 url?
【发布时间】:2018-05-23 15:00:02
【问题描述】:

我想显示当前 url,例如:https://{hostname}/{pathname}...,相应地,我在其中运行 swagger ui 而不是硬编码的相对路径。是否有任何可能的解决方案至少可以获取当前主机名? Like in the screenshot here where the same url is shown in swagger as well as in the adressbar of the browser.

我尝试了几件事,但似乎 swagger 中的文本只能硬编码。

【问题讨论】:

  • 你能给我们看一张你的意思的截图吗?
  • 海伦,谢谢你的提示。刚刚添加了一个屏幕截图。
  • 您的屏幕截图显示了绝对 URL。您想将相对 URL 更改为绝对 URL 的位置在哪里?
  • 很遗憾,我无法展示我的申请,因为它包含一些机密信息。在我的应用程序中,我只有相对 url,例如./somepath/example.json 我想将其更改为绝对路径,例如example_link 例如,此示例中标题下方的路径是指具有绝对路径的 json 文件。但是,就我而言,它只显示相对路径。

标签: url swagger display hostname absolute-path


【解决方案1】:

我自己也有这个需求,这是我的代码:

const ui = SwaggerUIBundle({
    url: window.location.protocol + '//' + window.location.host + '/api/swagger.json',
    dom_id: '#swagger-ui',
    deepLinking: true,
    presets: [
      SwaggerUIBundle.presets.apis,
      SwaggerUIStandalonePreset
    ],
    oauth2RedirectUrl: window.location.protocol + '//' + window.location.host + '/swagger-ui/oauth2-redirect.html',
    plugins: [
      SwaggerUIBundle.plugins.DownloadUrl,
      HideTopbarPlugin
    ],
    layout: "StandaloneLayout"
  });

只要确保 swagger.json 的路径在 URL 中正确。

【讨论】:

    猜你喜欢
    • 2018-11-15
    • 2020-06-10
    • 2020-12-22
    • 2019-04-21
    • 2016-11-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多