Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Avoiding default basic-error-controller from swagger api [duplicate]

I'm using swagger2 in my spring boot project. It's working well, but I need to exclude the basic-error-controller from the api. Currently I'm using the following code using regex. It's working but is there any perfect way to do this.

CODE :

@Bean public Docket demoApi() {     return new Docket(DocumentationType.SWAGGER_2)             .select()             .apis(RequestHandlerSelectors.any())             .paths(PathSelectors.regex('(?!/error.*).*'))             .build() } 
like image 593
Pranav C Balan Avatar asked Oct 30 '15 08:10

Pranav C Balan


People also ask

What is Springfox Swagger2?

React + Spring Boot Microservices and Spring Swagger2 is an open source project used to generate the REST API documents for RESTful web services. It provides a user interface to access our RESTful web services via the web browser.


2 Answers

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() } 
like image 181
Pranav C Balan Avatar answered Sep 28 '22 19:09

Pranav C Balan


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

like image 29
Vytautas Alkimavičius Avatar answered Sep 28 '22 18:09

Vytautas Alkimavičius