Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ability to disable TopbarPlugin via SwaggerUIBundle parameter #3229

Closed
tleyden opened this issue Jun 10, 2017 · 14 comments
Closed

Ability to disable TopbarPlugin via SwaggerUIBundle parameter #3229

tleyden opened this issue Jun 10, 2017 · 14 comments

Comments

@tleyden
Copy link

tleyden commented Jun 10, 2017

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 212396f

tleyden pushed a commit to tleyden/swagger-ui that referenced this issue Jun 10, 2017
See swagger-ui issue swagger-api#3229
@webron
Copy link
Contributor

webron commented Jun 12, 2017

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?

@roben
Copy link

roben commented Jun 14, 2017

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.

@shockey
Copy link
Contributor

shockey commented Jun 19, 2017

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: #3246. I think it would address this use case, and solve some other limitations we're facing as well.

@shockey
Copy link
Contributor

shockey commented Jun 27, 2017

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.

@ppKrauss
Copy link

ppKrauss commented Jun 28, 2017

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 ;-)

@tleyden
Copy link
Author

tleyden commented Jun 29, 2017

@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"

@ppKrauss
Copy link

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

@nfroidure
Copy link

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.

@shockey
Copy link
Contributor

shockey commented Oct 13, 2017

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

@shockey
Copy link
Contributor

shockey commented Jun 12, 2018

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

@shockey shockey closed this as completed Jun 12, 2018
@divyakakkirala
Copy link

divyakakkirala commented Jun 29, 2018

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

@sir-gon
Copy link

sir-gon commented Jul 29, 2018

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).

@magdiel01
Copy link

magdiel01 commented Sep 30, 2018

setting layout: "BaseLayout" should work

@yinzara
Copy link
Contributor

yinzara commented Apr 2, 2019

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

@lock lock bot locked and limited conversation to collaborators Apr 2, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

10 participants