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 swagger-ui default petstore url #714

Closed
alfonz19 opened this issue Jun 7, 2020 · 10 comments
Closed

Ability to disable swagger-ui default petstore url #714

alfonz19 opened this issue Jun 7, 2020 · 10 comments
Labels
enhancement New feature or request

Comments

@alfonz19
Copy link

alfonz19 commented Jun 7, 2020

We are deploying to production environment. If someone opens default swagger page without configUrl specified, it's completely NOT ok, to display some playground petstore app.

by setting property( is placeholder):

springdoc.swagger-ui.configUrl=/<contextPath>/v3/api-docs

I'd expect that this configUrl will be opened if configUrl is not present in URL, however it seems, that if I put this configuration here, I won't be able to use url:

http://localhost:8080/<contextPath>/swagger-ui/index.html?configUrl=/<contextPath>/v3/api-docs

and will get PetStore undesirable even for this URL. Either I'm misreading documentation or this is a bug.

Regardless of that — I understand, that this behavior goes back to swagger_ui and their targetting of their product for non-prod environment. The web/stackoverflow/... provides examples how to block this behavior, but the suggestions are rather ridiculous(rebuilding swagger), or not appliable (because requires javascript customization of swagger). Can you suggest correct solution? I don't want to see any possibility to reach PetStore nonsense or any other config other than what we provided on our URL. If someone wants to use PetStore app, he can surely do it elsewhere. Currently we have to do it via spring resource transformer just to force swagger to good behavior.

@bnasslahsen
Copy link
Contributor

@alfonz19,

This behaviour is not related directly to sprindoc-openapi, but to swagger-ui project:

It is a duplicate of: #43, #379 and #660.

Our goal is not to change the behaviour of the swagger-ui. But to build on top of it.
I see that there is a lot of demand on disabling this default url, because its understandable from a security perspective that some organisations don't want to serve the default swagger-ui petstore url.

So waiting for the swagger-ui to address issue, we can add a property to disable it on the springdoc side, and hide all the additional configuration of adding spring resource transformer.

@alfonz19
Copy link
Author

alfonz19 commented Jun 7, 2020

Ok, so there is currently no way, how to correctly block it somehow from your side?

What we probably will endup using is setting springdoc.swagger-ui.layout to BaseLayout (which seems not to be the default values as your documentation says, since wihout it I'm getting StandaloneLayout) and filtering requests to overwrite all incorrect swagger requests(like removing layout or chagning configuration) to correct one. It's very bad solution, but I'm not aware of any better. Are you?

And how do you explain described behavior of configUrl?
springdoc.swagger-ui.configUrl

@bnasslahsen
Copy link
Contributor

As explained, you can use spring resource transformer to block. We will see if we can add it on springdoc property which is not the best choice.

springdoc.swagger-ui.configUrl is mapping of on the swagger-ui property: configUrl

You can have a look at the documentation of configurl, which serves all the configuration of the swagger and ( url/urls are only one of the fields returned by the configurl):

  • This property will not help you change anything about the default url, without extra code.

The layout setting depend on the experience you want to offer to the user. There is no bad choice on that. It depends on your own context.

@bnasslahsen bnasslahsen changed the title configUrl parameter not respected? Ability to disable swagger default petstore url Jun 7, 2020
@bnasslahsen bnasslahsen changed the title Ability to disable swagger default petstore url Ability to disable swagger-ui default petstore url Jun 7, 2020
@bnasslahsen
Copy link
Contributor

Starting from the next release v1.4.1, the following property will be added to disable the swagger-ui default petstore url:

springdoc.swagger-ui.disable-swagger-default-url=true

@alfonz19, you can validate it with the latest snapshot which is already deployed.

@alfonz19
Copy link
Author

alfonz19 commented Jun 7, 2020

Thank you very much!

@alfonz19
Copy link
Author

alfonz19 commented Jun 7, 2020

Tested it, it works. Thanks again.

@sourabhparsekar
Copy link

springdoc.swagger-ui.disable-swagger-default-url=true

THis is not working for me in 1.4.4 version :(

@bnasslahsen
Copy link
Contributor

@sourabhparsekar,

It's just deployed using the last stable version (v1.4.8) without any issue: You can see the petstore url is disabled here:

If you have having any difficulties, you can have a look at the sample configuration for this sample:

If you are still facing problems, please help to speed up problem diagnosis by providing as much information as possible, by providing a Minimal, Reproducible Example - with HelloController that reproduces the problem:

@sourabhparsekar
Copy link

@bnasslahsen - Yes, after changing to v1.4.8, it works as expected. 👍

@springdoc springdoc deleted a comment from ilanr1 Feb 28, 2021
@RyanHolstien
Copy link

RyanHolstien commented Mar 12, 2021

Same, changing to 1.5.4 version in the same project correctly prevents the default page from loading.

@springdoc springdoc deleted a comment from ak185489 Apr 14, 2021
@springdoc springdoc deleted a comment from Gungrave223 Apr 14, 2021
@springdoc springdoc locked as resolved and limited conversation to collaborators Apr 14, 2021
@bnasslahsen bnasslahsen added the enhancement New feature or request label Jan 9, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants