如何在普通 spring 项目中将 swagger2 升级到 swagger3

how upgrade swagger2 to swagger3 in plain spring project

在我们的spring-webmvc项目中我们使用下面的代码来配置swagger2,现在我们要升级到swagger3,所以我们添加了springdoc-openapi-ui在 pom 文件中,我们需要在 swagger-configuration 文件中进行哪些更改

@Configuration
@EnableSwagger2
public class SwaggerConfiguration {
    @Bean
    public Docket api() {
        return new Docket(DocumentationType.SWAGGER_2)
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.hjk.controller"))
                .paths(PathSelectors.any())
                .build()
                .apiInfo(getApiInfo());
    }
    private ApiInfo getApiInfo() {
        return new ApiInfo(title, description, version, termsOfServiceUrl, contact, license, licenseUrl);
    }     
}

您必须删除 @EnableSwagger2 并像这样更改您的 Docket api()

@Bean
public OpenAPI customOpenAPI() {
    return new OpenAPI().info(new Info().title("SpringShop API"));}

有关更多详细信息,请参阅此文档 https://springdoc.org/#migrating-from-springfox