【问题标题】:How to set request interceptor in SwaggerUIBundle?如何在 SwaggerUIBundle 中设置请求拦截器?
【发布时间】:2017-09-29 09:15:01
【问题描述】:

在我们的 swagger.json 中,我们将 basePath 设置为 /api,但是,当应用程序部署在 docker 容器中时,上下文路径不是 /api。这可能是不同的东西,我们不知道它是什么,所以我们不能硬编码它。

我正在尝试按照以下指南设置 requestInterceptor,以便捕获请求并可能修改 url 路径:

https://swagger.io/docs/swagger-tools/#customization-36

但似乎 requestInterceptor 被忽略了。这可能吗?如果没有,如何在运行时设置正确的路径?

这是我在 index.html

中的代码
    window.onload = function() {
  // Build a system
  const ui = SwaggerUIBundle({
    url: "../api-docs/swagger.json",
    dom_id: '#swagger-ui',
    deepLinking: true,
    requestInterceptor: function(request) {
        window.alert(request);
    },
    presets: [
      SwaggerUIBundle.presets.apis,
      SwaggerUIStandalonePreset
    ],
    plugins: [
      SwaggerUIBundle.plugins.DownloadUrl
    ],
    layout: "StandaloneLayout"
  })

  window.ui = ui

}

我们正在使用 Swagger 2.0

【问题讨论】:

    标签: swagger swagger-ui swagger-2.0


    【解决方案1】:

    从here升级到最新版本,或者更新你的节点包。我遇到了同样的问题,因为我在添加 requestInterceptor 支持之前下载了发行版。

    【讨论】:

    • 很遗憾,在技术团队批准之前,我无法轻松升级,但问题是,如果我进行升级,我的解决方案是否可行?我可以即时设置主机和上下文路径吗?
    猜你喜欢
    • 2021-02-04
    • 2019-03-03
    • 1970-01-01
    • 2015-06-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-13
    • 1970-01-01
    相关资源
    最近更新 更多