如何在 SwaggerUIBundle 中设置请求拦截器?
How to set request interceptor in SwaggerUIBundle?
在我们的 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
从 here 升级到最新版本,或更新您的节点包。我遇到了同样的问题,因为我在添加 requestInterceptor
支持之前下载了分发版。
在我们的 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
从 here 升级到最新版本,或更新您的节点包。我遇到了同样的问题,因为我在添加 requestInterceptor
支持之前下载了分发版。