修改api文档
This commit is contained in:
parent
c00a7c5375
commit
66fdc286de
@ -22,6 +22,8 @@ import com.ruoyi.common.utils.sign.Base64;
|
||||
import com.ruoyi.common.utils.uuid.IdUtils;
|
||||
import com.ruoyi.system.service.ISysConfigService;
|
||||
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
|
||||
@ -30,9 +32,9 @@ import jakarta.servlet.http.HttpServletResponse;
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
@Tag(name = "验证码")
|
||||
@RestController
|
||||
public class CaptchaController
|
||||
{
|
||||
public class CaptchaController {
|
||||
@Resource(name = "captchaProducer")
|
||||
private Producer captchaProducer;
|
||||
|
||||
@ -44,18 +46,18 @@ public class CaptchaController
|
||||
|
||||
@Autowired
|
||||
private ISysConfigService configService;
|
||||
|
||||
/**
|
||||
* 生成验证码
|
||||
*/
|
||||
@Operation(summary = "获取验证码")
|
||||
@Anonymous
|
||||
@GetMapping("/captchaImage")
|
||||
public AjaxResult getCode(HttpServletResponse response) throws IOException
|
||||
{
|
||||
public AjaxResult getCode(HttpServletResponse response) throws IOException {
|
||||
AjaxResult ajax = AjaxResult.success();
|
||||
boolean captchaEnabled = configService.selectCaptchaEnabled();
|
||||
ajax.put("captchaEnabled", captchaEnabled);
|
||||
if (!captchaEnabled)
|
||||
{
|
||||
if (!captchaEnabled) {
|
||||
return ajax;
|
||||
}
|
||||
|
||||
@ -68,15 +70,12 @@ public class CaptchaController
|
||||
|
||||
// 生成验证码
|
||||
String captchaType = RuoYiConfig.getCaptchaType();
|
||||
if ("math".equals(captchaType))
|
||||
{
|
||||
if ("math".equals(captchaType)) {
|
||||
String capText = captchaProducerMath.createText();
|
||||
capStr = capText.substring(0, capText.lastIndexOf("@"));
|
||||
code = capText.substring(capText.lastIndexOf("@") + 1);
|
||||
image = captchaProducerMath.createImage(capStr);
|
||||
}
|
||||
else if ("char".equals(captchaType))
|
||||
{
|
||||
} else if ("char".equals(captchaType)) {
|
||||
capStr = code = captchaProducer.createText();
|
||||
image = captchaProducer.createImage(capStr);
|
||||
}
|
||||
@ -84,12 +83,9 @@ public class CaptchaController
|
||||
redisCache.setCacheObject(verifyKey, code, Constants.CAPTCHA_EXPIRATION, TimeUnit.MINUTES);
|
||||
// 转换流信息写出
|
||||
FastByteArrayOutputStream os = new FastByteArrayOutputStream();
|
||||
try
|
||||
{
|
||||
try {
|
||||
ImageIO.write(image, "jpg", os);
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
} catch (IOException e) {
|
||||
return AjaxResult.error(e.getMessage());
|
||||
}
|
||||
|
||||
|
@ -2,8 +2,7 @@ package com.ruoyi.web.controller.common;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@ -11,8 +10,10 @@ import org.springframework.http.MediaType;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import com.ruoyi.common.config.RuoYiConfig;
|
||||
import com.ruoyi.common.constant.Constants;
|
||||
import com.ruoyi.common.core.domain.AjaxResult;
|
||||
@ -21,15 +22,22 @@ import com.ruoyi.common.utils.file.FileUploadUtils;
|
||||
import com.ruoyi.common.utils.file.FileUtils;
|
||||
import com.ruoyi.framework.config.ServerConfig;
|
||||
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.Parameters;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
|
||||
/**
|
||||
* 通用请求处理
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
@Tag(name = "通用请求处理")
|
||||
@RestController
|
||||
@RequestMapping("/common")
|
||||
public class CommonController
|
||||
{
|
||||
public class CommonController {
|
||||
private static final Logger log = LoggerFactory.getLogger(CommonController.class);
|
||||
|
||||
@Autowired
|
||||
@ -41,15 +49,21 @@ public class CommonController
|
||||
* 通用下载请求
|
||||
*
|
||||
* @param fileName 文件名称
|
||||
* @param delete 是否删除
|
||||
* @param delete 是否删除
|
||||
*/
|
||||
@Operation(summary = "通用下载请求")
|
||||
@Parameters({
|
||||
@Parameter(name = "fileName", description = "文件名称"),
|
||||
@Parameter(name = "delete", description = "是否删除")
|
||||
})
|
||||
@GetMapping("/download")
|
||||
public void fileDownload(String fileName, Boolean delete, HttpServletResponse response, HttpServletRequest request)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!FileUtils.checkAllowDownload(fileName))
|
||||
{
|
||||
public void fileDownload(
|
||||
@RequestParam("fileName") String fileName,
|
||||
@RequestParam("delete") Boolean delete,
|
||||
HttpServletResponse response,
|
||||
HttpServletRequest request) {
|
||||
try {
|
||||
if (!FileUtils.checkAllowDownload(fileName)) {
|
||||
throw new Exception(StringUtils.format("文件名称({})非法,不允许下载。 ", fileName));
|
||||
}
|
||||
String realFileName = System.currentTimeMillis() + fileName.substring(fileName.indexOf("_") + 1);
|
||||
@ -58,13 +72,10 @@ public class CommonController
|
||||
response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE);
|
||||
FileUtils.setAttachmentResponseHeader(response, realFileName);
|
||||
FileUtils.writeBytes(filePath, response.getOutputStream());
|
||||
if (delete)
|
||||
{
|
||||
if (delete) {
|
||||
FileUtils.deleteFile(filePath);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
} catch (Exception e) {
|
||||
log.error("下载文件失败", e);
|
||||
}
|
||||
}
|
||||
@ -72,11 +83,10 @@ public class CommonController
|
||||
/**
|
||||
* 通用上传请求(单个)
|
||||
*/
|
||||
@Operation(summary = "通用上传请求(单个)")
|
||||
@PostMapping("/upload")
|
||||
public AjaxResult uploadFile(MultipartFile file) throws Exception
|
||||
{
|
||||
try
|
||||
{
|
||||
public AjaxResult uploadFile(MultipartFile file) throws Exception {
|
||||
try {
|
||||
// 上传文件路径
|
||||
String filePath = RuoYiConfig.getUploadPath();
|
||||
// 上传并返回新文件名称
|
||||
@ -88,9 +98,7 @@ public class CommonController
|
||||
ajax.put("newFileName", FileUtils.getName(fileName));
|
||||
ajax.put("originalFilename", file.getOriginalFilename());
|
||||
return ajax;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
} catch (Exception e) {
|
||||
return AjaxResult.error(e.getMessage());
|
||||
}
|
||||
}
|
||||
@ -98,19 +106,18 @@ public class CommonController
|
||||
/**
|
||||
* 通用上传请求(多个)
|
||||
*/
|
||||
@Operation(summary = "通用上传请求(多个)")
|
||||
@PostMapping("/uploads")
|
||||
public AjaxResult uploadFiles(List<MultipartFile> files) throws Exception
|
||||
{
|
||||
try
|
||||
{
|
||||
public AjaxResult uploadFiles(List<MultipartFile> files)
|
||||
throws Exception {
|
||||
try {
|
||||
// 上传文件路径
|
||||
String filePath = RuoYiConfig.getUploadPath();
|
||||
List<String> urls = new ArrayList<String>();
|
||||
List<String> fileNames = new ArrayList<String>();
|
||||
List<String> newFileNames = new ArrayList<String>();
|
||||
List<String> originalFilenames = new ArrayList<String>();
|
||||
for (MultipartFile file : files)
|
||||
{
|
||||
for (MultipartFile file : files) {
|
||||
// 上传并返回新文件名称
|
||||
String fileName = FileUploadUtils.upload(filePath, file);
|
||||
String url = serverConfig.getUrl() + fileName;
|
||||
@ -125,9 +132,7 @@ public class CommonController
|
||||
ajax.put("newFileNames", StringUtils.join(newFileNames, FILE_DELIMETER));
|
||||
ajax.put("originalFilenames", StringUtils.join(originalFilenames, FILE_DELIMETER));
|
||||
return ajax;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
} catch (Exception e) {
|
||||
return AjaxResult.error(e.getMessage());
|
||||
}
|
||||
}
|
||||
@ -135,14 +140,13 @@ public class CommonController
|
||||
/**
|
||||
* 本地资源通用下载
|
||||
*/
|
||||
@Operation(summary = "本地资源通用下载")
|
||||
@GetMapping("/download/resource")
|
||||
public void resourceDownload(String resource, HttpServletRequest request, HttpServletResponse response)
|
||||
throws Exception
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!FileUtils.checkAllowDownload(resource))
|
||||
{
|
||||
public void resourceDownload(@Parameter(name = "resource", description = "资源名称") String resource,
|
||||
HttpServletRequest request, HttpServletResponse response)
|
||||
throws Exception {
|
||||
try {
|
||||
if (!FileUtils.checkAllowDownload(resource)) {
|
||||
throw new Exception(StringUtils.format("资源文件({})非法,不允许下载。 ", resource));
|
||||
}
|
||||
// 本地资源路径
|
||||
@ -154,9 +158,7 @@ public class CommonController
|
||||
response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE);
|
||||
FileUtils.setAttachmentResponseHeader(response, downloadName);
|
||||
FileUtils.writeBytes(downloadPath, response.getOutputStream());
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
} catch (Exception e) {
|
||||
log.error("下载文件失败", e);
|
||||
}
|
||||
}
|
||||
|
@ -1,36 +1,45 @@
|
||||
package com.ruoyi.web.core.config;
|
||||
|
||||
import org.springdoc.core.models.GroupedOpenApi;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import io.swagger.v3.oas.models.ExternalDocumentation;
|
||||
import io.swagger.v3.oas.models.OpenAPI;
|
||||
import io.swagger.v3.oas.models.info.Info;
|
||||
import io.swagger.v3.oas.models.info.License;
|
||||
import org.springdoc.core.models.GroupedOpenApi;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration
|
||||
public class SwaggerConfig {
|
||||
|
||||
@Bean
|
||||
public OpenAPI springShopOpenAPI() {
|
||||
return new OpenAPI()
|
||||
.info(new Info().title("RuoYi Geek")
|
||||
.description("RuoYi Geek API文档")
|
||||
.version("v1")
|
||||
.license(new License().name("Apache 2.0").url("http://springdoc.org")))
|
||||
.externalDocs(new ExternalDocumentation()
|
||||
.description("外部文档")
|
||||
.url("https://springshop.wiki.github.org/docs"));
|
||||
}
|
||||
@Bean
|
||||
public OpenAPI springShopOpenAPI() {
|
||||
return new OpenAPI()
|
||||
.info(new Info().title("RuoYi Geek")
|
||||
.description("RuoYi Geek API文档")
|
||||
.version("v1")
|
||||
.license(new License().name("Apache 2.0").url("http://springdoc.org")))
|
||||
.externalDocs(new ExternalDocumentation()
|
||||
.description("外部文档")
|
||||
.url("https://springshop.wiki.github.org/docs"));
|
||||
}
|
||||
|
||||
@Bean
|
||||
public GroupedOpenApi sysApi() {
|
||||
return GroupedOpenApi.builder()
|
||||
.group("sys系统")
|
||||
.pathsToMatch("/system/**")
|
||||
.packagesToScan(
|
||||
"com.ruoyi.web.controller")
|
||||
.build();
|
||||
}
|
||||
@Bean
|
||||
public GroupedOpenApi sysApi() {
|
||||
return GroupedOpenApi.builder()
|
||||
.group("sys系统模块")
|
||||
.pathsToMatch("/system/**")
|
||||
.packagesToScan("com.ruoyi.web.controller")
|
||||
.build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public GroupedOpenApi commonApi() {
|
||||
return GroupedOpenApi.builder()
|
||||
.group("基础模块")
|
||||
.pathsToMatch("/common/**")
|
||||
.packagesToScan("com.ruoyi.web.controller")
|
||||
.build();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -23,8 +23,8 @@ import com.ruoyi.common.utils.poi.ExcelUtil;
|
||||
import com.ruoyi.common.core.page.TableDataInfo;
|
||||
#elseif($table.tree)
|
||||
#end
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
|
||||
/**
|
||||
* ${functionName}Controller
|
||||
@ -34,7 +34,7 @@ import io.swagger.annotations.ApiOperation;
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/${moduleName}/${businessName}")
|
||||
@Api(tags = "【${functionName}】管理")
|
||||
@Tag(name = "【${functionName}】管理")
|
||||
public class ${ClassName}Controller extends BaseController
|
||||
{
|
||||
@Autowired
|
||||
@ -43,9 +43,9 @@ public class ${ClassName}Controller extends BaseController
|
||||
/**
|
||||
* 查询${functionName}列表
|
||||
*/
|
||||
@Operation(summary = "查询${functionName}列表")
|
||||
@PreAuthorize("@ss.hasPermi('${permissionPrefix}:list')")
|
||||
@GetMapping("/list")
|
||||
@ApiOperation("查询${functionName}列表")
|
||||
#if($table.crud || $table.sub)
|
||||
public TableDataInfo list(${ClassName} ${className})
|
||||
{
|
||||
@ -64,10 +64,10 @@ public class ${ClassName}Controller extends BaseController
|
||||
/**
|
||||
* 导出${functionName}列表
|
||||
*/
|
||||
@Operation(summary = "导出${functionName}列表")
|
||||
@PreAuthorize("@ss.hasPermi('${permissionPrefix}:export')")
|
||||
@Log(title = "${functionName}", businessType = BusinessType.EXPORT)
|
||||
@PostMapping("/export")
|
||||
@ApiOperation("导出${functionName}列表")
|
||||
public void export(HttpServletResponse response, ${ClassName} ${className})
|
||||
{
|
||||
List<${ClassName}> list = ${className}Service.select${ClassName}List(${className});
|
||||
@ -78,9 +78,9 @@ public class ${ClassName}Controller extends BaseController
|
||||
/**
|
||||
* 获取${functionName}详细信息
|
||||
*/
|
||||
@Operation(summary = "获取${functionName}详细信息")
|
||||
@PreAuthorize("@ss.hasPermi('${permissionPrefix}:query')")
|
||||
@GetMapping(value = "/{${pkColumn.javaField}}")
|
||||
@ApiOperation("获取${functionName}详细信息")
|
||||
public AjaxResult getInfo(@PathVariable("${pkColumn.javaField}") ${pkColumn.javaType} ${pkColumn.javaField})
|
||||
{
|
||||
return success(${className}Service.select${ClassName}By${pkColumn.capJavaField}(${pkColumn.javaField}));
|
||||
@ -89,10 +89,10 @@ public class ${ClassName}Controller extends BaseController
|
||||
/**
|
||||
* 新增${functionName}
|
||||
*/
|
||||
@Operation(summary = "新增${functionName}")
|
||||
@PreAuthorize("@ss.hasPermi('${permissionPrefix}:add')")
|
||||
@Log(title = "${functionName}", businessType = BusinessType.INSERT)
|
||||
@PostMapping
|
||||
@ApiOperation("新增${functionName}")
|
||||
public AjaxResult add(@RequestBody ${ClassName} ${className})
|
||||
{
|
||||
return toAjax(${className}Service.insert${ClassName}(${className}));
|
||||
@ -101,10 +101,10 @@ public class ${ClassName}Controller extends BaseController
|
||||
/**
|
||||
* 修改${functionName}
|
||||
*/
|
||||
@Operation(summary = "修改${functionName}")
|
||||
@PreAuthorize("@ss.hasPermi('${permissionPrefix}:edit')")
|
||||
@Log(title = "${functionName}", businessType = BusinessType.UPDATE)
|
||||
@PutMapping
|
||||
@ApiOperation("修改${functionName}")
|
||||
public AjaxResult edit(@RequestBody ${ClassName} ${className})
|
||||
{
|
||||
return toAjax(${className}Service.update${ClassName}(${className}));
|
||||
@ -113,10 +113,10 @@ public class ${ClassName}Controller extends BaseController
|
||||
/**
|
||||
* 删除${functionName}
|
||||
*/
|
||||
@Operation(summary = "删除${functionName}")
|
||||
@PreAuthorize("@ss.hasPermi('${permissionPrefix}:remove')")
|
||||
@Log(title = "${functionName}", businessType = BusinessType.DELETE)
|
||||
@DeleteMapping("/{${pkColumn.javaField}s}")
|
||||
@ApiOperation("删除${functionName}")
|
||||
public AjaxResult remove(@PathVariable( name = "${pkColumn.javaField}s" ) ${pkColumn.javaType}[] ${pkColumn.javaField}s)
|
||||
{
|
||||
return toAjax(${className}Service.delete${ClassName}By${pkColumn.capJavaField}s(${pkColumn.javaField}s));
|
||||
|
@ -13,6 +13,8 @@ import com.ruoyi.common.core.domain.BaseEntity;
|
||||
import com.ruoyi.common.core.domain.TreeEntity;
|
||||
#end
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
|
||||
/**
|
||||
* ${functionName}对象 ${tableName}
|
||||
*
|
||||
@ -24,6 +26,7 @@ import com.ruoyi.common.core.domain.TreeEntity;
|
||||
#elseif($table.tree)
|
||||
#set($Entity="TreeEntity")
|
||||
#end
|
||||
@Schema(description = "${functionName}对象")
|
||||
public class ${ClassName} extends ${Entity}
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
@ -32,7 +35,7 @@ public class ${ClassName} extends ${Entity}
|
||||
|
||||
#if(!$table.isSuperColumn($column.javaField))
|
||||
/** $column.columnComment */
|
||||
@ApiModelProperty(value = "$column.columnComment")
|
||||
@Schema(defaultValue = "$column.columnComment")
|
||||
#if($column.list)
|
||||
#set($parentheseIndex=$column.columnComment.indexOf("("))
|
||||
#if($parentheseIndex != -1)
|
||||
|
Loading…
Reference in New Issue
Block a user