Swagger Multiple hosts in the same Json specification

I use a single host to document the REST API in Swagger Ui 2.0, but I need two hosts in the JSON file to call the shutdown API for http and the other for https. Is it possible? If so, how to do it?

Thanks!

+4
source share
1 answer

The way the URL is expanded is as follows:

  • You provide the base file in index.html, from where swagger.json is generated. The generated swagger.json file does not contain the per se URL or any http / https information. It has only the path to the base URL that you specified.
  • After creating the user interface based on the generated swagger.json, the Try buttons execute GET / POST / PUT requests based on the URL information in the address bar. check this piece of code in swagger-ui.js :

    if (url && url.indexOf('http') !== 0) { url = this.buildUrl(window.location.href.toString(), url); }

So, if you want to use https, use https in the address bar to get to the Swagger interface. You will also need to mention the same in your index.html and in swagger-ui.js in the above code.

+2
source

Source: https://habr.com/ru/post/1247135/


All Articles