Change default erorr message on swagger-ui when it is disabled

Viewed 415

I am trying to manually disable swagger, based on a flag in my application-local.properties. The code to disable is:

@Bean
Docket localApi() {
    return new Docket(DocumentationType.SWAGGER_2)
    .enable(swaggerEnabled)
    .ignoredParameterTypes(MetaClass.class, MetaMethod.class)
    .apiInfo(metaData())
    .select()
    .build()
}

swaggerEnabled is the boolean flag. This does disable the UI if the flag is false. However, when I go to http://localhost:8080/swagger-ui.html, the default message is displayed: Could not render e, see the console.

Is there any way to change that default message when the ui is disabled?

swaggerVersion = 2.9.2

springBootVersion = 2.1.3.RELEASE

springVersion = 5.0.7.RELEASE

Thanks in advance!

1 Answers

i wanted to do tha same, but i wasn't able to do it, so instead i use the ConditionalOnExpression annotation to disable swagger and the message is no longer show.

@Configuration
@ConditionalOnExpression(value = "${useSwagger:false}")
@EnableSwagger2
public class SwaggerConfig implements WebMvcConfigurer {
   ...
}
Related