Hello,
I have multiple swagger.json files (each of these spec files is for one service) and I am trying to have all these spec files plugged into the same swagger-ui. For instance: the api_selector should give me an option to select one of those swagger.json files and the resource should be rendered from the selected spec file.
Is there way to do this?
Thanks
Hi, currently no, you cannot, although it's quite easy to add yourself. You should be able to do everything in the index.html file that ships with swagger-ui and reload the UI with an .onChange event.
@ponelat shared a solution in the google group that may help your use case - https://groups.google.com/d/msg/swagger-swaggersocket/Uz9UhRzKBo8/ITQkXO-zvwAJ
Thanks @webron and @fehguy . The solutions that you guys said worked. However, I am hitting this issue when I try to do a ui re-load when the selected service is changed. The re-load works perfectly fine and the APIs are loaded correctly. However, the text value of the selector does not change in the UI and always remains One. Is there any other place that I need to set the selected service?
Index.html present here: https://gist.github.com/sacredMonster/1fdd8fad2d99e4f8b408
Thanks..
@sacredMonster we'd have to change some things... here is an updated gist https://gist.github.com/ponelat/328c2f651760fe3fdab2
@ponelat thank you for the help.
I imagine with the prevelance of microservices this is going to become a more sought after feature
We built this into our swagger spec, but it was painful to deal with the version parameter. I'm in the process of porting all our customizations to the latest version and I can report back when I get through that. I think the biggest pain point is where do we store the configuration of all our services, end point versions, and environments. We are micro service oriented.
Our existing swagger ui has a custom header control like this:

We had to come up with a custom JSON object to define that header and keep it up to date. Also, we have a proxy that handles all the pathing by environment, we prefixed the routes with /dev, /staging etc, but the issue with this is that the swagger spec itself is served from the service, but in each environment it isn't aware of the proxy path. I had to write a hack into the swagger core that injected this into the base path of the swagger spec on the fly as its accessed. It would be nice if that was somehow configurable from the swagger ui.
Hi @hunt3r , is your solution available here on github please?
Thanks
@hunt3r 馃憤 share share share!
I actually rebuilt the whole thing last week and introduced a python app server that handles all the routing and functions as a proxy to the services. The solution above required a core hack to swagger ui and I didn't like that. It had to update the basePath and host URL dynamically based on the environment you are using and the /
It assumes that your services publish the swagger specs.
It uses a YAML file to configure everything and generate the UI, wireup all the proxies via Tornado, generate the header navigation, etc. I even added a homepage that is generated with links and other info.
I do plan to open source the solution I just haven't gotten it to where its generic enough. It has all the URBN specificity in there right now. I will post back here within a month or so and link you to the repo when its ready.
@hunt3r can you post whatever we have and we as a community and contribute. Thanks for doing the good work.
I know the issue is already closed but even after reading all the comments it wasn't clear this functionality is now built-in to swagger-ui version 3.x using the urls parameter in the index.html file. https://github.com/swagger-api/swagger-ui#parameters
So hopefully this will save some people the trouble of trying to implement the above solutions when this is now a supported feature.
Most helpful comment
I know the issue is already closed but even after reading all the comments it wasn't clear this functionality is now built-in to swagger-ui version 3.x using the
urlsparameter in theindex.htmlfile. https://github.com/swagger-api/swagger-ui#parametersSo hopefully this will save some people the trouble of trying to implement the above solutions when this is now a supported feature.