From ec4188d8599f02fd3526ae7f481126695ab9ab7c Mon Sep 17 00:00:00 2001 From: duanledexianxianxian Date: Tue, 19 May 2020 23:50:30 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E9=87=8D=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../description/ArrayTypeDescription.java | 2 + .../description/ObjectTypeDescription.java | 10 ++- .../description/PrimitiveTypeDescription.java | 2 + .../description/StringTypeDescription.java | 3 + .../common/description/TypeDescription.java | 16 +++-- .../UnAvailableTypeDescription.java | 3 + .../apidoc/core/render/MarkdownRender.java | 1 + .../apidoc/core/schema/Appendix.java | 6 +- .../apidoc/core/schema/Book.java | 6 +- .../apidoc/core/schema/Cell.java | 2 + .../apidoc/core/schema/Chapter.java | 7 +- .../apidoc/core/schema/Header.java | 4 +- .../apidoc/core/schema/Node.java | 5 +- .../apidoc/core/schema/Project.java | 7 +- .../apidoc/core/schema/Row.java | 3 +- .../apidoc/core/schema/Section.java | 6 +- .../apidoc/core/schema/Tag.java | 4 +- .../apidoc/springmvc/SpringParser.java | 2 + .../spring/advanced/UserController.java | 64 ++++++++++++++++++- 19 files changed, 122 insertions(+), 31 deletions(-) diff --git a/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/common/description/ArrayTypeDescription.java b/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/common/description/ArrayTypeDescription.java index d4cebc3..b6b014b 100644 --- a/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/common/description/ArrayTypeDescription.java +++ b/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/common/description/ArrayTypeDescription.java @@ -3,6 +3,7 @@ package com.github.fengyuchenglun.apidoc.core.common.description; import com.github.fengyuchenglun.apidoc.core.common.ObjectMappers; import com.github.fengyuchenglun.apidoc.core.schema.Row; import com.fasterxml.jackson.databind.node.ArrayNode; +import lombok.Data; import java.util.ArrayList; import java.util.Collection; @@ -10,6 +11,7 @@ import java.util.Collection; /** * 数组类型描述 */ +@Data public class ArrayTypeDescription extends TypeDescription { protected ArrayNode value; diff --git a/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/common/description/ObjectTypeDescription.java b/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/common/description/ObjectTypeDescription.java index 4b6fd05..c138f62 100644 --- a/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/common/description/ObjectTypeDescription.java +++ b/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/common/description/ObjectTypeDescription.java @@ -4,6 +4,7 @@ import com.github.fengyuchenglun.apidoc.core.common.ObjectMappers; import com.github.fengyuchenglun.apidoc.core.schema.Row; import com.fasterxml.jackson.databind.node.ObjectNode; import com.google.common.collect.Lists; +import lombok.Data; import lombok.Getter; import lombok.Setter; @@ -16,8 +17,7 @@ import java.util.List; * @author fengyuchenglun * @version 1.0.0 */ -@Setter -@Getter +@Data public class ObjectTypeDescription extends TypeDescription { /** @@ -29,6 +29,12 @@ public class ObjectTypeDescription extends TypeDescription { */ private ObjectNode value = ObjectMappers.instance.createObjectNode(); + @Override + public void setRequired(Boolean required) { + this.required = required; + this.members.get(0).setRequired(required); + } + /** * Merge. * diff --git a/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/common/description/PrimitiveTypeDescription.java b/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/common/description/PrimitiveTypeDescription.java index 71d36d2..5b64174 100644 --- a/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/common/description/PrimitiveTypeDescription.java +++ b/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/common/description/PrimitiveTypeDescription.java @@ -2,10 +2,12 @@ package com.github.fengyuchenglun.apidoc.core.common.description; import com.github.javaparser.resolution.types.ResolvedPrimitiveType; import com.github.javaparser.resolution.types.ResolvedReferenceType; +import lombok.Data; /** * 原始类型描述 */ +@Data public class PrimitiveTypeDescription extends TypeDescription { /** diff --git a/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/common/description/StringTypeDescription.java b/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/common/description/StringTypeDescription.java index 597be89..d866428 100644 --- a/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/common/description/StringTypeDescription.java +++ b/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/common/description/StringTypeDescription.java @@ -1,8 +1,11 @@ package com.github.fengyuchenglun.apidoc.core.common.description; +import lombok.Data; + /** * 字符串类型 */ +@Data public class StringTypeDescription extends TypeDescription { /** diff --git a/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/common/description/TypeDescription.java b/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/common/description/TypeDescription.java index 690c3f7..ff53410 100644 --- a/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/common/description/TypeDescription.java +++ b/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/common/description/TypeDescription.java @@ -6,6 +6,7 @@ import com.github.fengyuchenglun.apidoc.core.schema.Row; import com.github.javaparser.ast.comments.Comment; import com.github.javaparser.javadoc.Javadoc; import com.google.common.collect.Lists; +import lombok.Data; import lombok.Getter; import lombok.Setter; @@ -13,9 +14,9 @@ import java.util.Collection; /** * The type Type description. + * @author duanledexianxianxian */ -@Setter -@Getter +@Data public abstract class TypeDescription { /** @@ -46,10 +47,11 @@ public abstract class TypeDescription { * 默认值. */ protected Object defaultValue; + /** * 是否必填. */ - protected Boolean required; + protected Boolean required=false; /** * Is available boolean. @@ -185,11 +187,11 @@ public abstract class TypeDescription { def = ""; } - if (required != null) { - condition.append("required=").append(required); - } +// if (required != null) { +// condition.append("required=").append(required); +// } - return Lists.newArrayList(new Row(key, type, false, condition.toString(), def, remark, requestParameterType)); + return Lists.newArrayList(new Row(key, type, required, condition.toString(), def, remark, requestParameterType)); } diff --git a/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/common/description/UnAvailableTypeDescription.java b/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/common/description/UnAvailableTypeDescription.java index 4261239..2856799 100644 --- a/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/common/description/UnAvailableTypeDescription.java +++ b/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/common/description/UnAvailableTypeDescription.java @@ -1,12 +1,15 @@ package com.github.fengyuchenglun.apidoc.core.common.description; import com.github.fengyuchenglun.apidoc.core.schema.Row; +import lombok.Data; import java.util.Collection; /** * 未知类型,应该忽略 + * @author duanledexianxianxian */ +@Data public class UnAvailableTypeDescription extends TypeDescription { public UnAvailableTypeDescription() { diff --git a/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/render/MarkdownRender.java b/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/render/MarkdownRender.java index 6e95f2a..a587fdf 100644 --- a/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/render/MarkdownRender.java +++ b/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/render/MarkdownRender.java @@ -43,6 +43,7 @@ public class MarkdownRender implements ProjectRender { } private void build(Project project) throws Exception { + System.out.println(project); String templatePath = ApiDoc.getInstance().getContext().getMarkdownTemplate(); String id = ApiDoc.getInstance().getContext().getId(); Path buildPath = ApiDoc.getInstance().getContext().getBuildPath(); diff --git a/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/schema/Appendix.java b/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/schema/Appendix.java index 058765d..4a8d396 100644 --- a/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/schema/Appendix.java +++ b/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/schema/Appendix.java @@ -5,6 +5,8 @@ import com.github.javaparser.ast.comments.JavadocComment; import com.github.javaparser.ast.nodeTypes.NodeWithSimpleName; import com.github.fengyuchenglun.apidoc.core.common.helper.EnumHelper; import com.github.fengyuchenglun.apidoc.core.common.helper.FieldHelper; +import lombok.Data; +import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.Setter; @@ -15,8 +17,8 @@ import java.util.List; /** * 附录 */ -@Setter -@Getter +@Data +@EqualsAndHashCode(callSuper=true) public class Appendix extends Node { /** diff --git a/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/schema/Book.java b/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/schema/Book.java index 20045d3..6222b98 100644 --- a/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/schema/Book.java +++ b/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/schema/Book.java @@ -1,5 +1,7 @@ package com.github.fengyuchenglun.apidoc.core.schema; +import lombok.Data; +import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.Setter; @@ -12,8 +14,8 @@ import java.util.TreeSet; * @author fengyuchenglun * @version 1.0.0 */ -@Setter -@Getter +@Data +@EqualsAndHashCode(callSuper=true) public class Book extends Node { /** diff --git a/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/schema/Cell.java b/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/schema/Cell.java index b2fee04..e364c74 100644 --- a/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/schema/Cell.java +++ b/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/schema/Cell.java @@ -1,6 +1,7 @@ package com.github.fengyuchenglun.apidoc.core.schema; import com.google.common.collect.Lists; +import lombok.Data; import java.util.List; @@ -9,6 +10,7 @@ import java.util.List; * * @param the type parameter */ +@Data public class Cell { /** diff --git a/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/schema/Chapter.java b/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/schema/Chapter.java index 9b7da8e..745a554 100644 --- a/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/schema/Chapter.java +++ b/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/schema/Chapter.java @@ -1,5 +1,7 @@ package com.github.fengyuchenglun.apidoc.core.schema; +import lombok.Data; +import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.Setter; @@ -12,15 +14,14 @@ import java.util.TreeSet; * @author fengyuchenglun * @version 1.0.0 */ -@Setter -@Getter +@Data +@EqualsAndHashCode(callSuper = true) public class Chapter extends Node { /** * The Book name. */ String bookName; - Project project; /** * The Sections. diff --git a/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/schema/Header.java b/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/schema/Header.java index 481bb49..1b0778e 100644 --- a/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/schema/Header.java +++ b/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/schema/Header.java @@ -1,5 +1,6 @@ package com.github.fengyuchenglun.apidoc.core.schema; +import lombok.Data; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; @@ -10,8 +11,7 @@ import lombok.Setter; * @author fengyuchenglun * @version 1.0.0 */ -@Setter -@Getter +@Data @NoArgsConstructor public class Header { diff --git a/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/schema/Node.java b/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/schema/Node.java index aeaf8ea..3e29c12 100644 --- a/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/schema/Node.java +++ b/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/schema/Node.java @@ -5,6 +5,8 @@ import com.github.javaparser.ast.comments.Comment; import com.github.javaparser.javadoc.Javadoc; import com.github.fengyuchenglun.apidoc.core.common.helper.CommentHelper; import com.github.fengyuchenglun.apidoc.core.common.helper.StringHelper; +import lombok.Data; +import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.Setter; @@ -19,8 +21,7 @@ import java.util.Optional; * @author fengyuchenglun * @version 1.0.0 */ -@Setter -@Getter +@Data public class Node implements Comparable { /** * 节点类型 diff --git a/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/schema/Project.java b/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/schema/Project.java index 43609d4..9036a1a 100644 --- a/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/schema/Project.java +++ b/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/schema/Project.java @@ -1,6 +1,8 @@ package com.github.fengyuchenglun.apidoc.core.schema; import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; +import lombok.Data; +import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.Setter; @@ -13,8 +15,8 @@ import java.util.*; * @author fengyuchenglun * @version 1.0.0 */ -@Setter -@Getter +@Data +@EqualsAndHashCode(callSuper = true) public class Project extends Node { /** @@ -42,7 +44,6 @@ public class Project extends Node { * @param chapter the chapter */ public void addChapter(Chapter chapter) { - chapter.setProject(this); if (Objects.isNull(chapter.getBookName())) { chapter.setBookName(Book.DEFAULT); } diff --git a/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/schema/Row.java b/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/schema/Row.java index 13adc24..22956b9 100644 --- a/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/schema/Row.java +++ b/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/schema/Row.java @@ -11,8 +11,7 @@ import lombok.*; @EqualsAndHashCode @NoArgsConstructor @AllArgsConstructor -@Setter -@Getter +@Data public class Row { /** diff --git a/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/schema/Section.java b/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/schema/Section.java index 6d69374..1d83c65 100644 --- a/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/schema/Section.java +++ b/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/schema/Section.java @@ -5,6 +5,8 @@ import com.github.fengyuchenglun.apidoc.core.common.QueryStringBuilder; import com.github.fengyuchenglun.apidoc.core.common.helper.StringHelper; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.node.ObjectNode; +import lombok.Data; +import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.Setter; import org.apache.commons.lang3.StringUtils; @@ -17,8 +19,8 @@ import java.util.*; * @author fengyuchenglun * @version 1.0.0 */ -@Setter -@Getter +@Data +@EqualsAndHashCode(callSuper=true) public class Section extends Node { /** diff --git a/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/schema/Tag.java b/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/schema/Tag.java index 5122332..d00bbd3 100644 --- a/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/schema/Tag.java +++ b/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/schema/Tag.java @@ -1,5 +1,6 @@ package com.github.fengyuchenglun.apidoc.core.schema; +import lombok.Data; import lombok.Getter; import lombok.Setter; import lombok.extern.slf4j.Slf4j; @@ -14,8 +15,7 @@ import java.util.Objects; * @version 1.0.0 */ @Slf4j -@Setter -@Getter +@Data public class Tag { /** diff --git a/apidoc-springmvc/src/main/java/com/github/fengyuchenglun/apidoc/springmvc/SpringParser.java b/apidoc-springmvc/src/main/java/com/github/fengyuchenglun/apidoc/springmvc/SpringParser.java index 6a63490..9f4d066 100644 --- a/apidoc-springmvc/src/main/java/com/github/fengyuchenglun/apidoc/springmvc/SpringParser.java +++ b/apidoc-springmvc/src/main/java/com/github/fengyuchenglun/apidoc/springmvc/SpringParser.java @@ -265,6 +265,8 @@ public class SpringParser implements ParserStrategy { Optional optional = parameter.getAnnotationByName(ParameterHelper.ANNOTATION_REQUEST_PARAM); if (optional.isPresent()) { + // 如果有RequestParam注解,则参数必填 + required = true; Optional valueOptional = AnnotationHelper.getAnyAttribute(optional.get(), "value", "name"); if (valueOptional.isPresent()) { key = String.valueOf(ExpressionHelper.getValue(valueOptional.get())); diff --git a/apidoc-springmvc/src/test/java/com/github/fengyuchenglun/example/spring/advanced/UserController.java b/apidoc-springmvc/src/test/java/com/github/fengyuchenglun/example/spring/advanced/UserController.java index ab2765b..046aba5 100644 --- a/apidoc-springmvc/src/test/java/com/github/fengyuchenglun/example/spring/advanced/UserController.java +++ b/apidoc-springmvc/src/test/java/com/github/fengyuchenglun/example/spring/advanced/UserController.java @@ -3,6 +3,7 @@ package com.github.fengyuchenglun.example.spring.advanced; import com.github.fengyuchenglun.example.annotation.KimController; import com.github.fengyuchenglun.example.common.Query; import com.github.fengyuchenglun.example.common.User; +import com.github.fengyuchenglun.example.common.UserQuery; import lombok.Data; import org.springframework.web.bind.annotation.*; @@ -42,7 +43,7 @@ public class UserController { * @return 用户对象 user */ @GetMapping(value = "/detail1") - public User detail1( Query query) { + public User detail1(Query query) { User user = new User(); return user; } @@ -59,6 +60,65 @@ public class UserController { return user; } + /** + * 查看用户详情 + * + * @param query 过滤条件 + * @return 用户对象 user + */ + @GetMapping(value = "/detail4") + public User detail4(@RequestParam(required = false) Query query) { + User user = new User(); + return user; + } + + /** + * 查看用户详情 + * + * @return 用户对象 user + */ + @GetMapping(value = "/detail5") + public User detail5() { + User user = new User(); + return user; + } + + /** + * 查看用户详情 + * + * @param userName the user name + * @param age the age + * @param query the query + * @return 用户对象 user + */ + @GetMapping(value = "/detail6") + public User detail6(String userName, Integer age, UserQuery query) { + User user = new User(); + return user; + } + + /** + * 查看用户详情 + * + * @return 用户对象 user + */ + @GetMapping(value = "/detail7") + public void detail7() { + } + + + /** + * 删除用户 + * + * @param userId the user id + * @return boolean 是否成功 + */ + @DeleteMapping(value = "/{userId}") + public Boolean deleteUser(@PathVariable("userId") Long userId) { + return true; + } + + /** * 用户表单对象. * @@ -86,7 +146,7 @@ public class UserController { * 添加用户 * * @param form 用户表单对象 - * @return integer integer + * @return integer 返回记录 */ @PostMapping public Integer add(@RequestBody UserForm form) { -- GitLab