5

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

xbmono
  • 2,084
  • 2
  • 30
  • 50

1 Answers1

3

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.

Andy McCluggage
  • 37,618
  • 18
  • 59
  • 69
  • Unfortunately I can't easily upgrade before approval from technical team but the question is, is my solution going to work if I do the upgrade? Can I set the host and context path on the fly? – xbmono Oct 02 '17 at 22:13