Search code examples
swaggerswagger-ui

Swagger: deepLinking to method with tags collapsed does not work


For our Swagger API documentation, we'd like to send a deep link to an API method (=operation in swagger) to a developer.

Our Swagger version is 2.2.15 and Swagger-ui version is 5.11.8.

We use the parameter docExpansion: none to have all tags collapsed by default.

const ui = SwaggerUIBundle({
        url: url,
        dom_id: '#swagger-ui-container',
        docExpansion: 'none',
        defaultModelsExpandDepth: -1,
        deepLinking: true,

When using the deepLinking: true parameter, it does not open a method when opening that link in the browser.

When using docExpansion: list, the deep links do work.

In the documentation https://swagger.io/docs/open-source-tools/swagger-ui/usage/deep-linking/ it says, that this combination should work but it does not, neither in Firefox nor in Chrome.

Sure - use docExpansion: none to collapse all tags and operations. Your deep link will take precedence over the setting, so only the tag or operation you've specified will be expanded.

Is there another option that we can use to make the deepLinking work?


Solution

  • We had the problem as well. We solved it by

    • either updating swagger-ui from 5.11.8 to 5.17.11
    • or adapting swagger-ui-bundle.js: Look for className:S?"opblock-tag-section is-open":"opblock-tag-section" and change the decaration of S shortly before from S=i.isShown(b,"full"===c||"list"===c) to S=i.isShown(b,"full"===c||"list"===c||location.hash.includes("/"+r+"/")). This will show the method section also if the tag r is contained as part of the hash of the url entered even with docExpansion: none.