如何在 swagger ui 中显示当前 url?

How can I display the current url in swagger ui?

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

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

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

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 中是正确的。