I'm upgrading to SpringFox Swagger 3.0.0 from 2.x, which introduces the Spring Boot starter springfox-boot-starter
dependency that obviates the need for the 2.x-based SwaggerConfig
:
/**
* NO LONGER NEEDED
*/
@Configuration
@EnableSwagger2
@Profile({"local", "dev", "beta"}) // <- HOW TO DISABLE IN PROD INSTEAD OF THIS
public class SwaggerConfig {
@Bean
public Docket api() {
return new Docket(DocumentationType.SWAGGER_2)
.select()
.apis(RequestHandlerSelectors.any())
.paths(PathSelectors.any())
.build();
}
}
Now that I no longer need this @Configuration
, which allows me to specify my environment profiles in @Profile
and therefore disable Swagger in production, how do I disable Swagger in production in SpringFox Swagger-UI 3.x?
NOTE: There is Spring Security-based approached discussed here that could be an option for some, but is not an option for this scenario for two reasons:
spring-boot-security-starter
dependencyThe answer was not easy to find and was NOT in SpringFox's migration guide or documentation here (where it should be).
The CORRECT and by far best answer for Swagger UI 3.0.0 is here.
Just add springfox.documentation.enabled=[true|false]
to the target environment's application.properties or application.yml.
As an aside, it would be nice to see a section with the list of all available Spring Boot properties listed in the SpringFox doc.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With