I would like to display the current url, eg.: https://{hostname}/{pathname}..., where I am running the swagger ui on instead of a hardcoded relative path, accordingly. Is there any possible solution to do so at least to get the current hostname? Like in the screenshot here where the same url is shown in swagger as well as in the adressbar of the browser.
I've tried several things but it seemed that text in swagger can only be hard coded.
I just had this need myself, here is my code:
const ui = SwaggerUIBundle({
url: window.location.protocol + '//' + window.location.host + '/api/swagger.json',
dom_id: '#swagger-ui',
deepLinking: true,
presets: [
SwaggerUIBundle.presets.apis,
SwaggerUIStandalonePreset
],
oauth2RedirectUrl: window.location.protocol + '//' + window.location.host + '/swagger-ui/oauth2-redirect.html',
plugins: [
SwaggerUIBundle.plugins.DownloadUrl,
HideTopbarPlugin
],
layout: "StandaloneLayout"
});
Just make sure the path to swagger.json is correct in the URL.