【发布时间】:2019-11-04 14:50:51
【问题描述】:
我项目中的 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 在项目中使用。
【问题讨论】:
-
据我所知,在 springfox api 中没有解决方案。另一个对我有用的肮脏解决方案:如果您有权修改
swagger-ui.html,您可以使用 javascript 对规范进行排序。
标签: java spring-boot swagger swagger-ui springfox