How do you turn off swagger-ui in production

前端 未结 6 1622
孤独总比滥情好
孤独总比滥情好 2021-01-31 14:46

I have swagger plugged in to my spring boot application. Spring boot allows you to have property files for each environment that you have. Is there a way to disable swagger fo

6条回答
  •  死守一世寂寞
    2021-01-31 15:06

    This is my configuration class:

    @Configuration
    @Profile("swagger")
    @EnableSwagger2
    public class SwaggerConfig {
    
        @Value("${info.build.version}")
        private String buildVersion;
    
        @Bean
        public Docket documentation() {
            return new Docket(DocumentationType.SWAGGER_2)
                    .select()
                    .apis(RequestHandlerSelectors.any())
                    .paths(regex("/rest/.*"))
                    .build()
                    .pathMapping("/")
                    .apiInfo(metadata());
        }
    
        private ApiInfo metadata() {
            return new ApiInfoBuilder()
                    .title("API documentation of our App")
                    .description("Use this documentation as a reference how to interact with app's API")
                    .version(buildVersion)
                    .contact(new Contact("Dev-Team", "https://dev-website", "dev@mailbox"))
                    .build();
        }
    }
    

    Wherever I need Swagger, I add the profile swagger to the environment variable SPRING_PROFILES_ACTIVE

提交回复
热议问题