下面是我需要为其编写swagger2 API文档的控制器:
@RestController
@RequestMapping("/abc/def/pqr")
public class Controller {
@GetMapping(path = "", consumes = "application/json", produces = "application/json")
@ResponseBody
public <T> PagedResources<SomeResource> get(Pageable pageable,
Assembler assembler) {
Page<Something> somethings = service.get(pageable);
return pagedAssembler.toResource(somethings, assembler);
}
}
以下是我试图通过其编写API文档的代码:
@Bean
public Docket swaggerConfiguration() {
return new Docket(DocumentationType.SWAGGER_2)
.select()
.paths(PathSelectors.ant("/abc/def/pqr/"))
.build()
}
但即使写了它,这个API也不会暴露在招摇撞骗之下。无论在哪里,我都能理解问题,我认为PathSelectors.ant("/abc/def/pqr/"(中存在一些问题。所以,请有人帮我,这样对我更好。
提前感谢。。。
试试这个
@Configuration
@EnableSwagger2
public class SwaggerConfig {
@Bean
public Docket productApi() {
return new Docket(DocumentationType.SWAGGER_2)
.select() .apis(RequestHandlerSelectors.basePackage("your.base.package"))
.paths(regex("/product.*"))
.build();
}
}