refactor 完善swagger的配置项,各模块可以独立指定模块说明信息,未指定默认使用全局说明信息

This commit is contained in:
xiaoxie 2022-02-14 17:59:29 +08:00
parent 68a23c4918
commit 3958c6018a
3 changed files with 58 additions and 24 deletions

View File

@ -219,12 +219,13 @@ swagger:
enabled: true enabled: true
# 请求前缀 # 请求前缀
pathMapping: /dev-api pathMapping: /dev-api
# 标题 info:
title: '标题:${ruoyi.name}后台管理系统_接口文档' # 标题
# 描述 title: '标题:${ruoyi.name}后台管理系统_接口文档'
description: '描述:用于管理集团旗下公司的人员信息,具体包括XXX,XXX模块...' # 描述
# 版本 description: '描述:用于管理集团旗下公司的人员信息,具体包括XXX,XXX模块...'
version: '版本号: ${ruoyi-vue-plus.version}' # 版本
version: '版本号: ${ruoyi-vue-plus.version}'
# 作者信息 # 作者信息
contact: contact:
name: Lion Li name: Lion Li
@ -233,6 +234,18 @@ swagger:
groups: groups:
- name: 1.演示案例 - name: 1.演示案例
basePackage: com.ruoyi.demo 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.系统模块 - name: 2.系统模块
basePackage: com.ruoyi.web basePackage: com.ruoyi.web
- name: 3.代码生成模块 - name: 3.代码生成模块

View File

@ -84,7 +84,7 @@ public class SwaggerConfig {
Docket docket = new Docket(DocumentationType.OAS_30) Docket docket = new Docket(DocumentationType.OAS_30)
.enable(swaggerProperties.getEnabled()) .enable(swaggerProperties.getEnabled())
// 用来创建该API的基本信息展示在文档的页面中自定义展示的信息 // 用来创建该API的基本信息展示在文档的页面中自定义展示的信息
.apiInfo(apiInfo()) .apiInfo(apiInfo(group.getInfo(), group.getContact()))
// 设置哪些接口暴露给Swagger展示 // 设置哪些接口暴露给Swagger展示
.select() .select()
// 扫描所有有注解的api用这种方式更灵活 // 扫描所有有注解的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进行定制 // 用ApiInfoBuilder进行定制
SwaggerProperties.Contact contact = swaggerProperties.getContact(); contact = contact != null ? contact : swaggerProperties.getContact();return new ApiInfoBuilder()
return new ApiInfoBuilder()
// 设置标题 // 设置标题
.title(swaggerProperties.getTitle()) .title(info.getTitle())
// 描述 // 描述
.description(swaggerProperties.getDescription()) .description(info.getDescription())
// 作者信息 // 作者信息
.contact(new Contact(contact.getName(), contact.getUrl(), contact.getEmail())) .contact(new Contact(contact.getName(), contact.getUrl(), contact.getEmail()))
// 版本 // 版本
.version(swaggerProperties.getVersion()) .version(info.getVersion())
.build(); .build();
} }
} }

View File

@ -18,25 +18,19 @@ import java.util.List;
public class SwaggerProperties { public class SwaggerProperties {
/** /**
* 验证码类型 * API文档开关
*/ */
private Boolean enabled; private Boolean enabled;
/** /**
* 设置请求的统一前缀 * 设置请求的统一前缀
*/ */
private String pathMapping; private String pathMapping;
/** /**
* 验证码类别 * 文档基本信息
*/ */
private String title; private Info info;
/**
* 数字验证码位数
*/
private String description;
/**
* 字符验证码长度
*/
private String version;
/** /**
* 联系方式 * 联系方式
@ -48,6 +42,23 @@ public class SwaggerProperties {
*/ */
private List<Groups> groups; private List<Groups> groups;
@Data
@NoArgsConstructor
public static class Info {
/**
* API文档标题
*/
private String title = "";
/**
* 摘要
*/
private String description="";
/**
* 版本
*/
private String version="";
}
@Data @Data
@NoArgsConstructor @NoArgsConstructor
public static class Contact { public static class Contact {
@ -83,6 +94,16 @@ public class SwaggerProperties {
*/ */
private String basePackage; private String basePackage;
/**
* 模块基本信息
*/
private Info info;
/**
* 联系方式
*/
private Contact contact;
} }
} }