1

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

  • Springdoc doesn't seem to support swagger v2 annotations. See this for migration: https://stackoverflow.com/questions/59291371/migrating-from-springfox-swagger-2-to-springdoc-open-api – dekkard May 07 '22 at 20:37

1 Answers1

2

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.

Debargha Roy
  • 2,320
  • 1
  • 15
  • 34
  • / assuming you have v3 APIs which start with either of the entry in the list. my problem is different, i need swagger to produce both api documentation in v2 AND in v3 styled json. – Fabio Roscioli Jun 01 '22 at 12:32
  • What do you mean by "v2 and v3 styled json"? Are you referring to the OpenAPI specification version? – Debargha Roy Jun 01 '22 at 12:36
  • yes i mean that. v3: path: /documentation/v3/api-docs swagger: v2: path: /documentation/v2/api-docs as i wrote at the start. – Fabio Roscioli Jun 10 '22 at 12:19