question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

showing documentation for one version of the API in a multi-version API environment

See original GitHub issue

I 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:closed
  • Created 4 years ago
  • Comments:10

github_iconTop GitHub Comments

1reaction
robmcguinnesscommented, Sep 11, 2019

would the urls parameter work? https://github.com/swagger-api/swagger-ui/blob/master/docs/usage/configuration.md#core

urls: 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.

0reactions
robmcguinnesscommented, May 5, 2021

uiCompleteScript has been fixed in latest version so closing this ticket.

Read more comments on GitHub >

github_iconTop Results From Across the Web

showing documentation for one version of the API in a multi ...
I have two versions of the API, v1 and v2 I would like to provide a dropdown that defaults to the latest version,...
Read more >
Tutorial: Publish multiple versions of your API - Azure
As shown in this tutorial, it is possible to provide multiple versions in Azure API Management. For background, see Versions & revisions.
Read more >
How to version an API to easily deploy many versions?
Multiple versions of the API can be deployed on CloudHub. Check out what versioning an API approach you can use.
Read more >
Versioning an API | Cloud Endpoints with OpenAPI
Although Cloud Endpoints runs only one minor version of an API at a time, the graphs and logs in Endpoints > Services display...
Read more >
How to deploy multiple versions of an API using paths on ...
This post uses an example API server written in Node.js to show how you can deploy more than one version of an application...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found