diff --git a/openhis-server-new/core-admin/pom.xml b/openhis-server-new/core-admin/pom.xml index bb096d31f..fbd1d11fa 100755 --- a/openhis-server-new/core-admin/pom.xml +++ b/openhis-server-new/core-admin/pom.xml @@ -31,16 +31,10 @@ lombok - + - io.springfox - springfox-boot-starter - - - - - io.swagger - swagger-models + org.springdoc + springdoc-openapi-ui diff --git a/openhis-server-new/core-admin/src/main/java/com/core/web/core/config/SwaggerConfig.java b/openhis-server-new/core-admin/src/main/java/com/core/web/core/config/SwaggerConfig.java index 61c499d33..ccb233e42 100755 --- a/openhis-server-new/core-admin/src/main/java/com/core/web/core/config/SwaggerConfig.java +++ b/openhis-server-new/core-admin/src/main/java/com/core/web/core/config/SwaggerConfig.java @@ -1,26 +1,20 @@ package com.core.web.core.config; import com.core.common.config.CoreConfig; -import io.swagger.annotations.ApiOperation; -import io.swagger.models.auth.In; +import io.swagger.v3.oas.models.Components; +import io.swagger.v3.oas.models.OpenAPI; +import io.swagger.v3.oas.models.info.Contact; +import io.swagger.v3.oas.models.info.Info; +import io.swagger.v3.oas.models.security.SecurityRequirement; +import io.swagger.v3.oas.models.security.SecurityScheme; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import springfox.documentation.builders.ApiInfoBuilder; -import springfox.documentation.builders.PathSelectors; -import springfox.documentation.builders.RequestHandlerSelectors; -import springfox.documentation.service.*; -import springfox.documentation.spi.DocumentationType; -import springfox.documentation.spi.service.contexts.SecurityContext; -import springfox.documentation.spring.web.plugins.Docket; - -import java.util.ArrayList; -import java.util.List; /** - * Swagger2的接口配置 - * + * Springdoc OpenAPI 配置 (替代 Springfox) + * * @author system */ @Configuration @@ -30,79 +24,29 @@ public class SwaggerConfig { private CoreConfig coreConfig; /** 是否开启swagger */ - @Value("${swagger.enabled}") + @Value("${springdoc.api-docs.enabled:true}") private boolean enabled; - /** 设置请求的统一前缀 */ - @Value("${swagger.pathMapping}") - private String pathMapping; - - /** - * 创建API - */ @Bean - public Docket createRestApi() { - return new Docket(DocumentationType.OAS_30) - // 是否启用Swagger - .enable(enabled) - // 用来创建该API的基本信息,展示在文档的页面中(自定义展示的信息) - .apiInfo(apiInfo()) - // 设置哪些接口暴露给Swagger展示 - .select() - // 扫描所有有注解的api,用这种方式更灵活 - .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class)) - // 扫描指定包中的swagger注解 - // .apis(RequestHandlerSelectors.basePackage("com.core.project.tool.swagger")) - // 扫描所有 .apis(RequestHandlerSelectors.any()) - .paths(PathSelectors.any()).build() - /* 设置安全模式,swagger可以设置访问token */ - .securitySchemes(securitySchemes()).securityContexts(securityContexts()).pathMapping(pathMapping); + public OpenAPI openAPI() { + return new OpenAPI() + .info(apiInfo()) + .schemaRequirement("Authorization", + new SecurityScheme() + .type(SecurityScheme.Type.HTTP) + .scheme("bearer") + .bearerFormat("JWT")) + .addSecurityItem(new SecurityRequirement().addList("Authorization")); } /** - * 安全模式,这里指定token通过Authorization头请求头传递 + * API 基本信息 */ - private List securitySchemes() { - List apiKeyList = new ArrayList(); - apiKeyList.add(new ApiKey("Authorization", "Authorization", In.HEADER.toValue())); - return apiKeyList; - } - - /** - * 安全上下文 - */ - private List securityContexts() { - List securityContexts = new ArrayList<>(); - securityContexts.add(SecurityContext.builder().securityReferences(defaultAuth()) - .operationSelector(o -> o.requestMappingPattern().matches("/.*")).build()); - return securityContexts; - } - - /** - * 默认的安全上引用 - */ - private List defaultAuth() { - AuthorizationScope authorizationScope = new AuthorizationScope("global", "accessEverything"); - AuthorizationScope[] authorizationScopes = new AuthorizationScope[1]; - authorizationScopes[0] = authorizationScope; - List securityReferences = new ArrayList<>(); - securityReferences.add(new SecurityReference("Authorization", authorizationScopes)); - return securityReferences; - } - - /** - * 添加摘要信息 - */ - private ApiInfo apiInfo() { - // 用ApiInfoBuilder进行定制 - return new ApiInfoBuilder() - // 设置标题 - .title("标题:开放医院管理系统_接口文档") - // 描述 - .description("描述:用于管理集团旗下公司的人员信息,具体包括XXX,XXX模块...") - // 作者信息 - .contact(new Contact(coreConfig.getName(), null, null)) - // 版本 - .version("版本号:" + coreConfig.getVersion()).build(); + private Info apiInfo() { + return new Info() + .title("开放医院管理系统 - 接口文档") + .description("OpenHIS API 文档,基于 Springdoc OpenAPI 3.0") + .contact(new Contact().name(coreConfig.getName())) + .version("版本号: " + coreConfig.getVersion()); } } diff --git a/openhis-server-new/core-framework/src/main/java/com/core/framework/config/ResourcesConfig.java b/openhis-server-new/core-framework/src/main/java/com/core/framework/config/ResourcesConfig.java index cfbd421af..67091fb38 100755 --- a/openhis-server-new/core-framework/src/main/java/com/core/framework/config/ResourcesConfig.java +++ b/openhis-server-new/core-framework/src/main/java/com/core/framework/config/ResourcesConfig.java @@ -6,7 +6,6 @@ import com.core.framework.interceptor.RepeatSubmitInterceptor; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import org.springframework.http.CacheControl; import org.springframework.web.cors.CorsConfiguration; import org.springframework.web.cors.UrlBasedCorsConfigurationSource; import org.springframework.web.filter.CorsFilter; @@ -14,7 +13,6 @@ import org.springframework.web.servlet.config.annotation.InterceptorRegistry; import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; -import java.util.concurrent.TimeUnit; /** * 通用配置 @@ -32,10 +30,7 @@ public class ResourcesConfig implements WebMvcConfigurer { registry.addResourceHandler(Constants.RESOURCE_PREFIX + "/**") .addResourceLocations("file:" + CoreConfig.getProfile() + "/"); - /** swagger配置 */ - registry.addResourceHandler("/swagger-ui/**") - .addResourceLocations("classpath:/META-INF/resources/webjars/springfox-swagger-ui/") - .setCacheControl(CacheControl.maxAge(5, TimeUnit.HOURS).cachePublic()); + /** springdoc UI 由 springdoc-openapi 自动提供,无需手动配置 */ } /** diff --git a/openhis-server-new/openhis-application/src/main/resources/application.yml b/openhis-server-new/openhis-application/src/main/resources/application.yml index c960e9945..b3d0ab777 100755 --- a/openhis-server-new/openhis-application/src/main/resources/application.yml +++ b/openhis-server-new/openhis-application/src/main/resources/application.yml @@ -110,17 +110,15 @@ pagehelper: # 默认值为 false。设置为 true 时,允许在运行时根据多数据源自动识别对应方言的分页 auto-runtime-dialect: true -# Swagger配置 -# 禁用 Springfox (与 Spring Boot 2.7 不兼容, 后续迁移至 springdoc) -springfox: - documentation: - enabled: false - -swagger: - # 是否开启swagger - enabled: true - # 请求前缀 - pathMapping: /dev-api +# Springdoc OpenAPI 配置 (替代 Springfox) +springdoc: + api-docs: + enabled: true + swagger-ui: + enabled: true + tags-sorter: alpha + operations-sorter: alpha + packages-to-scan: com.core.web,com.openhis.web # 防止XSS攻击 xss: diff --git a/openhis-server-new/openhis-domain/src/main/java/com/openhis/appointmentmanage/service/ISchedulePoolService.java b/openhis-server-new/openhis-domain/src/main/java/com/openhis/appointmentmanage/service/ISchedulePoolService.java index 228f1f55a..8463e1ddc 100755 --- a/openhis-server-new/openhis-domain/src/main/java/com/openhis/appointmentmanage/service/ISchedulePoolService.java +++ b/openhis-server-new/openhis-domain/src/main/java/com/openhis/appointmentmanage/service/ISchedulePoolService.java @@ -2,7 +2,6 @@ package com.openhis.appointmentmanage.service; import com.baomidou.mybatisplus.extension.service.IService; import com.openhis.appointmentmanage.domain.SchedulePool; -import io.swagger.models.auth.In; public interface ISchedulePoolService extends IService { /** diff --git a/openhis-server-new/pom.xml b/openhis-server-new/pom.xml index 57e8d074d..b4e018f1c 100755 --- a/openhis-server-new/pom.xml +++ b/openhis-server-new/pom.xml @@ -28,7 +28,7 @@ 3.1.1 1.2.28 1.21 - 3.0.0 + 1.8.0 2.3.3 2.1.1 6.10.0 @@ -268,15 +268,9 @@ - io.springfox - springfox-boot-starter - ${swagger.version} - - - io.swagger - swagger-models - - + org.springdoc + springdoc-openapi-ui + ${springdoc.version}