diff --git a/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/swagger/DocumentationPluginsManagerExt.java b/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/swagger/DocumentationPluginsManagerExt.java index 10efd4cd..d3db16dc 100644 --- a/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/swagger/DocumentationPluginsManagerExt.java +++ b/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/swagger/DocumentationPluginsManagerExt.java @@ -20,9 +20,9 @@ import java.util.List; */ public class DocumentationPluginsManagerExt extends DocumentationPluginsManager { - public static final String SOP_NAME = "sop_name"; - public static final String SOP_VERSION = "sop_version"; - public static final String MODULE_ORDER = "module_order"; + private static final String SOP_NAME = "sop_name"; + private static final String SOP_VERSION = "sop_version"; + private static final String MODULE_ORDER = "module_order"; @Override public Operation operation(OperationContext operationContext) { diff --git a/sop-example/sop-story/sop-story-web/src/main/java/com/gitee/sop/storyweb/controller/AlipayController.java b/sop-example/sop-story/sop-story-web/src/main/java/com/gitee/sop/storyweb/controller/AlipayController.java index 96d57a8d..c1e525ab 100644 --- a/sop-example/sop-story/sop-story-web/src/main/java/com/gitee/sop/storyweb/controller/AlipayController.java +++ b/sop-example/sop-story/sop-story-web/src/main/java/com/gitee/sop/storyweb/controller/AlipayController.java @@ -10,6 +10,7 @@ import com.gitee.sop.storyweb.controller.param.CategoryParam; import com.gitee.sop.storyweb.controller.param.StoryParam; import com.gitee.sop.storyweb.controller.result.CategoryResult; import com.gitee.sop.storyweb.controller.result.StoryResult; +import com.gitee.sop.storyweb.controller.result.TreeResult; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import lombok.Data; @@ -240,6 +241,18 @@ public class AlipayController { return categoryResult; } + /** + * 树状返回 + * + * @param param + * @return + */ + @ApiOperation(value = "树状返回", notes = "树状返回") + @ApiMapping(value = "alipay.tree.get", method = RequestMethod.POST) + public TreeResult tree(StoryParam param) { + return new TreeResult(); + } + // 测试参数绑定,http://localhost:2222/story/getStory4?biz_content=%7b%22id%22%3a1%2c%22name%22%3a%22aaaa%22%7d @ApiAbility @GetMapping("getStory4") diff --git a/sop-example/sop-story/sop-story-web/src/main/java/com/gitee/sop/storyweb/controller/result/TreeResult.java b/sop-example/sop-story/sop-story-web/src/main/java/com/gitee/sop/storyweb/controller/result/TreeResult.java new file mode 100644 index 00000000..58ecf0ae --- /dev/null +++ b/sop-example/sop-story/sop-story-web/src/main/java/com/gitee/sop/storyweb/controller/result/TreeResult.java @@ -0,0 +1,24 @@ +package com.gitee.sop.storyweb.controller.result; + +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.util.List; + +/** + * @author tanghc + */ +@Data +public class TreeResult { + @ApiModelProperty(value = "id") + private Integer id; + + @ApiModelProperty(value = "名称") + private String name; + + @ApiModelProperty(value = "父id") + private Integer pid; + + @ApiModelProperty(value = "子节点") + private List children; +} diff --git a/sop-website/src/main/java/com/gitee/sop/websiteserver/manager/SwaggerDocParser.java b/sop-website/src/main/java/com/gitee/sop/websiteserver/manager/SwaggerDocParser.java index ae83b3ab..1693628b 100644 --- a/sop-website/src/main/java/com/gitee/sop/websiteserver/manager/SwaggerDocParser.java +++ b/sop-website/src/main/java/com/gitee/sop/websiteserver/manager/SwaggerDocParser.java @@ -18,6 +18,7 @@ import java.util.Collections; import java.util.Comparator; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.Optional; import java.util.Set; import java.util.stream.Collectors; @@ -170,7 +171,7 @@ public class SwaggerDocParser implements DocParser { List respParameterList = Collections.emptyList(); if (refInfo != null) { String responseRef = refInfo.ref; - respParameterList = this.buildDocParameters(responseRef, docRoot); + respParameterList = this.buildDocParameters(responseRef, docRoot, true); // 如果返回数组 if (refInfo.isArray) { DocParameter docParameter = new DocParameter(); @@ -183,7 +184,7 @@ public class SwaggerDocParser implements DocParser { return respParameterList; } - protected List buildDocParameters(String ref, JSONObject docRoot) { + protected List buildDocParameters(String ref, JSONObject docRoot, boolean doSubRef) { JSONObject responseObject = docRoot.getJSONObject("definitions").getJSONObject(ref); JSONObject properties = responseObject.getJSONObject("properties"); Set fieldNames = properties.keySet(); @@ -200,8 +201,11 @@ public class SwaggerDocParser implements DocParser { docParameter.setName(fieldName); docParameterList.add(docParameter); RefInfo refInfo = this.getRefInfo(fieldInfo); - if (refInfo != null) { - List refs = buildDocParameters(refInfo.ref, docRoot); + if (refInfo != null && doSubRef) { + // 如果是树状菜单的话,这里可能触发死循环 + String subRef = refInfo.ref; + boolean nextDoRef = !Objects.equals(ref, subRef); + List refs = buildDocParameters(subRef, docRoot, nextDoRef); docParameter.setRefs(refs); } }