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

标签 url swagger display hostname absolute-path

我想显示当前的 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 中的文本只能硬编码。

最佳答案

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

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"
  });

只需确保 URL 中 swagger.json 的路径正确即可。

关于url - 如何在 swagger ui 中显示当前 url?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50491654/

相关文章:

有效 URL 的 java.io.FileNotFoundException

php - 使用 .htaccess 创建 SEO 网址

node.js - Multer 文件上传不适用于 swaggerExpress

node.js - 当数据存储在csv文件中时在Nodejs中响应查询

android - 显示尺寸最大时parentWidth返回错误值?

javascript - 在 $_REQUEST 中选择没有显示的元素是空字符串

javascript - 使用单选按钮根据表单输入转到 URL

python - 使用 Python 请求库构建 URL

swagger - OpenAPI 3.0 - 如何避免在通过 ref 包含示例时添加 "value" key

html - float Div 列表不能正确显示自动高度