init
This commit is contained in:
@@ -135,9 +135,12 @@ security:
|
|||||||
# swagger 文档配置
|
# swagger 文档配置
|
||||||
- /*/api-docs
|
- /*/api-docs
|
||||||
- /*/api-docs/**
|
- /*/api-docs/**
|
||||||
|
- /doc.html
|
||||||
|
- /swagger-resources/**
|
||||||
|
- /webjars/**
|
||||||
# actuator 监控配置
|
# actuator 监控配置
|
||||||
- /actuator
|
# - /actuator
|
||||||
- /actuator/**
|
# - /actuator/**
|
||||||
|
|
||||||
# MyBatisPlus配置
|
# MyBatisPlus配置
|
||||||
# https://baomidou.com/config/
|
# https://baomidou.com/config/
|
||||||
@@ -201,36 +204,15 @@ springdoc:
|
|||||||
api-docs:
|
api-docs:
|
||||||
# 是否开启接口文档
|
# 是否开启接口文档
|
||||||
enabled: true
|
enabled: true
|
||||||
# swagger-ui:
|
swagger-ui:
|
||||||
# # 持久化认证数据
|
path: /swagger-ui.html
|
||||||
# persistAuthorization: true
|
tags-sorter: alpha
|
||||||
info:
|
operations-sorter: alpha
|
||||||
# 标题
|
|
||||||
title: '标题:${ruoyi.name}后台管理系统_接口文档'
|
|
||||||
# 描述
|
|
||||||
description: '描述:用于管理集团旗下公司的人员信息,具体包括XXX,XXX模块...'
|
|
||||||
# 版本
|
|
||||||
version: '版本号: ${ruoyi-vue-plus.version}'
|
|
||||||
# 作者信息
|
|
||||||
contact:
|
|
||||||
name: Lion Li
|
|
||||||
email: crazylionli@163.com
|
|
||||||
url: https://gitee.com/dromara/RuoYi-Vue-Plus
|
|
||||||
components:
|
|
||||||
# 鉴权方式配置
|
|
||||||
security-schemes:
|
|
||||||
apiKey:
|
|
||||||
type: APIKEY
|
|
||||||
in: HEADER
|
|
||||||
name: ${sa-token.token-name}
|
|
||||||
#这里定义了两个分组,可定义多个,也可以不定义
|
#这里定义了两个分组,可定义多个,也可以不定义
|
||||||
group-configs:
|
group-configs:
|
||||||
- group: 1.演示模块
|
- group: 'default'
|
||||||
packages-to-scan: com.ruoyi.demo
|
paths-to-match: '/api/**'
|
||||||
- group: 2.系统模块
|
packages-to-scan: com.ruoyi.cai
|
||||||
packages-to-scan: com.ruoyi.web
|
|
||||||
- group: 3.代码生成模块
|
|
||||||
packages-to-scan: com.ruoyi.generator
|
|
||||||
|
|
||||||
# 防止XSS攻击
|
# 防止XSS攻击
|
||||||
xss:
|
xss:
|
||||||
|
|||||||
@@ -12,15 +12,16 @@ import com.ruoyi.cai.service.CaiUserGiftService;
|
|||||||
import com.ruoyi.common.core.domain.PageQuery;
|
import com.ruoyi.common.core.domain.PageQuery;
|
||||||
import com.ruoyi.common.core.domain.R;
|
import com.ruoyi.common.core.domain.R;
|
||||||
import com.ruoyi.common.core.page.TableDataInfo;
|
import com.ruoyi.common.core.page.TableDataInfo;
|
||||||
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
|
import io.swagger.v3.oas.annotations.Parameter;
|
||||||
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
|
||||||
|
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/api/anchor")
|
@RequestMapping("/api/anchor")
|
||||||
|
@Tag(name = "主播相关接口")
|
||||||
public class CaiAnchorAppController {
|
public class CaiAnchorAppController {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
@@ -31,19 +32,23 @@ public class CaiAnchorAppController {
|
|||||||
private CaiUserGiftService userGiftService;
|
private CaiUserGiftService userGiftService;
|
||||||
|
|
||||||
@GetMapping("/page")
|
@GetMapping("/page")
|
||||||
public TableDataInfo<AnchorListVo> page(PageQuery page, AnchorListQuery query){
|
@Operation(summary = "查询主播-分页")
|
||||||
|
public TableDataInfo<AnchorListVo> page(@Parameter(description = "name") PageQuery page,
|
||||||
|
@Parameter(description = "name2") AnchorListQuery query){
|
||||||
Page<AnchorListVo> res = anchorService.pageApp(page,query);
|
Page<AnchorListVo> res = anchorService.pageApp(page,query);
|
||||||
return TableDataInfo.build(res);
|
return TableDataInfo.build(res);
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/give/guard")
|
@PostMapping("/give/guard")
|
||||||
public R<Boolean> giveGuard(GiveGuardRes query){
|
@Operation(summary = "赠送主播守护")
|
||||||
|
public R<Boolean> giveGuard(@RequestBody GiveGuardRes query){
|
||||||
boolean res = guardTotalService.giveGuard(query);
|
boolean res = guardTotalService.giveGuard(query);
|
||||||
return R.ok(res);
|
return R.ok(res);
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/give/gift")
|
@PostMapping("/give/gift")
|
||||||
public R<Boolean> giveGift(GiveGiftRes query){
|
@Operation(summary = "赠送主播礼物")
|
||||||
|
public R<Boolean> giveGift(@RequestBody GiveGiftRes query){
|
||||||
boolean res = userGiftService.giveGift(query);
|
boolean res = userGiftService.giveGift(query);
|
||||||
return R.ok(res);
|
return R.ok(res);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
package com.ruoyi.cai.dto.app.query;
|
package com.ruoyi.cai.dto.app.query;
|
||||||
|
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
|
@Schema(description = "主播查询条件")
|
||||||
public class AnchorListQuery {
|
public class AnchorListQuery {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -11,7 +13,9 @@ public class AnchorListQuery {
|
|||||||
* 2-新人查询
|
* 2-新人查询
|
||||||
* 3-同城查询
|
* 3-同城查询
|
||||||
*/
|
*/
|
||||||
|
@Schema(description = "类型")
|
||||||
private Integer type;
|
private Integer type;
|
||||||
|
|
||||||
|
@Schema(description = "城市")
|
||||||
private String city;
|
private String city;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,15 @@
|
|||||||
package com.ruoyi.cai.dto.app.query;
|
package com.ruoyi.cai.dto.app.query;
|
||||||
|
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
|
@Schema(description = "赠送守护入参")
|
||||||
public class GiveGuardRes {
|
public class GiveGuardRes {
|
||||||
|
|
||||||
|
@Schema(description = "接收方用户ID")
|
||||||
private Long toUserId;
|
private Long toUserId;
|
||||||
|
|
||||||
|
@Schema(description = "赠送数量")
|
||||||
private Long guardNum;
|
private Long guardNum;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -120,17 +120,6 @@
|
|||||||
<groupId>org.projectlombok</groupId>
|
<groupId>org.projectlombok</groupId>
|
||||||
<artifactId>lombok</artifactId>
|
<artifactId>lombok</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.springdoc</groupId>
|
|
||||||
<artifactId>springdoc-openapi-webmvc-core</artifactId>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.springdoc</groupId>
|
|
||||||
<artifactId>springdoc-openapi-javadoc</artifactId>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<!-- 自动生成YML配置关联JSON文件 -->
|
<!-- 自动生成YML配置关联JSON文件 -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
@@ -159,6 +148,12 @@
|
|||||||
<artifactId>bcprov-jdk15to18</artifactId>
|
<artifactId>bcprov-jdk15to18</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.github.xiaoymin</groupId>
|
||||||
|
<artifactId>knife4j-openapi3-spring-boot-starter</artifactId>
|
||||||
|
<version>4.1.0</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<!-- 离线IP地址定位库 -->
|
<!-- 离线IP地址定位库 -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.lionsoul</groupId>
|
<groupId>org.lionsoul</groupId>
|
||||||
@@ -168,7 +163,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.google.guava</groupId>
|
<groupId>com.google.guava</groupId>
|
||||||
<artifactId>guava</artifactId>
|
<artifactId>guava</artifactId>
|
||||||
<version>23.0</version>
|
<version>27.0.1-jre</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|||||||
import com.ruoyi.common.exception.ServiceException;
|
import com.ruoyi.common.exception.ServiceException;
|
||||||
import com.ruoyi.common.utils.StringUtils;
|
import com.ruoyi.common.utils.StringUtils;
|
||||||
import com.ruoyi.common.utils.sql.SqlUtil;
|
import com.ruoyi.common.utils.sql.SqlUtil;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
@@ -20,6 +21,7 @@ import java.util.List;
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
|
@Schema(description = "分页实体")
|
||||||
public class PageQuery implements Serializable {
|
public class PageQuery implements Serializable {
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
@@ -27,21 +29,25 @@ public class PageQuery implements Serializable {
|
|||||||
/**
|
/**
|
||||||
* 分页大小
|
* 分页大小
|
||||||
*/
|
*/
|
||||||
|
@Schema(description = "分页大小")
|
||||||
private Integer pageSize;
|
private Integer pageSize;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 当前页数
|
* 当前页数
|
||||||
*/
|
*/
|
||||||
|
@Schema(description = "页数")
|
||||||
private Integer pageNum;
|
private Integer pageNum;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 排序列
|
* 排序列
|
||||||
*/
|
*/
|
||||||
|
@Schema(accessMode = Schema.AccessMode.READ_ONLY)
|
||||||
private String orderByColumn;
|
private String orderByColumn;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 排序的方向desc或者asc
|
* 排序的方向desc或者asc
|
||||||
*/
|
*/
|
||||||
|
@Schema(accessMode = Schema.AccessMode.READ_ONLY)
|
||||||
private String isAsc;
|
private String isAsc;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,122 +0,0 @@
|
|||||||
package com.ruoyi.framework.config;
|
|
||||||
|
|
||||||
import com.ruoyi.common.utils.StringUtils;
|
|
||||||
import com.ruoyi.framework.config.properties.SpringDocProperties;
|
|
||||||
import com.ruoyi.framework.handler.OpenApiHandler;
|
|
||||||
import io.swagger.v3.oas.models.OpenAPI;
|
|
||||||
import io.swagger.v3.oas.models.Paths;
|
|
||||||
import io.swagger.v3.oas.models.info.Info;
|
|
||||||
import io.swagger.v3.oas.models.security.SecurityRequirement;
|
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
import org.springdoc.core.*;
|
|
||||||
import org.springdoc.core.customizers.OpenApiBuilderCustomizer;
|
|
||||||
import org.springdoc.core.customizers.OpenApiCustomiser;
|
|
||||||
import org.springdoc.core.customizers.ServerBaseUrlCustomizer;
|
|
||||||
import org.springdoc.core.providers.JavadocProvider;
|
|
||||||
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
|
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
|
||||||
import org.springframework.boot.autoconfigure.web.ServerProperties;
|
|
||||||
import org.springframework.context.annotation.Bean;
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Optional;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Swagger 文档配置
|
|
||||||
*
|
|
||||||
* @author Lion Li
|
|
||||||
*/
|
|
||||||
@RequiredArgsConstructor
|
|
||||||
@Configuration
|
|
||||||
@AutoConfigureBefore(SpringDocConfiguration.class)
|
|
||||||
@ConditionalOnProperty(name = "springdoc.api-docs.enabled", havingValue = "true", matchIfMissing = true)
|
|
||||||
public class SpringDocConfig {
|
|
||||||
|
|
||||||
private final ServerProperties serverProperties;
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
@ConditionalOnMissingBean(OpenAPI.class)
|
|
||||||
public OpenAPI openApi(SpringDocProperties properties) {
|
|
||||||
OpenAPI openApi = new OpenAPI();
|
|
||||||
// 文档基本信息
|
|
||||||
SpringDocProperties.InfoProperties infoProperties = properties.getInfo();
|
|
||||||
Info info = convertInfo(infoProperties);
|
|
||||||
openApi.info(info);
|
|
||||||
// 扩展文档信息
|
|
||||||
openApi.externalDocs(properties.getExternalDocs());
|
|
||||||
openApi.tags(properties.getTags());
|
|
||||||
openApi.paths(properties.getPaths());
|
|
||||||
openApi.components(properties.getComponents());
|
|
||||||
Set<String> keySet = properties.getComponents().getSecuritySchemes().keySet();
|
|
||||||
List<SecurityRequirement> list = new ArrayList<>();
|
|
||||||
SecurityRequirement securityRequirement = new SecurityRequirement();
|
|
||||||
keySet.forEach(securityRequirement::addList);
|
|
||||||
list.add(securityRequirement);
|
|
||||||
openApi.security(list);
|
|
||||||
|
|
||||||
return openApi;
|
|
||||||
}
|
|
||||||
|
|
||||||
private Info convertInfo(SpringDocProperties.InfoProperties infoProperties) {
|
|
||||||
Info info = new Info();
|
|
||||||
info.setTitle(infoProperties.getTitle());
|
|
||||||
info.setDescription(infoProperties.getDescription());
|
|
||||||
info.setContact(infoProperties.getContact());
|
|
||||||
info.setLicense(infoProperties.getLicense());
|
|
||||||
info.setVersion(infoProperties.getVersion());
|
|
||||||
return info;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 自定义 openapi 处理器
|
|
||||||
*/
|
|
||||||
@Bean
|
|
||||||
public OpenAPIService openApiBuilder(Optional<OpenAPI> openAPI,
|
|
||||||
SecurityService securityParser,
|
|
||||||
SpringDocConfigProperties springDocConfigProperties, PropertyResolverUtils propertyResolverUtils,
|
|
||||||
Optional<List<OpenApiBuilderCustomizer>> openApiBuilderCustomisers,
|
|
||||||
Optional<List<ServerBaseUrlCustomizer>> serverBaseUrlCustomisers, Optional<JavadocProvider> javadocProvider) {
|
|
||||||
return new OpenApiHandler(openAPI, securityParser, springDocConfigProperties, propertyResolverUtils, openApiBuilderCustomisers, serverBaseUrlCustomisers, javadocProvider);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 对已经生成好的 OpenApi 进行自定义操作
|
|
||||||
*/
|
|
||||||
@Bean
|
|
||||||
public OpenApiCustomiser openApiCustomiser() {
|
|
||||||
String contextPath = serverProperties.getServlet().getContextPath();
|
|
||||||
String finalContextPath;
|
|
||||||
if (StringUtils.isBlank(contextPath) || "/".equals(contextPath)) {
|
|
||||||
finalContextPath = "";
|
|
||||||
} else {
|
|
||||||
finalContextPath = contextPath;
|
|
||||||
}
|
|
||||||
// 对所有路径增加前置上下文路径
|
|
||||||
return openApi -> {
|
|
||||||
Paths oldPaths = openApi.getPaths();
|
|
||||||
if (oldPaths instanceof PlusPaths) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
PlusPaths newPaths = new PlusPaths();
|
|
||||||
oldPaths.forEach((k,v) -> newPaths.addPathItem(finalContextPath + k, v));
|
|
||||||
openApi.setPaths(newPaths);
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 单独使用一个类便于判断 解决springdoc路径拼接重复问题
|
|
||||||
*
|
|
||||||
* @author Lion Li
|
|
||||||
*/
|
|
||||||
static class PlusPaths extends Paths {
|
|
||||||
|
|
||||||
public PlusPaths() {
|
|
||||||
super();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,96 +0,0 @@
|
|||||||
package com.ruoyi.framework.config.properties;
|
|
||||||
|
|
||||||
import io.swagger.v3.oas.models.Components;
|
|
||||||
import io.swagger.v3.oas.models.ExternalDocumentation;
|
|
||||||
import io.swagger.v3.oas.models.Paths;
|
|
||||||
import io.swagger.v3.oas.models.info.Contact;
|
|
||||||
import io.swagger.v3.oas.models.info.License;
|
|
||||||
import io.swagger.v3.oas.models.tags.Tag;
|
|
||||||
import lombok.Data;
|
|
||||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
|
||||||
import org.springframework.boot.context.properties.NestedConfigurationProperty;
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* swagger 配置属性
|
|
||||||
*
|
|
||||||
* @author Lion Li
|
|
||||||
*/
|
|
||||||
@Data
|
|
||||||
@Component
|
|
||||||
@ConfigurationProperties(prefix = "springdoc")
|
|
||||||
public class SpringDocProperties {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 文档基本信息
|
|
||||||
*/
|
|
||||||
@NestedConfigurationProperty
|
|
||||||
private InfoProperties info = new InfoProperties();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 扩展文档地址
|
|
||||||
*/
|
|
||||||
@NestedConfigurationProperty
|
|
||||||
private ExternalDocumentation externalDocs;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 标签
|
|
||||||
*/
|
|
||||||
private List<Tag> tags = null;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 路径
|
|
||||||
*/
|
|
||||||
@NestedConfigurationProperty
|
|
||||||
private Paths paths = null;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 组件
|
|
||||||
*/
|
|
||||||
@NestedConfigurationProperty
|
|
||||||
private Components components = null;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* <p>
|
|
||||||
* 文档的基础属性信息
|
|
||||||
* </p>
|
|
||||||
*
|
|
||||||
* @see io.swagger.v3.oas.models.info.Info
|
|
||||||
*
|
|
||||||
* 为了 springboot 自动生产配置提示信息,所以这里复制一个类出来
|
|
||||||
*/
|
|
||||||
@Data
|
|
||||||
public static class InfoProperties {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 标题
|
|
||||||
*/
|
|
||||||
private String title = null;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 描述
|
|
||||||
*/
|
|
||||||
private String description = null;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 联系人信息
|
|
||||||
*/
|
|
||||||
@NestedConfigurationProperty
|
|
||||||
private Contact contact = null;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 许可证
|
|
||||||
*/
|
|
||||||
@NestedConfigurationProperty
|
|
||||||
private License license = null;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 版本
|
|
||||||
*/
|
|
||||||
private String version = null;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,63 @@
|
|||||||
|
package com.ruoyi.framework.config.properties;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* swagger 配置属性
|
||||||
|
*
|
||||||
|
* @author Lion Li
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@Component
|
||||||
|
@ConfigurationProperties(prefix = "swagger")
|
||||||
|
public class SwaggerProperties {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 验证码类型
|
||||||
|
*/
|
||||||
|
private Boolean enabled;
|
||||||
|
/**
|
||||||
|
* 设置请求的统一前缀
|
||||||
|
*/
|
||||||
|
private String pathMapping;
|
||||||
|
/**
|
||||||
|
* 验证码类别
|
||||||
|
*/
|
||||||
|
private String title;
|
||||||
|
/**
|
||||||
|
* 数字验证码位数
|
||||||
|
*/
|
||||||
|
private String description;
|
||||||
|
/**
|
||||||
|
* 字符验证码长度
|
||||||
|
*/
|
||||||
|
private String version;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 联系方式
|
||||||
|
*/
|
||||||
|
private Contact contact;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@NoArgsConstructor
|
||||||
|
public static class Contact{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 联系人
|
||||||
|
**/
|
||||||
|
private String name;
|
||||||
|
/**
|
||||||
|
* 联系人url
|
||||||
|
**/
|
||||||
|
private String url;
|
||||||
|
/**
|
||||||
|
* 联系人email
|
||||||
|
**/
|
||||||
|
private String email;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,272 +0,0 @@
|
|||||||
package com.ruoyi.framework.handler;
|
|
||||||
|
|
||||||
import cn.hutool.core.io.IoUtil;
|
|
||||||
import io.swagger.v3.core.jackson.TypeNameResolver;
|
|
||||||
import io.swagger.v3.core.util.AnnotationsUtils;
|
|
||||||
import io.swagger.v3.oas.annotations.tags.Tags;
|
|
||||||
import io.swagger.v3.oas.models.Components;
|
|
||||||
import io.swagger.v3.oas.models.OpenAPI;
|
|
||||||
import io.swagger.v3.oas.models.Operation;
|
|
||||||
import io.swagger.v3.oas.models.Paths;
|
|
||||||
import io.swagger.v3.oas.models.tags.Tag;
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
import org.springdoc.core.OpenAPIService;
|
|
||||||
import org.springdoc.core.PropertyResolverUtils;
|
|
||||||
import org.springdoc.core.SecurityService;
|
|
||||||
import org.springdoc.core.SpringDocConfigProperties;
|
|
||||||
import org.springdoc.core.customizers.OpenApiBuilderCustomizer;
|
|
||||||
import org.springdoc.core.customizers.ServerBaseUrlCustomizer;
|
|
||||||
import org.springdoc.core.providers.JavadocProvider;
|
|
||||||
import org.springframework.context.ApplicationContext;
|
|
||||||
import org.springframework.core.annotation.AnnotatedElementUtils;
|
|
||||||
import org.springframework.util.CollectionUtils;
|
|
||||||
import org.springframework.web.method.HandlerMethod;
|
|
||||||
|
|
||||||
import java.io.StringReader;
|
|
||||||
import java.lang.reflect.Method;
|
|
||||||
import java.util.*;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
import java.util.stream.Stream;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 自定义 openapi 处理器
|
|
||||||
* 对源码功能进行修改 增强使用
|
|
||||||
*/
|
|
||||||
@SuppressWarnings("all")
|
|
||||||
public class OpenApiHandler extends OpenAPIService {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The constant LOGGER.
|
|
||||||
*/
|
|
||||||
private static final Logger LOGGER = LoggerFactory.getLogger(OpenAPIService.class);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The Context.
|
|
||||||
*/
|
|
||||||
private ApplicationContext context;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The Security parser.
|
|
||||||
*/
|
|
||||||
private final SecurityService securityParser;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The Mappings map.
|
|
||||||
*/
|
|
||||||
private final Map<String, Object> mappingsMap = new HashMap<>();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The Springdoc tags.
|
|
||||||
*/
|
|
||||||
private final Map<HandlerMethod, io.swagger.v3.oas.models.tags.Tag> springdocTags = new HashMap<>();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The Open api builder customisers.
|
|
||||||
*/
|
|
||||||
private final Optional<List<OpenApiBuilderCustomizer>> openApiBuilderCustomisers;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The server base URL customisers.
|
|
||||||
*/
|
|
||||||
private final Optional<List<ServerBaseUrlCustomizer>> serverBaseUrlCustomizers;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The Spring doc config properties.
|
|
||||||
*/
|
|
||||||
private final SpringDocConfigProperties springDocConfigProperties;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The Open api.
|
|
||||||
*/
|
|
||||||
private OpenAPI openAPI;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The Cached open api map.
|
|
||||||
*/
|
|
||||||
private final Map<String, OpenAPI> cachedOpenAPI = new HashMap<>();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The Is servers present.
|
|
||||||
*/
|
|
||||||
private boolean isServersPresent;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The Server base url.
|
|
||||||
*/
|
|
||||||
private String serverBaseUrl;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The Property resolver utils.
|
|
||||||
*/
|
|
||||||
private final PropertyResolverUtils propertyResolverUtils;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The javadoc provider.
|
|
||||||
*/
|
|
||||||
private final Optional<JavadocProvider> javadocProvider;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The Basic error controller.
|
|
||||||
*/
|
|
||||||
private static Class<?> basicErrorController;
|
|
||||||
|
|
||||||
static {
|
|
||||||
try {
|
|
||||||
//spring-boot 2
|
|
||||||
basicErrorController = Class.forName("org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController");
|
|
||||||
} catch (ClassNotFoundException e) {
|
|
||||||
//spring-boot 1
|
|
||||||
try {
|
|
||||||
basicErrorController = Class.forName("org.springframework.boot.autoconfigure.web.BasicErrorController");
|
|
||||||
} catch (ClassNotFoundException classNotFoundException) {
|
|
||||||
//Basic error controller class not found
|
|
||||||
LOGGER.trace(classNotFoundException.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Instantiates a new Open api builder.
|
|
||||||
*
|
|
||||||
* @param openAPI the open api
|
|
||||||
* @param securityParser the security parser
|
|
||||||
* @param springDocConfigProperties the spring doc config properties
|
|
||||||
* @param propertyResolverUtils the property resolver utils
|
|
||||||
* @param openApiBuilderCustomizers the open api builder customisers
|
|
||||||
* @param serverBaseUrlCustomizers the server base url customizers
|
|
||||||
* @param javadocProvider the javadoc provider
|
|
||||||
*/
|
|
||||||
public OpenApiHandler(Optional<OpenAPI> openAPI, SecurityService securityParser,
|
|
||||||
SpringDocConfigProperties springDocConfigProperties, PropertyResolverUtils propertyResolverUtils,
|
|
||||||
Optional<List<OpenApiBuilderCustomizer>> openApiBuilderCustomizers,
|
|
||||||
Optional<List<ServerBaseUrlCustomizer>> serverBaseUrlCustomizers,
|
|
||||||
Optional<JavadocProvider> javadocProvider) {
|
|
||||||
super(openAPI, securityParser, springDocConfigProperties, propertyResolverUtils, openApiBuilderCustomizers, serverBaseUrlCustomizers, javadocProvider);
|
|
||||||
if (openAPI.isPresent()) {
|
|
||||||
this.openAPI = openAPI.get();
|
|
||||||
if (this.openAPI.getComponents() == null)
|
|
||||||
this.openAPI.setComponents(new Components());
|
|
||||||
if (this.openAPI.getPaths() == null)
|
|
||||||
this.openAPI.setPaths(new Paths());
|
|
||||||
if (!CollectionUtils.isEmpty(this.openAPI.getServers()))
|
|
||||||
this.isServersPresent = true;
|
|
||||||
}
|
|
||||||
this.propertyResolverUtils = propertyResolverUtils;
|
|
||||||
this.securityParser = securityParser;
|
|
||||||
this.springDocConfigProperties = springDocConfigProperties;
|
|
||||||
this.openApiBuilderCustomisers = openApiBuilderCustomizers;
|
|
||||||
this.serverBaseUrlCustomizers = serverBaseUrlCustomizers;
|
|
||||||
this.javadocProvider = javadocProvider;
|
|
||||||
if (springDocConfigProperties.isUseFqn())
|
|
||||||
TypeNameResolver.std.setUseFqn(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Operation buildTags(HandlerMethod handlerMethod, Operation operation, OpenAPI openAPI, Locale locale) {
|
|
||||||
|
|
||||||
Set<Tag> tags = new HashSet<>();
|
|
||||||
Set<String> tagsStr = new HashSet<>();
|
|
||||||
|
|
||||||
buildTagsFromMethod(handlerMethod.getMethod(), tags, tagsStr, locale);
|
|
||||||
buildTagsFromClass(handlerMethod.getBeanType(), tags, tagsStr, locale);
|
|
||||||
|
|
||||||
if (!CollectionUtils.isEmpty(tagsStr))
|
|
||||||
tagsStr = tagsStr.stream()
|
|
||||||
.map(str -> propertyResolverUtils.resolve(str, locale))
|
|
||||||
.collect(Collectors.toSet());
|
|
||||||
|
|
||||||
if (springdocTags.containsKey(handlerMethod)) {
|
|
||||||
io.swagger.v3.oas.models.tags.Tag tag = springdocTags.get(handlerMethod);
|
|
||||||
tagsStr.add(tag.getName());
|
|
||||||
if (openAPI.getTags() == null || !openAPI.getTags().contains(tag)) {
|
|
||||||
openAPI.addTagsItem(tag);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!CollectionUtils.isEmpty(tagsStr)) {
|
|
||||||
if (CollectionUtils.isEmpty(operation.getTags()))
|
|
||||||
operation.setTags(new ArrayList<>(tagsStr));
|
|
||||||
else {
|
|
||||||
Set<String> operationTagsSet = new HashSet<>(operation.getTags());
|
|
||||||
operationTagsSet.addAll(tagsStr);
|
|
||||||
operation.getTags().clear();
|
|
||||||
operation.getTags().addAll(operationTagsSet);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isAutoTagClasses(operation)) {
|
|
||||||
|
|
||||||
|
|
||||||
if (javadocProvider.isPresent()) {
|
|
||||||
String description = javadocProvider.get().getClassJavadoc(handlerMethod.getBeanType());
|
|
||||||
if (StringUtils.isNotBlank(description)) {
|
|
||||||
io.swagger.v3.oas.models.tags.Tag tag = new io.swagger.v3.oas.models.tags.Tag();
|
|
||||||
|
|
||||||
// 自定义部分 修改使用java注释当tag名
|
|
||||||
List<String> list = IoUtil.readLines(new StringReader(description), new ArrayList<>());
|
|
||||||
// tag.setName(tagAutoName);
|
|
||||||
tag.setName(list.get(0));
|
|
||||||
operation.addTagsItem(list.get(0));
|
|
||||||
|
|
||||||
tag.setDescription(description);
|
|
||||||
if (openAPI.getTags() == null || !openAPI.getTags().contains(tag)) {
|
|
||||||
openAPI.addTagsItem(tag);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
String tagAutoName = splitCamelCase(handlerMethod.getBeanType().getSimpleName());
|
|
||||||
operation.addTagsItem(tagAutoName);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!CollectionUtils.isEmpty(tags)) {
|
|
||||||
// Existing tags
|
|
||||||
List<io.swagger.v3.oas.models.tags.Tag> openApiTags = openAPI.getTags();
|
|
||||||
if (!CollectionUtils.isEmpty(openApiTags))
|
|
||||||
tags.addAll(openApiTags);
|
|
||||||
openAPI.setTags(new ArrayList<>(tags));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Handle SecurityRequirement at operation level
|
|
||||||
io.swagger.v3.oas.annotations.security.SecurityRequirement[] securityRequirements = securityParser
|
|
||||||
.getSecurityRequirements(handlerMethod);
|
|
||||||
if (securityRequirements != null) {
|
|
||||||
if (securityRequirements.length == 0)
|
|
||||||
operation.setSecurity(Collections.emptyList());
|
|
||||||
else
|
|
||||||
securityParser.buildSecurityRequirement(securityRequirements, operation);
|
|
||||||
}
|
|
||||||
|
|
||||||
return operation;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void buildTagsFromMethod(Method method, Set<io.swagger.v3.oas.models.tags.Tag> tags, Set<String> tagsStr, Locale locale) {
|
|
||||||
// method tags
|
|
||||||
Set<Tags> tagsSet = AnnotatedElementUtils
|
|
||||||
.findAllMergedAnnotations(method, Tags.class);
|
|
||||||
Set<io.swagger.v3.oas.annotations.tags.Tag> methodTags = tagsSet.stream()
|
|
||||||
.flatMap(x -> Stream.of(x.value())).collect(Collectors.toSet());
|
|
||||||
methodTags.addAll(AnnotatedElementUtils.findAllMergedAnnotations(method, io.swagger.v3.oas.annotations.tags.Tag.class));
|
|
||||||
if (!CollectionUtils.isEmpty(methodTags)) {
|
|
||||||
tagsStr.addAll(methodTags.stream().map(tag -> propertyResolverUtils.resolve(tag.name(), locale)).collect(Collectors.toSet()));
|
|
||||||
List<io.swagger.v3.oas.annotations.tags.Tag> allTags = new ArrayList<>(methodTags);
|
|
||||||
addTags(allTags, tags, locale);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void addTags(List<io.swagger.v3.oas.annotations.tags.Tag> sourceTags, Set<io.swagger.v3.oas.models.tags.Tag> tags, Locale locale) {
|
|
||||||
Optional<Set<io.swagger.v3.oas.models.tags.Tag>> optionalTagSet = AnnotationsUtils
|
|
||||||
.getTags(sourceTags.toArray(new io.swagger.v3.oas.annotations.tags.Tag[0]), true);
|
|
||||||
optionalTagSet.ifPresent(tagsSet -> {
|
|
||||||
tagsSet.forEach(tag -> {
|
|
||||||
tag.name(propertyResolverUtils.resolve(tag.getName(), locale));
|
|
||||||
tag.description(propertyResolverUtils.resolve(tag.getDescription(), locale));
|
|
||||||
if (tags.stream().noneMatch(t -> t.getName().equals(tag.getName())))
|
|
||||||
tags.add(tag);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user