6

I would like to display the current url, eg.: https://{hostname}/{pathname}..., where I am running the swagger ui on instead of a hardcoded relative path, accordingly. Is there any possible solution to do so at least to get the current hostname? Like in the screenshot here where the same url is shown in swagger as well as in the adressbar of the browser.

I've tried several things but it seemed that text in swagger can only be hard coded.

pink_panda
  • 100
  • 1
  • 6
  • Can you show us a screenshot of what you mean? – Helen May 23 '18 at 16:59
  • Hy Helen, thank you for the hint. Just added a screenshot. – pink_panda May 24 '18 at 11:08
  • Your screenshot shows absolute URLs. Where are the relative URLs that you want to change to absolute URLs? – Helen May 24 '18 at 12:12
  • Unfortunetly, I can't show my application because it contains some confidential information. In my application I only have relativ urls e.g. ./somepath/example.json which I want to change to absolute-paths like here [example_link](http://petstore.swagger.io/?url=https://raw.githubusercontent.com/OAI/OpenAPI-Specification/master/examples/v2.0/json/api-with-examples.json#/default/getVersionDetailsv2) For instance, the path below the header in this example is refering to the json file with an absolut-path. However, in my case it only shows the relative path. – pink_panda May 24 '18 at 13:07

1 Answers1

5

I just had this need myself, here is my code:

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

Just make sure the path to swagger.json is correct in the URL.

Guilherme Mussi
  • 956
  • 7
  • 14