'Springboot 2.6.7, springdoc 1.6.8 i need to have v3/api-docs and v1/api-docs

I'm trying to upgrade my springboot app from 2.5.9 to 2.6.7 so i needed to migrate from springfox 3.0.0 to springdoc 1.6.8 because of many compatibility issues.

In springfox i configured in this way

springfox:
  documentation:
    swaggerUi:
      baseUrl: /documentation
    openApi:
      v3:
        path: /documentation/v3/api-docs
    swagger:
      v2:
        path: /documentation/v2/api-docs

I used v2 api-docs for other stuffs so i'd like to continue to have also a v2 documentation.

Do you know if is possible to produce v2 and v3 documentation with springdoc?

thx



Solution 1:[1]

You need to use the API Groups from Springdoc to achieve what you're looking for.

An API Group is a bean that specifies which APIs to include/exclude from a group. In your case, v2 APIs form one group while v3 APIs form another group.

The v2 bean should be defined as follows

@Bean
public GroupedOpenApi v2Apis() {
    return GroupedOpenApi.builder().group("v2 APIs")
            // show all v2 APIs. 
            .pathsToMatch("/api/v2/**", "/v2/**") // assuming you have v2 APIs which start with either of the entry in the list.
            .build();
}

and the v3 bean as follows

@Bean
public GroupedOpenApi v3Apis() {
    return GroupedOpenApi.builder().group("v3 APIs")
            // show all v3 APIs. 
            .pathsToMatch("/api/v3/**", "/v3/**") // assuming you have v3 APIs which start with either of the entry in the list.
            .build();
}

Refer to the answer here for details on how wildcards behave for the API Groups.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Debargha Roy