showing documentation for one version of the API in a multi-version API environment
See original GitHub issueI have two versions of the API, v1
and v2
I would like to provide a dropdown that defaults to the latest version, and allows selecting other version(s). Documentation of the selected version should be shown in the panel below. Is there a solution for this that already exists (so I don’t reinvent the wheel)? If not, I would like to create one. However, for starters, with regards to the uiCompleteScript
option, from the documentation, it seems like a server-side option, but it makes more sense as a client-side option. Assuming it is a client-side option, I am doing something like below
function selectVersion() {
const vContainers = document.querySelectorAll('.opblock-tag-section');
console.log(vContainers);
}
window.onload = function() {
var swaggerOptions = {
documentationPage: false,
documentationPath: "/docs",
uiCompleteScript: selectVersion()
}
var ui = SwaggerUIBundle(swaggerOptions);
window.ui = ui;
};
When I load the /docs
page, the uiCompleteScript
runs before the ui is created, since fetch
-ing the /swagger.json
is async. As a result, vContainers
is an empty list rather than a list of two nodes. For one, is looking for the '.opblock-tag-section'
divs the right approach? Two, how can I ensure that uiCompleteScript runs after the ui is complete?
Update: Well, uiCompleteScript
certainly doesn’t seem to belong on the server-side, but I am not sure me fiddling with the template on the client side is the right way forward. In any case, I want to get the divs created by the ui for each version, hide some of them, and show only the selected one. Am stuck…
Issue Analytics
- State:
- Created 4 years ago
- Comments:10
would the
urls
parameter work? https://github.com/swagger-api/swagger-ui/blob/master/docs/usage/configuration.md#coreurls
:Array
. An array of API definition objects([{url: "<url1>", name: "<name1>"},{url: "<url2>", name: "<name2>"}])
used by Topbar plugin. When used and Topbar plugin is enabled, the url parameter will not be parsed. Names and URLs must be unique among all items in this array, since they’re used as identifiers.uiCompleteScript
has been fixed in latest version so closing this ticket.