3

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?

Jeroen Kransen
  • 1,379
  • 3
  • 19
  • 45

3 Answers3

4

You can disable using below property

springfox.documentation.enabled=false
Niraj Sonawane
  • 10,225
  • 10
  • 75
  • 104
2

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.

0

If you want to remove the swagger-related resources completely, consider do it in the compile-time.

If you are using Apache Maven, it is easy to control dependencies and runtime configuration in a Maven profile, eg swagger.

When building for production, run the following command.

mvn package -Pprod

// for dev stage.
mvn clean spring-boot:run -Pdev,swagger

My example is a little old which used Maven to control different configuration in different stage.

Hantsy
  • 8,006
  • 7
  • 64
  • 109
  • Thank you, we build one package for tst/acc/prd, and on tst and acc we do want the swagger ui. Otherwise this would have worked for us. – Jeroen Kransen Mar 12 '21 at 09:21