From f7aa5c52590f5a4e04c6887a5daefb24f77a8796 Mon Sep 17 00:00:00 2001 From: rkyao Date: Sun, 17 Jul 2022 14:20:06 +0800 Subject: [PATCH] =?UTF-8?q?[mod]=20=E4=BF=AE=E5=A4=8D=E4=BA=86=E4=B8=80?= =?UTF-8?q?=E4=BA=9Bbug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 12 +++++--- .../impl/ClassInfoTransformServiceImpl.java | 28 +++++++++++++++++-- .../templates/freemarker/controller.ftl | 2 +- 3 files changed, 35 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 7e2c0e4..715b89f 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ 1)下载发布版本 -最新版本:[v1.0.0](https://github.com/yaorongke/yapi-generator/releases/tag/v1.0.0) +最新版本:xxx 将`yaorongke-yapi-generator-1.0.0.zip`解压到一个文件夹里,包含一个`jar`和一个配置文件 @@ -36,7 +36,7 @@ ```shell # clone本项目源码 -git clone https://github.com/yaorongke/yapi-generator.git +git clone xxx # 编译打包,jar包输出到target目录下 mvn clean package -Dmaven.test.skip=true ``` @@ -53,7 +53,7 @@ yapi.project.token=bb70d7d0d1511baa7873fb515398a7b935add6e3575s5d79e8c62805afb3b # 需要生成Java代码的接口id,多个接口id时逗号隔开 yapi.api.interface.ids=11 # 需要生成Java代码的分类id,只支持单个分类id,配置该项会获取分类下的所有接口id -yapi.api.cat.id= +yapi.api.cat.id=18 # 类文件的包路径 yapi.generator.base.package=com.rkyao.yapi.generator @@ -83,6 +83,10 @@ java -jar yaorongke-yapi-generator.jar #### 三、版本说明 -##### v1.0.0 +##### 1.0.0版本 目前`1.0.0`版本中,参数格式支持最常使用的`Query`和`Body`里的`json`格式,`form`、`file`、`raw`格式使用较少暂不支持,未来有时间会考虑兼容。 + +##### 1.0.1版本 + +修复了一些bug \ No newline at end of file diff --git a/src/main/java/com/rkyao/yapi/generator/service/impl/ClassInfoTransformServiceImpl.java b/src/main/java/com/rkyao/yapi/generator/service/impl/ClassInfoTransformServiceImpl.java index 731b21b..e6556c5 100644 --- a/src/main/java/com/rkyao/yapi/generator/service/impl/ClassInfoTransformServiceImpl.java +++ b/src/main/java/com/rkyao/yapi/generator/service/impl/ClassInfoTransformServiceImpl.java @@ -109,7 +109,7 @@ public List getApiInfoList(List idList) { ApiInfo apiInfo = new ApiInfo(); apiInfo.setHttpMethod(dataDTO.getMethod()); apiInfo.setPath(dataDTO.getPath()); - apiInfo.setDesc(StringUtils.isEmpty(dataDTO.getMarkdown()) ? "这是注释" : dataDTO.getMarkdown()); + apiInfo.setDesc(StringUtils.isEmpty(dataDTO.getTitle()) ? "这是注释" : dataDTO.getTitle()); apiInfo.setMethodName(methodName); apiInfo.setParamList(analysisParamList(interfaceInfoDTO.getData(), reqEntityInfoList)); apiInfo.setResponseType(analysisResponseType(respPropertiesDTO, respEntityInfoList)); @@ -125,8 +125,32 @@ private void handeleEntityName(List entityInfoList, String methodNam if (CollectionUtils.isEmpty(entityInfoList)) { return; } + // key: 实体类旧名称 val: 实体类新名称 + Map classNameMap = new HashMap<>(); + // 实体类名前加上接口名防止重复 for (EntityInfo entityInfo : entityInfoList) { - entityInfo.setClassName(StringUtil.capitalizeFirstLetter(methodName) + entityInfo.getClassName()); + String oldName = entityInfo.getClassName(); + String newName = StringUtil.capitalizeFirstLetter(methodName) + entityInfo.getClassName(); + classNameMap.put(oldName, newName); + + entityInfo.setClassName(newName); + } + // 实体类中的字段有包含实体类的,也加上接口名 + for (EntityInfo entityInfo : entityInfoList) { + List fieldInfoList = entityInfo.getFieldList(); + if (CollectionUtils.isEmpty(fieldInfoList)) { + continue; + } + for (FieldInfo fieldInfo : fieldInfoList) { + String type = fieldInfo.getType(); + for (Map.Entry entry : classNameMap.entrySet()) { + String oldName = entry.getKey(); + String newName = entry.getValue(); + if (type.contains(oldName)) { + fieldInfo.setType(type.replace(oldName, newName)); + } + } + } } } diff --git a/src/main/resources/templates/freemarker/controller.ftl b/src/main/resources/templates/freemarker/controller.ftl index 00e4e28..8934716 100644 --- a/src/main/resources/templates/freemarker/controller.ftl +++ b/src/main/resources/templates/freemarker/controller.ftl @@ -38,7 +38,7 @@ public class ${serviceName}Controller { * @return ${api.responseType?uncap_first} */ - @RequestMapping(value = "/", method = RequestMethod.${api.httpMethod}) + @RequestMapping(value = "${api.path}", method = RequestMethod.${api.httpMethod}) public ${api.responseType} ${api.methodName}(<#list api.paramList as param><#if param.annotation??>${param.annotation} ${param.type} ${param.name}<#if param_has_next>, ) { <#if api.responseType != "void"> return ${serviceName?uncap_first}Service.${api.methodName}(<#list api.paramList as param>${param.name}<#if param_has_next>, );