How to set request interceptor in SwaggerUIBundle?

家住魔仙堡 提交于 2019-12-10 17:56:54

问题


In our swagger.json we are setting basePath to /api, however, when the application is deployed in docker container, the context path is not /api. This could be different thing and we don't know what it is so we can't hard code it.

I am trying to set requestInterceptor as per the following guide, in order to catch the request and modify the url path perhaps:

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

But it seems requestInterceptor is being ignored. Is this possible? If not, how can I set the correct path at runtime?

This is my code in 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

}

We are using Swagger 2.0


回答1:


Upgrade to the latest version from here, or update your node package. I had the same problem because I downloaded the distribution before requestInterceptor support was added.



来源:https://stackoverflow.com/questions/46485621/how-to-set-request-interceptor-in-swaggeruibundle

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!