Swagger-ui: Ability to disable TopbarPlugin via SwaggerUIBundle parameter

Created on 10 Jun 2017  路  14Comments  路  Source: swagger-api/swagger-ui

There are README instructions on how to disable the TopBar, which is really helpful.

Would a PR be considered that would make it even easier -- for example a parameter in SwaggerUIBundle?

  // Build a system
  const ui = SwaggerUIBundle({
    ...
    presets: [
      SwaggerUIBundle.presets.apis,
      SwaggerUIStandalonePreset
    ],
    presets_config: {
       SwaggerUIStandalonePreset: {
           TopbarPlugin: false
       }
    }
    ...
  })

  window.ui = ui
}

There would be a new section called presets_config that would allow parameters to be passed for things like disabling the TopbarPlugin. This is just a rough idea, and I haven't really looked much at the swagger-ui codebase at all.

Here's the before vs after:

screen shot 2017-06-10 at 1 30 48 pm

after:

screen shot 2017-06-10 at 1 30 22 pm

swagger-ui version: commit https://github.com/swagger-api/swagger-ui/commit/212396f24d0d0f072d06c6af71087d6fddef9134

lock-bot feature 3.x

Most helpful comment

Drop it here since it may help. I managed to remove the top bar on the latest version by simply doing:

    const ui = SwaggerUIBundle({
      url: "/static/swagger.api.json",
      dom_id: `#${ DOM_ID }`,
      presets: [
        SwaggerUIBundle.presets.apis,
        SwaggerUIStandalonePreset.slice(1) // here
      ],
      plugins: [
        SwaggerUIBundle.plugins.DownloadUrl
      ],
      layout: "StandaloneLayout"
    })

Looks like a hack, but works out of the box.

All 14 comments

Interesting thought, @tleyden. It might be useful to allow configuring which plugins are enabled via the main config, and maybe even extend it more at some point by adding the ability to configure specific plugins.

@shockey - your thoughts?

This would also be nice to have for the schemes selection. Currently I am working around this by using a
<style> .swagger-ui .scheme-container, .swagger-ui .topbar { display: none !important; } </style>
block.

We can extend the plugin interface itself in order to make it easier to disable things, but I'm against adding flags for enabling/disabling specific things to the core- I'd rather those things happen through the plugin interface we have than add another layer of abstraction.

That being said, @ponelat wrote up up a way to disable entire plugins on the fly, though it would be a significant change to the plugin system as a whole: https://github.com/swagger-api/swagger-ui/issues/3246. I think it would address this use case, and solve some other limitations we're facing as well.

Looking at this again, I may have misinterpreted the intent. I would be open to a namespace in the main configuration object that allows for options meant for a specific plugin.

We already have custom for this purpose (see #3108) formalizing it further would be nice.

My main concern is how to set defaults for config options. It's a handy feature that we use in the core configs for many things.

Off the top of my head, passing in defaults at plugin-register time (when the plugin passes in its components and Redux bits) would be a good option, though it increases the surface area of the plugin interface.

Hi, the instructions at README, ".. remove Topbar plugin from presets..." (commenting // TopbarPlugin) are not working. There are a workaround?


PS#1: ideal is to remove the "false instruction" from README.

PS#2: see other motivations for "please remove the TopBar" at https://stackoverflow.com/q/44803881 ;-)

@ppKrauss if it helps, I was able to get it to work. Check out: http://cecil-assets.s3-website-us-east-1.amazonaws.com/swagger/ and do "view source"

Thanks @tleyden! With your clues I am building an "alternative swagger-ui" of pure HTML (and no TopbarPlugin) at https://github.com/okfn-brasil/swagger-ui-html

Drop it here since it may help. I managed to remove the top bar on the latest version by simply doing:

    const ui = SwaggerUIBundle({
      url: "/static/swagger.api.json",
      dom_id: `#${ DOM_ID }`,
      presets: [
        SwaggerUIBundle.presets.apis,
        SwaggerUIStandalonePreset.slice(1) // here
      ],
      plugins: [
        SwaggerUIBundle.plugins.DownloadUrl
      ],
      layout: "StandaloneLayout"
    })

Looks like a hack, but works out of the box.

@nfroidure, removing SwaggerUIStandalonePreset entirely, along with layout: "StandaloneLayout", should work as well :smile:

Closing - per my comment in October, the best way to do this is to remove the Standalone preset and layout from your configuration :)

how can i configure under resource folder files(like assets or folder) swagger.ui.html file, for me its not working.This is my project structure.

image

Is ther a way to pass this settings with a environment variable. I want to disable the explorer bar in a docker based installation (docker-compose).

setting layout: "BaseLayout" should work

For a Docker based installation, you will need to create your own Dockerfile to remove the preset however it's as simple as:

FROM swaggerapi/swagger-ui

RUN sed -i 's/SwaggerUIStandalonePreset/SwaggerUIStandalonePreset.slice(1)/' /usr/share/nginx/html/index.html

COPY . /app
Was this page helpful?
0 / 5 - 0 ratings