I build a REST interface using Spring Boot framework. Then, I use Swagger version 2.9.2 to generate the documentation. As you can see from the photo below, Swagger automatically detects a lot of models.
However, most of them are redundant. Among them, only the ResponseMessage
is necessary, the rest are just standard Java class.
So, my question is: how can I tell Swagger which models to expose?
Here are my Swagger configuration and code snippet of my controller.
@Bean
public Docket api() {
return new Docket(DocumentationType.SWAGGER_2)
.select()
.apis(RequestHandlerSelectors.basePackage("my.package"))
.paths(PathSelectors.any())
.build()
.apiInfo(API_INFO)
.useDefaultResponseMessages(false);
}
Controller:
@PostMapping(value = "/import", produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
public ResponseEntity<?> importData(HttpServletRequest request) {
// processing...
return ResponseEntity.created(uri)
.body(new ResponseMessage(HttpStatus.CREATED, "Your data is being processed"));
}