Avoiding default basic-error-controller from swagger api

I encountered the same problem. I did this.

java
@Bean
public Docket api() {
    return new Docket(DocumentationType.SWAGGER_2)
            .select()
            .apis(RequestHandlerSelectors.basePackage("com.xxx.xxx"))
            .paths(PathSelectors.any())
            .build();
}

After searching in google I got the solution from one issue in GitHub, [question] How to exclude the basic-error-controller from being added to the swagger description?. It can be done using Predicates.not().

Code looks like as follows after using Predicates.not().

@Bean
public Docket demoApi() {
    return new Docket(DocumentationType.SWAGGER_2)//<3>
            .select()//<4>
            .apis(RequestHandlerSelectors.any())//<5>
            .paths(Predicates.not(PathSelectors.regex("/error.*")))//<6>, regex must be in double quotes.
            .build()
}

Lot's of time gone by, but if someone has same problem you could do it by providing selector for RestController:

new Docket(SWAGGER_2)
                .select()
                .apis(RequestHandlerSelectors.withClassAnnotation(RestController.class))
                .paths(PathSelectors.any())
                .build();

Keeping in mind that your controllers are annotated with @RestController