下面是我需要为其编写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,它也不会暴露于swagger2。无论在哪里,我都能理解问题,我认为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();
}
}