Это очень просто.Просто создайте один Docket для каждой версии.
Пример, первая версия:
@Bean
public Docket customImplementation(
@Value("${springfox.documentation.info.title}") String title,
@Value("${springfox.documentation.info.description}") String description) {
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo(title, description, "1.0"))
.groupName("v1")
.useDefaultResponseMessages(false)
.securitySchemes(newArrayList(apiKey()))
.pathMapping("/api")
.securityContexts(newArrayList(securityContext())).select()
.apis(e -> Objects.requireNonNull(e).produces().parallelStream()
.anyMatch(p -> "application/vnd.company.v1+json".equals(p.toString())))
.paths(PathSelectors.any())
.build();
}
А для второй версии:
@Bean
public Docket customImplementationV2(
@Value("${springfox.documentation.info.title}") String title,
@Value("${springfox.documentation.info.description}") String description) {
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo(title, description, "2.0"))
.groupName("v2")
.select()
.apis(e -> Objects.requireNonNull(e).produces()
.parallelStream()
.anyMatch(p -> "application/vnd.company.v2+json".equals(p.toString())))
.build();
}
Секрет здесь заключается в фильтрации доступныхконечные точки с атрибутом produces
.
Swagger-UI покажет две версии в комбо:
Этот коддолжен быть в классе, помеченном @Configuration
.Вам также нужно включить Swagger с @EnableSwagger2
.