diff --git a/csap-framework-apidoc-core/src/main/java/com/csap/framework/apidoc/response/CsapDocMethodModel.java b/csap-framework-apidoc-core/src/main/java/com/csap/framework/apidoc/response/CsapDocMethodModel.java new file mode 100644 index 0000000000000000000000000000000000000000..459bc14380806634e69b8ed9d64bd1de7ce6ba4c --- /dev/null +++ b/csap-framework-apidoc-core/src/main/java/com/csap/framework/apidoc/response/CsapDocMethodModel.java @@ -0,0 +1,38 @@ +package com.csap.framework.apidoc.response; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * @author yangchengfu + * @description 文档 controller 信息 + * @dataTime 2019年-12月-28日 17:44:00 + **/ +@Data +@Builder +@AllArgsConstructor +@NoArgsConstructor +public class CsapDocMethodModel { + /** + * 名称描述 + */ + private String title; + /** + * 包含类名和方法名称 标识 + */ + private String key; + /** + * 实际名称 + */ + private Boolean isLeaf; + + private String method; + + private String type; + + private String path; + + +} diff --git a/csap-framework-apidoc-core/src/main/java/com/csap/framework/apidoc/response/CsapDocMethodResponse.java b/csap-framework-apidoc-core/src/main/java/com/csap/framework/apidoc/response/CsapDocMethodResponse.java new file mode 100644 index 0000000000000000000000000000000000000000..5e7d84a0cd9956fc8698c74c00768a4d308c7bab --- /dev/null +++ b/csap-framework-apidoc-core/src/main/java/com/csap/framework/apidoc/response/CsapDocMethodResponse.java @@ -0,0 +1,37 @@ +package com.csap.framework.apidoc.response; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.List; + +/** + * @author yangchengfu + * @description 文档 controller 信息 + * @dataTime 2019年-12月-28日 17:44:00 + **/ +@Data +@Builder +@AllArgsConstructor +@NoArgsConstructor +public class CsapDocMethodResponse { + + private List headers; + + private List request; + + private List response; + + private String paramType; + + private String title; + + private String method; + + private String patch; + + + +} diff --git a/csap-framework-apidoc-core/src/main/java/com/csap/framework/apidoc/response/CsapDocParentResponse.java b/csap-framework-apidoc-core/src/main/java/com/csap/framework/apidoc/response/CsapDocParentResponse.java new file mode 100644 index 0000000000000000000000000000000000000000..7ecb4a0d9ab04dd897d95aee8fa5b8ff0fb22420 --- /dev/null +++ b/csap-framework-apidoc-core/src/main/java/com/csap/framework/apidoc/response/CsapDocParentResponse.java @@ -0,0 +1,31 @@ +package com.csap.framework.apidoc.response; + +import com.csap.framework.annotation.apidoc.ApiModel; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; +import lombok.experimental.Accessors; + +import java.util.*; + +/** + * @author yangchengfu + * @description 文档接口返回参数 + * @dataTime 2019年-12月-29日 15:31:00 + **/ +@Data +@Builder +@AllArgsConstructor +@NoArgsConstructor +@ApiModel(value = "父类文档返回信息") +@Accessors(chain = true) +public class CsapDocParentResponse { + + /** + * 当前项目所有的api + */ + private List apiList; + + +} diff --git a/csap-framework-apidoc-core/src/main/java/com/csap/framework/apidoc/response/CsapDocParentResponseModel.java b/csap-framework-apidoc-core/src/main/java/com/csap/framework/apidoc/response/CsapDocParentResponseModel.java new file mode 100644 index 0000000000000000000000000000000000000000..6a0ecc348c99aaba2fc9338a4eb78f77003741e8 --- /dev/null +++ b/csap-framework-apidoc-core/src/main/java/com/csap/framework/apidoc/response/CsapDocParentResponseModel.java @@ -0,0 +1,29 @@ +package com.csap.framework.apidoc.response; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.List; + +/** + * @author yangchengfu + * @description 文档 controller 信息 + * @dataTime 2019年-12月-28日 17:44:00 + **/ +@Data +@Builder +@AllArgsConstructor +@NoArgsConstructor +public class CsapDocParentResponseModel { + /** + * 描述名称,简称 + */ + private String title; + private String key; + /** + * 当前controller下的所有方法 + */ + private List children; +} diff --git a/csap-framework-apidoc-core/src/main/java/com/csap/framework/apidoc/response/MethodHeadersResponseModel.java b/csap-framework-apidoc-core/src/main/java/com/csap/framework/apidoc/response/MethodHeadersResponseModel.java new file mode 100644 index 0000000000000000000000000000000000000000..12f1c270741876af1f3141742011d941f3d068f7 --- /dev/null +++ b/csap-framework-apidoc-core/src/main/java/com/csap/framework/apidoc/response/MethodHeadersResponseModel.java @@ -0,0 +1,37 @@ +package com.csap.framework.apidoc.response; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * @author yangchengfu + * @description 文档 controller 信息 + * @dataTime 2019年-12月-28日 17:44:00 + **/ +@Data +@Builder +@AllArgsConstructor +@NoArgsConstructor +public class MethodHeadersResponseModel { + /** + * 名称描述 + */ + private String description; + /** + * 包含类名和方法名称 标识 + */ + private String example; + /** + * 实际名称 + */ + private boolean required; + + + private String value; + private String key; + + + +} diff --git a/csap-framework-apidoc-core/src/main/java/com/csap/framework/apidoc/response/MethodRequestModel.java b/csap-framework-apidoc-core/src/main/java/com/csap/framework/apidoc/response/MethodRequestModel.java new file mode 100644 index 0000000000000000000000000000000000000000..0a6744c4bf053bfc257a67ac26936ce7bb724820 --- /dev/null +++ b/csap-framework-apidoc-core/src/main/java/com/csap/framework/apidoc/response/MethodRequestModel.java @@ -0,0 +1,46 @@ +package com.csap.framework.apidoc.response; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.List; + +/** + * @author yangchengfu + * @description 文档 controller 信息 + * @dataTime 2019年-12月-28日 17:44:00 + **/ +@Data +@Builder +@AllArgsConstructor +@NoArgsConstructor +public class MethodRequestModel { + /** + * 名称描述 + */ + private String key; + /** + * 包含类名和方法名称 标识 + */ + private String name; + /** + * 实际名称 + */ + private Boolean required; + + private String value; + + private String dataType; + + private String defaultValue; + + private String example; + + private String description; + + private List children; + + +} diff --git a/csap-framework-apidoc-core/src/main/java/com/csap/framework/apidoc/response/MethodResponseModel.java b/csap-framework-apidoc-core/src/main/java/com/csap/framework/apidoc/response/MethodResponseModel.java new file mode 100644 index 0000000000000000000000000000000000000000..15e6f797ec29603a637fecc1bc760191e888f178 --- /dev/null +++ b/csap-framework-apidoc-core/src/main/java/com/csap/framework/apidoc/response/MethodResponseModel.java @@ -0,0 +1,46 @@ +package com.csap.framework.apidoc.response; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.List; + +/** + * @author yangchengfu + * @description 文档 controller 信息 + * @dataTime 2019年-12月-28日 17:44:00 + **/ +@Data +@Builder +@AllArgsConstructor +@NoArgsConstructor +public class MethodResponseModel { + /** + * 名称描述 + */ + private String key; + /** + * 包含类名和方法名称 标识 + */ + private String name; + /** + * 实际名称 + */ + private Boolean required; + + private String value; + + private String dataType; + + private String defaultValue; + + private String example; + + private String description; + + private List children; + + +} diff --git a/csap-framework-apidoc-core/src/main/java/com/csap/framework/apidoc/web/CsapDocController.java b/csap-framework-apidoc-core/src/main/java/com/csap/framework/apidoc/web/CsapDocController.java index 056cc33bc4d7a03530c87d28dbadcb9763031f31..84355f14dca3fdf8ee5d1b16b2443a03c54e1b22 100644 --- a/csap-framework-apidoc-core/src/main/java/com/csap/framework/apidoc/web/CsapDocController.java +++ b/csap-framework-apidoc-core/src/main/java/com/csap/framework/apidoc/web/CsapDocController.java @@ -1,8 +1,11 @@ package com.csap.framework.apidoc.web; import com.csap.framework.annotation.ResponseAdvice; -import com.csap.framework.apidoc.model.CsapDocResponse; +import com.csap.framework.apidoc.model.*; +import com.csap.framework.apidoc.response.*; import com.csap.framework.apidoc.strategy.ApidocStrategy; +import com.csap.framework.util.CollectionsUtil; +import com.csap.framework.util.bean.BeanCopierUtil; import com.csap.framework.util.optional.Optional; import org.springframework.context.ApplicationContext; import org.springframework.web.bind.annotation.GetMapping; @@ -12,6 +15,10 @@ import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import javax.annotation.Resource; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.stream.Collectors; /** * @author yangchengfu @@ -64,4 +71,68 @@ public class CsapDocController { @RequestParam(required = false, defaultValue = "true") Boolean devTools) { return csapDocService.apidoc(tableName, className, devTools); } + + @GetMapping("/apidoc/parent") + public CsapDocParentResponse apiDocParent() { + CsapDocResponse apidoc = apidoc(Boolean.FALSE); + List apiList = apidoc.getApiList(); + List csapDocParentResponseModels = new ArrayList<>(); + apiList.stream().forEach(item -> { + csapDocParentResponseModels.add(CsapDocParentResponseModel.builder().title(item.getValue()).key(item.getName()).children(setChildren(item.getMethodList(), item.getProtocols().name())).build()); + }); + return CsapDocParentResponse.builder().apiList(csapDocParentResponseModels).build(); + } + + @GetMapping("/apidoc/method") + public CsapDocMethodResponse apiDocMethod(@RequestParam String name, @RequestParam String key) { + CsapDocResponse apidoc = apidoc(Boolean.FALSE); + List apiList = apidoc.getApiList(); + CsapDocMethod csapDocMethod = apiList.stream().filter(item -> item.getName().equals(name)).collect(Collectors.toList()).get(0) + .getMethodList().stream().filter(item -> item.getKey().equals(key)).collect(Collectors.toList()).get(0); + return CsapDocMethodResponse.builder() + .headers(BeanCopierUtil.copyList(csapDocMethod.getMethodHeaders(), MethodHeadersResponseModel.class)) + .patch("/"+csapDocMethod.getApiPath()[0] + "/" + csapDocMethod.getPaths()[0]) + .method(csapDocMethod.getMethods().get(0).name()) + .title(csapDocMethod.getValue()) + .paramType(csapDocMethod.getParamType().name()) + .request(CollectionsUtil.isNotEmpty(csapDocMethod.getRequest()) ? setChildParam(csapDocMethod.getRequest().get(0).getParameters()) : Collections.EMPTY_LIST) + .response(CollectionsUtil.isNotEmpty(csapDocMethod.getResponse()) ? setChildParam(csapDocMethod.getResponse().get(0).getParameters()) : Collections.EMPTY_LIST).build(); + + } + + public List setChildren(List methodList, String type) { + List childrenList = new ArrayList<>(); + methodList.stream().forEach(item -> { + childrenList.add(CsapDocMethodModel.builder() + .title(item.getValue()) + .key(item.getKey()) + .isLeaf(Boolean.TRUE) + .method(item.getMethods().get(0).name()) + .path(item.getApiPath()[0] + "/" + item.getPaths()[0]) + .type(type) + .build()); + }); + return childrenList; + } + + public List setChildParam(List parameters) { + List requestList = new ArrayList<>(); + parameters.stream().forEach(item -> { + MethodRequestModel build = MethodRequestModel.builder() + .key(item.getKey()) + .dataType(item.getDataType()) + .required(item.isRequired()) + .defaultValue(item.getDefaultValue()) + .name(item.getName()) + .value(item.getValue()) + .example(item.getExample()) + .description(item.getDescription()) + .build(); + if (CollectionsUtil.isNotEmpty(item.getParameters())) { + build.setChildren(setChildParam(item.getParameters())); + } + requestList.add(build); + }); + return requestList; + } }