Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change the default group / specification in Swagger UI?

The Swagger documentation in my project has multiple groups. There is a Docket for each group and the endpoints (members of each group) are marked with a custom annotation. For example here is the Docket for authentication group:

@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()));
}

There is also a (default) Docket for all available endpoints. The problem is that Swagger UI loads the most top group on default when I am calling the documentation URL .../swagger-ui.html. In my case it is the authentication group, since the groups are sorted alphabetically. The desired behaviour is that the default group is loaded as the default API group. How could I achieve that?

I have tried to name the default Docket with the .groupName("all") so it's the most top group (all < authentication) but this solution is a bit "dirty" and in this case the documentation would have two duplicate groups (all and default).

Springfox 2.9.2 is used in the project.

like image 620
Vladas Maier Avatar asked Nov 07 '22 12:11

Vladas Maier


1 Answers

My quick-and dirty hack:

  • I prepend "@" to make a group first in the list (hence default)
  • I prepend "~" to make a group last in the list
like image 150
Olivier Gérardin Avatar answered Nov 12 '22 14:11

Olivier Gérardin