7

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.

Vladas Maier
  • 2,054
  • 2
  • 22
  • 34
  • From what I know there is no solution for this in springfox api. Another dirty solution that worked for me: if you have access to modify `swagger-ui.html` you can sort the specs with javascript. – Jorj Nov 04 '19 at 15:17

2 Answers2

1

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
Olivier Gérardin
  • 1,113
  • 14
  • 27
0

use urls.primaryName parameter in the doc: https://github.com/swagger-api/swagger-ui/blob/v3.17.1/docs/usage/configuration.md#parameters

khejing
  • 31
  • 6
  • 1
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jan 09 '22 at 13:11