Skip to content

Commit

Permalink
[mod] 修复了一些bug
Browse files Browse the repository at this point in the history
  • Loading branch information
yaorongke committed Jul 17, 2022
1 parent 235c9bb commit f7aa5c5
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 7 deletions.
12 changes: 8 additions & 4 deletions README.md
Expand Up @@ -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`和一个配置文件

Expand All @@ -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
```
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Up @@ -109,7 +109,7 @@ public List<ApiInfo> getApiInfoList(List<String> 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));
Expand All @@ -125,8 +125,32 @@ private void handeleEntityName(List<EntityInfo> entityInfoList, String methodNam
if (CollectionUtils.isEmpty(entityInfoList)) {
return;
}
// key: 实体类旧名称 val: 实体类新名称
Map<String, String> 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<FieldInfo> fieldInfoList = entityInfo.getFieldList();
if (CollectionUtils.isEmpty(fieldInfoList)) {
continue;
}
for (FieldInfo fieldInfo : fieldInfoList) {
String type = fieldInfo.getType();
for (Map.Entry<String, String> entry : classNameMap.entrySet()) {
String oldName = entry.getKey();
String newName = entry.getValue();
if (type.contains(oldName)) {
fieldInfo.setType(type.replace(oldName, newName));
}
}
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/templates/freemarker/controller.ftl
Expand Up @@ -38,7 +38,7 @@ public class ${serviceName}Controller {
* @return ${api.responseType?uncap_first}
</#if>
*/
@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} </#if>${param.type} ${param.name}<#if param_has_next>, </#if></#list>) {
<#if api.responseType != "void">
return ${serviceName?uncap_first}Service.${api.methodName}(<#list api.paramList as param>${param.name}<#if param_has_next>, </#if></#list>);
Expand Down

0 comments on commit f7aa5c5

Please sign in to comment.