Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenAPI Specification 3.0 shows different url in browser and Servers dropdown

enter image description here

We are using OpenApi Specification v1.4.8. We have load balancer urls and domain url. Domain url http://market.place.com/productsservice/swagger-ui.html and load balancer url is http://7649263.path.aws.com/productsservice/swagger-ui.html.

Due some ongoing network issue with the domain, we have shifted to use load balancer url for testing the application. When I access swagger ui using the above load balancer url, I see the domain URL in servers dropdown(haven't added it anywhere). Thus the url in browser address bar and in Servers dropdown is different.

Since Swagger uses the base url from 'Servers' dropdown to fabricate paths for testing, and my domain is not working, I am not able to fire request from Swagger UI. The request work fine via postman when the url in browser that is load balancer url is used.

Is there some configuration which can make the Servers dropdown URL and Browser url base path same ? What we are trying to do is, the Servers dropdown needs to take the url as in the address bar of browser.

like image 322
Sourabh Avatar asked Nov 23 '25 22:11

Sourabh


1 Answers

Probably you have openapi 3 configuration java class.

You should

new OpenAPI().addServersItem(...)


Edit your method like this.
    
    private String ip="109.162.230.178";   //your ip

    private String port="8587";   //your port

    // if you have context add this line
    private String context="tws";   //your context

    @Bean
    public OpenAPI customOpenAPI() {
        return new OpenAPI()
                .addServersItem(new Server().url("http://"+ip+":"+port+"/"+context))
               ...
    }

now your UI Combobox is like this : combobox


For example my server static ip is

109.162.230.178

and i have to use this Openapi 3 UI

from another computer outside of my local network in Internet.

like image 165
geeekfa Avatar answered Nov 25 '25 16:11

geeekfa



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!