Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove Basic Error Controller In SpringFox SwaggerUI

Is there a way i can remove the "basic-error-controller" from springfox swagger-ui?

Picture:

enter image description here

like image 930
Rajkishan Swami Avatar asked Oct 05 '15 05:10

Rajkishan Swami


People also ask

How do I hide models in Swagger UI?

To hide the "Models" section, add defaultModelsExpandDepth: -1 to the Swagger UI configuration code in your index. html . Note the option name uses plural Model*s* not Model . Swagger UI also has many other configuration options that control API documentation rendering.

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

You can restrict the request handler selector to scan only the package of your project:

    return new Docket( DocumentationType.SWAGGER_2)         .select()         .apis( RequestHandlerSelectors.basePackage( "your package" ) )         ... 
like image 128
Carsten Zeitz Avatar answered Sep 21 '22 09:09

Carsten Zeitz


I think, the most elegant solution is to include only @RestController controllers into swagger, only thing to bear in mind, is to annotate all the REST controllers with that annotation:

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

As BasicErrorController is annotated with @Controller only, swagger would avoid BasicErrorController in definition file. Of course you can use your custom annotation instead of @RestController to mark your REST controllers as controllers eligible by swagger.

like image 40
bladekp Avatar answered Sep 22 '22 09:09

bladekp