pull/1/head tag-2.1.0
tanghc 6 years ago
parent b859e8b88f
commit d32d3931a1
  1. 6
      sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/swagger/DocumentationPluginsManagerExt.java
  2. 13
      sop-example/sop-story/sop-story-web/src/main/java/com/gitee/sop/storyweb/controller/AlipayController.java
  3. 24
      sop-example/sop-story/sop-story-web/src/main/java/com/gitee/sop/storyweb/controller/result/TreeResult.java
  4. 12
      sop-website/src/main/java/com/gitee/sop/websiteserver/manager/SwaggerDocParser.java

@ -20,9 +20,9 @@ import java.util.List;
*/ */
public class DocumentationPluginsManagerExt extends DocumentationPluginsManager { public class DocumentationPluginsManagerExt extends DocumentationPluginsManager {
public static final String SOP_NAME = "sop_name"; private static final String SOP_NAME = "sop_name";
public static final String SOP_VERSION = "sop_version"; private static final String SOP_VERSION = "sop_version";
public static final String MODULE_ORDER = "module_order"; private static final String MODULE_ORDER = "module_order";
@Override @Override
public Operation operation(OperationContext operationContext) { public Operation operation(OperationContext operationContext) {

@ -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.param.StoryParam;
import com.gitee.sop.storyweb.controller.result.CategoryResult; import com.gitee.sop.storyweb.controller.result.CategoryResult;
import com.gitee.sop.storyweb.controller.result.StoryResult; 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.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import lombok.Data; import lombok.Data;
@ -240,6 +241,18 @@ public class AlipayController {
return categoryResult; 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 // 测试参数绑定,http://localhost:2222/story/getStory4?biz_content=%7b%22id%22%3a1%2c%22name%22%3a%22aaaa%22%7d
@ApiAbility @ApiAbility
@GetMapping("getStory4") @GetMapping("getStory4")

@ -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<TreeResult> children;
}

@ -18,6 +18,7 @@ import java.util.Collections;
import java.util.Comparator; import java.util.Comparator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Objects;
import java.util.Optional; import java.util.Optional;
import java.util.Set; import java.util.Set;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -170,7 +171,7 @@ public class SwaggerDocParser implements DocParser {
List<DocParameter> respParameterList = Collections.emptyList(); List<DocParameter> respParameterList = Collections.emptyList();
if (refInfo != null) { if (refInfo != null) {
String responseRef = refInfo.ref; String responseRef = refInfo.ref;
respParameterList = this.buildDocParameters(responseRef, docRoot); respParameterList = this.buildDocParameters(responseRef, docRoot, true);
// 如果返回数组 // 如果返回数组
if (refInfo.isArray) { if (refInfo.isArray) {
DocParameter docParameter = new DocParameter(); DocParameter docParameter = new DocParameter();
@ -183,7 +184,7 @@ public class SwaggerDocParser implements DocParser {
return respParameterList; return respParameterList;
} }
protected List<DocParameter> buildDocParameters(String ref, JSONObject docRoot) { protected List<DocParameter> buildDocParameters(String ref, JSONObject docRoot, boolean doSubRef) {
JSONObject responseObject = docRoot.getJSONObject("definitions").getJSONObject(ref); JSONObject responseObject = docRoot.getJSONObject("definitions").getJSONObject(ref);
JSONObject properties = responseObject.getJSONObject("properties"); JSONObject properties = responseObject.getJSONObject("properties");
Set<String> fieldNames = properties.keySet(); Set<String> fieldNames = properties.keySet();
@ -200,8 +201,11 @@ public class SwaggerDocParser implements DocParser {
docParameter.setName(fieldName); docParameter.setName(fieldName);
docParameterList.add(docParameter); docParameterList.add(docParameter);
RefInfo refInfo = this.getRefInfo(fieldInfo); RefInfo refInfo = this.getRefInfo(fieldInfo);
if (refInfo != null) { if (refInfo != null && doSubRef) {
List<DocParameter> refs = buildDocParameters(refInfo.ref, docRoot); // 如果是树状菜单的话,这里可能触发死循环
String subRef = refInfo.ref;
boolean nextDoRef = !Objects.equals(ref, subRef);
List<DocParameter> refs = buildDocParameters(subRef, docRoot, nextDoRef);
docParameter.setRefs(refs); docParameter.setRefs(refs);
} }
} }

Loading…
Cancel
Save