In my spring boot application, I have multiple Rest Controllers and need to generate swagger for each controller seperately.
By using below Docket config for each controller in my spring boot application class, i am able to download controller specific swagger by going to /v2/api-docs?group=ai where i = 1 to n
However in swagger-ui.html, when i select a1(/v2/api-docs?group=a1), it shows path as "/api/a1/a1", while selecting a2(/v2/api-docs?greoup=a2), it shows correct path i.e. /api/a2
I have tried changing in Docket ,paths regex to absolute e.g. "api/a1" etc but that didn't help.
@Bean
public Docket a1Api() {
return new Docket(DocumentationType.SWAGGER_2)
.groupName("a1")
.apiInfo(a1Info())
.select().apis(RequestHandlerSelectors.any())
.paths(regex("/api/a1.*"))
.build()
.pathMapping("/");
}
@Bean
public Docket a2Api() {
return new Docket(DocumentationType.SWAGGER_2)
.groupName("a2")
.apiInfo(a1Info())
.select().apis(RequestHandlerSelectors.any())
.paths(regex("/api/a2.*"))
.build()
.pathMapping("/");
}
private ApiInfo a1Info() {
return new ApiInfoBuilder()
.title("a1 Swagger 2.0")
.description("a1")
.license("a1")
.version("1.0")
.build();
}
private ApiInfo a2Info() {
return new ApiInfoBuilder()
.title("a2 Swagger 2.0")
.description("a2")
.license("a2")
.version("1.0")
.build();
}
Rest Controllers
@RestController
@Api(tags = "A1")
@RequestMapping("/api/a1")
public class a1Controller {
@ApiOperation(value = "a1")
@RequestMapping(value = "", method = RequestMethod.POST)
public a1Response invoke(@RequestBody a1Request va1Request) {
.....;
}
}
@RestController
@Api(tags = "An")
@RequestMapping("/api/an")
public class a1Controller {
@ApiOperation(value = "an")
@RequestMapping(value = "", method = RequestMethod.POST)
public anResponse invoke(@RequestBody anRequest vanRequest) {
.....;
}
}
Any idea how can i address this....
i am using springfox swagger version 2.6.1
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…