Swagger 3.0.0:在没有 SwaggerConfig 和 @Profile 的情况下无法在生产中禁用

Swagger 3.0.0: Can't disable in production without SwaggerConfig and @Profile

我正在从 2.x 升级到 SpringFox Swagger 3.0.0,它引入了 Spring 引导启动程序 springfox-boot-starter 依赖项,无需 2.x基于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();
    }
}

现在我不再需要这个 @Configuration,它允许我在 @Profile 中指定我的环境配置文件,因此在生产中禁用 Swagger,如何在 [=32] 中禁用 Swagger =]Fox Swagger-UI3.x?

注意:Spring 讨论了基于安全的方法 对于某些人来说可能是一个选项,但对于这种情况不是一个选项,原因有两个:

答案不容易找到并且不在 SpringFox 的迁移指南或文档here(应该在的地方)。

Swagger UI 3.0.0 的正确且迄今为止最佳答案是

只需将 springfox.documentation.enabled=[true|false] 添加到目标环境的 application.properties 或 application.yml。

顺便说一句,很高兴在 SpringFox 文档中看到包含所有可用 Spring 引导属性列表的部分。