From 3958c6018a6479ea47cb4897f0531fd056a974ce Mon Sep 17 00:00:00 2001 From: xiaoxie Date: Mon, 14 Feb 2022 17:59:29 +0800 Subject: [PATCH] =?UTF-8?q?refactor=20=E5=AE=8C=E5=96=84swagger=E7=9A=84?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E9=A1=B9=EF=BC=8C=E5=90=84=E6=A8=A1=E5=9D=97?= =?UTF-8?q?=E5=8F=AF=E4=BB=A5=E7=8B=AC=E7=AB=8B=E6=8C=87=E5=AE=9A=E6=A8=A1?= =?UTF-8?q?=E5=9D=97=E8=AF=B4=E6=98=8E=E4=BF=A1=E6=81=AF=EF=BC=8C=E6=9C=AA?= =?UTF-8?q?=E6=8C=87=E5=AE=9A=E9=BB=98=E8=AE=A4=E4=BD=BF=E7=94=A8=E5=85=A8?= =?UTF-8?q?=E5=B1=80=E8=AF=B4=E6=98=8E=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/resources/application.yml | 25 ++++++++--- .../ruoyi/framework/config/SwaggerConfig.java | 14 +++--- .../config/properties/SwaggerProperties.java | 43 ++++++++++++++----- 3 files changed, 58 insertions(+), 24 deletions(-) diff --git a/ruoyi-admin/src/main/resources/application.yml b/ruoyi-admin/src/main/resources/application.yml index 8c0b6e432..dcc0c020e 100644 --- a/ruoyi-admin/src/main/resources/application.yml +++ b/ruoyi-admin/src/main/resources/application.yml @@ -219,12 +219,13 @@ swagger: enabled: true # 请求前缀 pathMapping: /dev-api - # 标题 - title: '标题:${ruoyi.name}后台管理系统_接口文档' - # 描述 - description: '描述:用于管理集团旗下公司的人员信息,具体包括XXX,XXX模块...' - # 版本 - version: '版本号: ${ruoyi-vue-plus.version}' + info: + # 标题 + title: '标题:${ruoyi.name}后台管理系统_接口文档' + # 描述 + description: '描述:用于管理集团旗下公司的人员信息,具体包括XXX,XXX模块...' + # 版本 + version: '版本号: ${ruoyi-vue-plus.version}' # 作者信息 contact: name: Lion Li @@ -233,6 +234,18 @@ swagger: groups: - name: 1.演示案例 basePackage: com.ruoyi.demo + info: + # 标题 + title: '标题:${ruoyi.name}后台管理系统_案例演示' + # 描述 + description: '描述:用于演示框架各种常用功能' + # 版本 + version: '版本号: ${ruoyi-vue-plus.version}' + # 作者信息 + contact: + name: Lion Li, Xiao Xie + email: crazylionli@163.com + url: https://gitee.com/JavaLionLi/RuoYi-Vue-Plus - name: 2.系统模块 basePackage: com.ruoyi.web - name: 3.代码生成模块 diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/config/SwaggerConfig.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/config/SwaggerConfig.java index 22ef7c1b5..58efe131e 100644 --- a/ruoyi-framework/src/main/java/com/ruoyi/framework/config/SwaggerConfig.java +++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/config/SwaggerConfig.java @@ -84,7 +84,7 @@ public class SwaggerConfig { Docket docket = new Docket(DocumentationType.OAS_30) .enable(swaggerProperties.getEnabled()) // 用来创建该API的基本信息,展示在文档的页面中(自定义展示的信息) - .apiInfo(apiInfo()) + .apiInfo(apiInfo(group.getInfo(), group.getContact())) // 设置哪些接口暴露给Swagger展示 .select() // 扫描所有有注解的api,用这种方式更灵活 @@ -143,18 +143,18 @@ public class SwaggerConfig { /** * 添加摘要信息 */ - private ApiInfo apiInfo() { + private ApiInfo apiInfo(SwaggerProperties.Info info, SwaggerProperties.Contact contact) { + info = info != null ? info : swaggerProperties.getInfo(); // 用ApiInfoBuilder进行定制 - SwaggerProperties.Contact contact = swaggerProperties.getContact(); - return new ApiInfoBuilder() + contact = contact != null ? contact : swaggerProperties.getContact();return new ApiInfoBuilder() // 设置标题 - .title(swaggerProperties.getTitle()) + .title(info.getTitle()) // 描述 - .description(swaggerProperties.getDescription()) + .description(info.getDescription()) // 作者信息 .contact(new Contact(contact.getName(), contact.getUrl(), contact.getEmail())) // 版本 - .version(swaggerProperties.getVersion()) + .version(info.getVersion()) .build(); } } diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/config/properties/SwaggerProperties.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/config/properties/SwaggerProperties.java index c2b3f97b6..fac14d147 100644 --- a/ruoyi-framework/src/main/java/com/ruoyi/framework/config/properties/SwaggerProperties.java +++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/config/properties/SwaggerProperties.java @@ -18,25 +18,19 @@ import java.util.List; public class SwaggerProperties { /** - * 验证码类型 + * API文档开关 */ private Boolean enabled; + /** * 设置请求的统一前缀 */ private String pathMapping; + /** - * 验证码类别 + * 文档基本信息 */ - private String title; - /** - * 数字验证码位数 - */ - private String description; - /** - * 字符验证码长度 - */ - private String version; + private Info info; /** * 联系方式 @@ -48,6 +42,23 @@ public class SwaggerProperties { */ private List groups; + @Data + @NoArgsConstructor + public static class Info { + /** + * API文档标题 + */ + private String title = ""; + /** + * 摘要 + */ + private String description=""; + /** + * 版本 + */ + private String version=""; + } + @Data @NoArgsConstructor public static class Contact { @@ -83,6 +94,16 @@ public class SwaggerProperties { */ private String basePackage; + /** + * 模块基本信息 + */ + private Info info; + + /** + * 联系方式 + */ + private Contact contact; + } }