cancel
Showing results for 
Search instead for 
Did you mean: 

Setting Host and BasePath dynamically

Highlighted
Visitor

Setting Host and BasePath dynamically

I'm looking to set host and basePath to override the host and bathPath settings stored in my swagger.json.

I'm using Swagger 2.0 spec and the following for package for swagger UI

"swagger-ui": "^3.22.1"

 Within the documentation there is reference to the following:

 

swaggerUi.api.setHost(<hosturl>);

which should set the host. I'm having issues on finding a working example of this.

 

Within App.js I have the following:

 

    componentDidUpdate() {

        console.log(this.state.definitionLink);

        const ui = SwaggerUI({
                domNode: document.getElementById("api-body"),
                url: this.state.definitionLink,
                deepLinking: true,
                docExpansion: true,
                showCommonExtensions: true,
                filter: true,
                requestInterceptor: function (request) {
                },
                responseInterceptor: function (response) {
                }
            }
        );
    }

where

 

this.state.definitionLink 

is the url of the swagger.json

 

Where in my app would i place the: swaggerUi.api.setHost(<hosturl>)? or is this call incompatible with my version of swagger-ui?

 

If someone has a working code snipped that would be really helpful.

Thanks

New Here?
Join us and watch the welcome video:
Join our online event
SeptemberHubBub
Top Kudoed Authors
Join the September Hub-bub to show off, learn and win