如何在Swagger UI中更改默认组/规范?

问题描述 投票:1回答:1

我项目中的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),但是这种解决方案有点“脏”,在这种情况下,文档将有两个重复的组(alldefault)。

Springfox 2.9.2用于项目中。

java spring-boot swagger swagger-ui springfox
1个回答
0
投票

我的快速又肮脏的骇客:

  • 我将“ @”放在列表的第一位(因此默认设置)
  • 我将“〜”添加到列表的末尾
© www.soinside.com 2019 - 2024. All rights reserved.