Can the base url change in swagger?

I have currently implemented Swagger and I noticed that the base url for resources is hard-coded in JSON resource files, ideally I would like to give the user the ability to change the base url for different json verbages. So, for example, give them the opportunity to send a receipt from one environment and put from another on the same page, since I work with several environments, otherwise they will have to change the JSON in each of their resources every time they want to use a new Wednesday Does anyone know if this is possible?

+5
source share
2 answers

It is possible, and I implement it as follows:

In swaggerui, I programmatically declare my url by selecting the url via javascript:

// Get the url: theUrl = window.location.protocol+"//" + window.location.host+"/docs"; window.swaggerUi = new SwaggerUi({ url: theUrl,..other parameters...}) 

In my json files where I declare the resource, I simply declare my base path as "/", as shown below:

 { "apiVersion": "1.0.0", "swaggerVersion": "1.2", "basePath": "/", "resourcePath": "/api/myapi"....... 

Hope this helps!

+3
source

Dynamically change the host name (and override the value from the JSON file) of the target server (where the REST request is sent):

 $.each(window.swaggerUi.api.apis, function(key, val) { window.swaggerUi.api.apis[key].basePath = "http://target:port"; }); 
+1
source

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


All Articles