Forum Discussion

automica's avatar
automica
Visitor
5 years ago

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

No RepliesBe the first to reply