swagger-js icon indicating copy to clipboard operation
swagger-js copied to clipboard

overriding host

Open vivilian-git opened this issue 9 years ago • 17 comments

In the old version of UI, i can override the host using window.swaggerUi.api.setHost(url), as explained in swagger-api/swagger-js#532.

How could achieve the same with the latest version?

vivilian-git avatar May 05 '17 23:05 vivilian-git

this worked for me but it's not official nor elegant

https://gist.github.com/hareeqi/c9496288cfccf52342930874ac9670d3

hareeqi avatar May 09 '17 21:05 hareeqi

This is actually very important for many scenarios, simplest being one spec and executing against test systems. How to achieve the same without the ability to switch? I can only think of multiple specs, one for each target system. In case only the host differs this does not make much sense. Hence, this feature should be considered important.

zhimoda avatar May 11 '17 09:05 zhimoda

It is considered important, but we still have to prioritize based on our resources. As with anything else, PRs are welcome.

@zhimoda in general, if you don't specify a host at all, and load it from the environment that you want to run against, that would work as well.

webron avatar May 12 '17 17:05 webron

Wanted to comment here with a semi-workaround. For me, I wanted to showcase a production URL in the docs, but have the "Try it out" button fire requests to a staging URL instead. I'm sure I'm not alone in this desire.

What I did was just set the host in my Swagger conf file to my staging URL so that the "Try it out" button would use that, but I just changed the .base-url DOM element to my production URL using the very-browser-supported document#querySelector method on page load. That element is the main place where the user sees the base URL:

document.querySelector('.base-url').textContent = '[ Base url: api.prod.com/ ]';

alkrauss48 avatar Jun 09 '17 18:06 alkrauss48

Please consider include ability to override basePath as well.

rautars avatar Jun 13 '17 20:06 rautars

+1

melanke avatar Sep 18 '17 01:09 melanke

+1

joeherwig avatar Nov 15 '17 13:11 joeherwig

Folks, please note that OpenAPI 3.0 allows you to specify multiple URLs for your API, and use variables in server hostnames and paths. Support for this is in Swagger-UI :smile:

shockey avatar Nov 15 '17 21:11 shockey

My team and I are very interested on this feature, and I consider to volonteer to implement it. Would it be possible to have some guidance? @shockey @webron :) (gitter session for instance)

AdrieanKhisbe avatar Apr 13 '18 13:04 AdrieanKhisbe

@AdrieanKhisbe, we don't have a gitter (https://github.com/swagger-api/swagger-ui/issues/3544!), send me an email if you need guidance!

shockey avatar Apr 20 '18 00:04 shockey

Any updates on the ability to override the Host?

cancan101 avatar Jul 25 '18 22:07 cancan101

I need this feature too

dark-reiser avatar Sep 24 '18 16:09 dark-reiser

I need this feature too.

zhoumeina avatar Dec 13 '18 01:12 zhoumeina

@cancan101, Sorry we went an other way at my company, so I shifted subject and did not took care of it. :/ So no updates on my side

AdrieanKhisbe avatar Dec 13 '18 09:12 AdrieanKhisbe

2 years and still no way to override host at init ?

Rmannn avatar May 28 '19 05:05 Rmannn

I'm also looking for this. Sounds like easily solvable inside the app.

niondir avatar Jul 24 '19 10:07 niondir

I've explained here why there is no need for swagger-js to support these mutators.

Addressing this issue should now be possible purely from swagger-ui by UrlMutatorPlugin.

Closing in favor of https://github.com/swagger-api/swagger-ui/issues/5981

char0n avatar Apr 30 '20 13:04 char0n