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



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

中做什么更改?
@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。

最新更新