From 13bba069fb314a4c06f27769e46d8843f23bc37d Mon Sep 17 00:00:00 2001 From: zhangjc Date: Thu, 24 Nov 2022 15:38:41 +0800 Subject: [PATCH] =?UTF-8?q?fix=20=E6=B7=BB=E5=8A=A0=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E6=96=87=E6=A1=A3=E8=BF=87=E6=BB=A4=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../apidoc/response/CsapDocMethodModel.java | 38 ++++++++++ .../response/CsapDocMethodResponse.java | 37 ++++++++++ .../response/CsapDocParentResponse.java | 31 ++++++++ .../response/CsapDocParentResponseModel.java | 29 ++++++++ .../response/MethodHeadersResponseModel.java | 37 ++++++++++ .../apidoc/response/MethodRequestModel.java | 46 ++++++++++++ .../apidoc/response/MethodResponseModel.java | 46 ++++++++++++ .../apidoc/web/CsapDocController.java | 73 ++++++++++++++++++- 8 files changed, 336 insertions(+), 1 deletion(-) create mode 100644 csap-framework-apidoc-core/src/main/java/com/csap/framework/apidoc/response/CsapDocMethodModel.java create mode 100644 csap-framework-apidoc-core/src/main/java/com/csap/framework/apidoc/response/CsapDocMethodResponse.java create mode 100644 csap-framework-apidoc-core/src/main/java/com/csap/framework/apidoc/response/CsapDocParentResponse.java create mode 100644 csap-framework-apidoc-core/src/main/java/com/csap/framework/apidoc/response/CsapDocParentResponseModel.java create mode 100644 csap-framework-apidoc-core/src/main/java/com/csap/framework/apidoc/response/MethodHeadersResponseModel.java create mode 100644 csap-framework-apidoc-core/src/main/java/com/csap/framework/apidoc/response/MethodRequestModel.java create mode 100644 csap-framework-apidoc-core/src/main/java/com/csap/framework/apidoc/response/MethodResponseModel.java 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 0000000..459bc14 --- /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 0000000..5e7d84a --- /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 0000000..7ecb4a0 --- /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 0000000..6a0ecc3 --- /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 0000000..12f1c27 --- /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 0000000..0a6744c --- /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 0000000..15e6f79 --- /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 056cc33..84355f1 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; + } } -- Gitee