我项目中的Swagger文档有多个组。每个组都有一个Docket
,并且端点(每个组的成员)都标有自定义注释。例如,这是authentication组的Docket
:
@Bean
public Docket authenticationApis() {
return new Docket(DocumentationType.SWAGGER_2)
.groupName("authentication")
.useDefaultResponseMessages(false)
.select()
.apis(RequestHandlerSelectors.withMethodAnnotation(AuthenticationApiGroup.class))
.paths(PathSelectors.any())
.build()
.apiInfo(apiInfo())
.securitySchemes(Collections.singletonList(securityScheme()))
.securityContexts(Collections.singletonList(securityContext()));
}
所有可用端点也有一个(默认)Docket
。问题是,当我调用文档URL .../swagger-ui.html
时,Swagger UI默认会加载最多的组。在我的情况下,它是authentication组,因为这些组是按字母顺序排序的。所需的行为是default组被加载为默认API组。我该如何实现?
我已经尝试用Docket
来命名默认的.groupName("all")
,因此它是最顶层的组(all <authentication),但是这种解决方案有点“脏”,在这种情况下,文档将有两个重复的组(all和default)。
Springfox 2.9.2
用于项目中。
我的快速又肮脏的骇客: