Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SpringFox Boot starter: How to disable swagger-ui for production profile?

I am using the io.springfox springfox-boot-starter v 3.0.0,

According to the documentation, this Spring Boot setup would disable the swagger endpoint for prod:

@Configuration
@Profile({"!prod && swagger"})
public class SwaggerConfig implements WebMvcConfigurer {

    @Bean
    public Docket api() {
        return new Docket(DocumentationType.SWAGGER_2)
                .useDefaultResponseMessages(false)
                .select()
                .apis(RequestHandlerSelectors.any())
                .build()
                .apiInfo(apiInfo());
    }

...

When on prod, the customisations of swagger defined here are indeed missing, but the Swagger UI endpoint is still there. How can I suppress the /swagger-ui/ endpoint altogether? Is there nothing like a springfox.swagger-ui.enabled=false property I can set somewhere in the spring boot application configuration?

like image 496
Jeroen Kransen Avatar asked Oct 22 '25 04:10

Jeroen Kransen


2 Answers

You can disable using below property

springfox.documentation.enabled=false
like image 63
Niraj Sonawane Avatar answered Oct 26 '25 11:10

Niraj Sonawane


Springfox Boot Starter API enable by default the 'auto-startup' configuration, means Swagger UI html page (ex. /swagger-ui/index.html) and Api-Docs (/v2/api-docs) JSON page containing a swagger with All API definitions.

For production environment is a good choise disable all the API documentation.

To disable all the swagger auto-configurations you can add on your application-prod.properties file the property below:

springfox.documentation.auto-startup=false

In this case with Your config on prod you have nothing about swagger.

like image 22
salvatore rinaudo Avatar answered Oct 26 '25 10:10

salvatore rinaudo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!