From 678ef8b4b0bc30abe63b67738f7eae13a0673d94 Mon Sep 17 00:00:00 2001 From: duanledexianxianxian Date: Tue, 28 Jul 2020 14:40:50 +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 --- .../fengyuchenglun/apidoc/core/Context.java | 10 +- .../apidoc/core/common/Assert.java | 25 ++ .../apidoc/core/common/Constants.java | 13 + .../apidoc/core/common/ObjectMappers.java | 21 ++ .../core/common/QueryStringBuilder.java | 21 ++ .../apidoc/core/common/URI.java | 41 +++ .../core/common/convert/FieldTypeConvert.java | 34 +- .../description/ArrayTypeDescription.java | 2 +- .../description/ObjectTypeDescription.java | 6 + .../description/StringTypeDescription.java | 1 + .../common/description/TypeDescription.java | 26 +- .../apidoc/core/common/diff/FileMatcher.java | 1 + .../apidoc/core/common/diff/FileSystem.java | 3 + .../core/common/enums/FieldShowWay.java | 17 + .../core/common/helper/AnnotationHelper.java | 3 + .../common/helper/ClassDeclarationHelper.java | 3 + .../core/common/helper/CommentHelper.java | 1 + .../common/helper/CompilationUnitHelper.java | 10 + .../core/common/helper/FieldHelper.java | 1 + .../apidoc/core/common/helper/FileHelper.java | 17 + .../common/helper/JsonPropertyHelper.java | 28 ++ .../core/common/helper/ReferenceContext.java | 1 + .../core/common/helper/StringHelper.java | 3 + .../core/common/helper/TypeNameHelper.java | 17 + .../common/helper/TypeParameterHelper.java | 3 + .../core/common/markup/asciidoc/AsciiDoc.java | 151 +++++++++ .../markup/asciidoc/AsciiDocBuilder.java | 25 ++ .../core/common/markup/asciidoc/Color.java | 1 + .../core/common/markup/markdown/Markdown.java | 69 ---- .../markup/markdown/MarkdownBuilder.java | 303 ------------------ .../core/resolver/CollectionTypeResolver.java | 17 + .../core/resolver/DateTypeResolver.java | 17 + .../core/resolver/EnumTypeResolver.java | 5 + .../apidoc/core/resolver/MapTypeResolver.java | 14 + .../core/resolver/ObjectTypeResolver.java | 8 + .../core/resolver/StringTypeResolver.java | 17 + .../resolver/SystemObjectTypeResolver.java | 17 + .../apidoc/core/schema/Row.java | 55 +++- .../apidoc/core/schema/Section.java | 19 +- .../src/main/resources/templates/markdown.ftl | 27 +- .../apidoc/springmvc/ParameterHelper.java | 3 +- .../apidoc/springmvc/SpringParser.java | 19 ++ .../fengyuchenglun/example/common/Query.java | 8 +- .../example/common/ResultData.java | 2 + .../fengyuchenglun/example/common/User.java | 54 ++-- .../spring/advanced/UserController.java | 285 +++++++++------- 46 files changed, 845 insertions(+), 579 deletions(-) create mode 100644 apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/common/enums/FieldShowWay.java delete mode 100644 apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/common/markup/markdown/Markdown.java delete mode 100644 apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/common/markup/markdown/MarkdownBuilder.java diff --git a/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/Context.java b/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/Context.java index effafc9..1998227 100644 --- a/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/Context.java +++ b/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/Context.java @@ -1,6 +1,7 @@ package com.github.fengyuchenglun.apidoc.core; import com.github.fengyuchenglun.apidoc.core.common.Constants; +import com.github.fengyuchenglun.apidoc.core.common.enums.FieldShowWay; import com.github.fengyuchenglun.apidoc.core.render.AsciiDocRender; import com.github.fengyuchenglun.apidoc.core.render.PostmanRender; import com.google.common.collect.Lists; @@ -44,7 +45,6 @@ public class Context { public static final String DEFAULT_CODE_STRUCTURE = "src/main/java"; - /** * 设置当前解析框架 */ @@ -115,6 +115,14 @@ public class Context { @Setter private String markdownTemplate = Constants.MARKDOWN_TEMPLATE; + /** + * 字段显示方式. + * 1. 平级(默认) + * 2. tree + */ + @Setter + private FieldShowWay fileShowWay= FieldShowWay.FLAT; + /** * 自定义扩展参数 */ diff --git a/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/common/Assert.java b/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/common/Assert.java index b0b887e..51efcc9 100644 --- a/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/common/Assert.java +++ b/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/common/Assert.java @@ -2,18 +2,43 @@ package com.github.fengyuchenglun.apidoc.core.common; import com.google.common.base.Strings; +/** + * The type Assert. + * + * @author duanledexianxianxian + */ public class Assert { + /** + * Is blank boolean. + * + * @param text the text + * @return the boolean + */ public static boolean isBlank(String text) { return Strings.isNullOrEmpty(text) || Strings.isNullOrEmpty(text.trim()); } + /** + * Not blank. + * + * @param text the text + * @param message the message + */ public static void notBlank(String text, String message) { if (Strings.isNullOrEmpty(text) || Strings.isNullOrEmpty(text.trim())) { throw new IllegalArgumentException(message); } } + /** + * Between. + * + * @param num the num + * @param min the min + * @param max the max + * @param message the message + */ public static void between(int num, int min, int max, String message) { if (num < min || num > max) { throw new IllegalArgumentException(message); diff --git a/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/common/Constants.java b/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/common/Constants.java index 69cf594..6e5e037 100644 --- a/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/common/Constants.java +++ b/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/common/Constants.java @@ -31,5 +31,18 @@ public class Constants { * 自定义tag-mock */ public static final String TAG_CUSTOM_JAVA_DOC_MOCK = "mock"; + /** + * 自定义tag-data + */ + public static final String TAG_CUSTOM_JAVA_DOC_DATA = "data"; + /** + * javadoc-tag-return + */ + public static final String TAG_JAVA_DOC_RETURN = "return"; + + /** + * 空格符 + */ + public static final String FIELD_SPACE = "     "; } diff --git a/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/common/ObjectMappers.java b/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/common/ObjectMappers.java index 6e4d36e..c888c4e 100644 --- a/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/common/ObjectMappers.java +++ b/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/common/ObjectMappers.java @@ -7,8 +7,16 @@ import com.fasterxml.jackson.databind.node.ObjectNode; import java.util.Iterator; +/** + * The type Object mappers. + * + * @author duanledexianxianxian + */ public class ObjectMappers { + /** + * The constant instance. + */ public static final ObjectMapper instance; static { @@ -16,6 +24,12 @@ public class ObjectMappers { instance.setSerializationInclusion(JsonInclude.Include.NON_NULL); } + /** + * Pretty string. + * + * @param node the node + * @return the string + */ public static String pretty(Object node) { try { return instance.writerWithDefaultPrettyPrinter().writeValueAsString(node); @@ -24,6 +38,13 @@ public class ObjectMappers { } } + /** + * Merge object node. + * + * @param result the result + * @param nodes the nodes + * @return the object node + */ public static ObjectNode merge(ObjectNode result, ObjectNode... nodes) { if (result != null) { for (ObjectNode node : nodes) { diff --git a/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/common/QueryStringBuilder.java b/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/common/QueryStringBuilder.java index 78a9e41..51b9154 100644 --- a/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/common/QueryStringBuilder.java +++ b/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/common/QueryStringBuilder.java @@ -7,10 +7,25 @@ import org.apache.commons.lang3.ObjectUtils; import java.util.Iterator; +/** + * The type Query string builder. + * + * @author duanledexianxianxian + */ public class QueryStringBuilder { + /** + * The Builder. + */ private StringBuilder builder = new StringBuilder(); + /** + * Append query string builder. + * + * @param key the key + * @param value the value + * @return the query string builder + */ public QueryStringBuilder append(Object key, Object value) { if (builder.length() > 0) { builder.append("&"); @@ -21,6 +36,12 @@ public class QueryStringBuilder { return this; } + /** + * Append query string builder. + * + * @param objectNode the object node + * @return the query string builder + */ public QueryStringBuilder append(ObjectNode objectNode) { Iterator iterator = objectNode.fieldNames(); while (iterator.hasNext()) { diff --git a/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/common/URI.java b/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/common/URI.java index d70d1eb..24f3841 100644 --- a/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/common/URI.java +++ b/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/common/URI.java @@ -9,25 +9,56 @@ import java.util.ArrayList; import java.util.List; import java.util.Objects; +/** + * The type Uri. + * + * @author duanledexianxianxian + */ @Getter @EqualsAndHashCode public class URI { + /** + * The Text. + */ private String text; + /** + * The Next. + */ private URI next; + /** + * Instantiates a new Uri. + */ public URI() { } + /** + * Instantiates a new Uri. + * + * @param text the text + */ public URI(String text) { this.text = text; } + /** + * Add uri. + * + * @param text the text + * @return the uri + */ public URI add(String text) { return add(new URI(text)); } + /** + * Add uri. + * + * @param uri the uri + * @return the uri + */ public URI add(URI uri) { if (next != null) { next.add(uri); @@ -37,6 +68,11 @@ public class URI { return this; } + /** + * Remove. + * + * @param uri the uri + */ public void remove(URI uri) { if (Objects.equals(next, uri)) { next = null; @@ -59,6 +95,11 @@ public class URI { return builder.toString(); } + /** + * Append to. + * + * @param list the list + */ private void appendTo(List list) { if (Objects.nonNull(text)) { list.addAll(Lists.newArrayList(text.split("/"))); diff --git a/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/common/convert/FieldTypeConvert.java b/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/common/convert/FieldTypeConvert.java index 8d8826d..cb9c7c9 100644 --- a/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/common/convert/FieldTypeConvert.java +++ b/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/common/convert/FieldTypeConvert.java @@ -2,71 +2,65 @@ package com.github.fengyuchenglun.apidoc.core.common.convert; import com.google.common.collect.Maps; -import java.sql.JDBCType; -import java.time.LocalDate; -import java.time.LocalDateTime; -import java.time.LocalTime; import java.util.Map; -import java.util.Optional; -import java.util.concurrent.ConcurrentHashMap; /** - * The enum Field type convert. + * 字段转换. * * @author duanledexianxianxian */ public enum FieldTypeConvert implements IFieldTypeConvert { /** - * String field type convert. + * String. */ STRING("String", "String"), /** - * Byte field type convert. + * Byte. */ BYTE("Byte", "Byte"), /** - * Short field type convert. + * Short. */ SHORT("Integer", "Short"), /** - * Char field type convert. + * Char. */ CHAR("String", "Char"), /** - * Int field type convert. + * Int. */ INT("Integer", "int"), /** - * Long field type convert. + * Long. */ LONG("Long", "Long"), /** - * Boolean field type convert. + * Boolean. */ BOOLEAN("Boolean", "Boolean"), /** - * Float field type convert. + * Float. */ FLOAT("Float", "Float"), /** - * Double field type convert. + * Double. */ DOUBLE("Double", "Double"), /** - * Local date field type convert. + * Local date. */ LOCAL_DATE("Date", "LocalDate"), /** - * Local date time field type convert. + * Local date time. */ LOCAL_DATE_TIME("DateTime", "LocalDateTime"), /** - * Local time field type convert. + * Local time. */ LOCAL_TIME("Time", "LocalTime"), /** - * Other field type convert. + * Other. */ OTHER("object", "Object"), ; 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 f26aa65..1e1c974 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 @@ -105,7 +105,7 @@ public class ArrayTypeDescription extends TypeDescription { @Override public String fullKey() { - return StringHelper.join("[].", prefix, key); + return StringHelper.join(".", prefix, key); } @Override 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 6c70f11..fe3bd08 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 @@ -1,6 +1,7 @@ package com.github.fengyuchenglun.apidoc.core.common.description; import com.github.fengyuchenglun.apidoc.core.common.ObjectMappers; +import com.github.fengyuchenglun.apidoc.core.common.helper.StringHelper; import com.github.fengyuchenglun.apidoc.core.schema.Row; import com.fasterxml.jackson.databind.node.ObjectNode; import com.google.common.collect.Lists; @@ -121,6 +122,11 @@ public class ObjectTypeDescription extends TypeDescription { } } + @Override + public String fullKey() { + return StringHelper.join(".", prefix, key); + } + @Override public ObjectNode getValue() { return value; 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 cda9563..de0803a 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 @@ -5,6 +5,7 @@ import lombok.EqualsAndHashCode; /** * 字符串类型 + * @author duanledexianxianxian */ @EqualsAndHashCode(callSuper = true) @Data 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 1377c57..5371ce9 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 @@ -20,6 +20,7 @@ import java.util.HashMap; import java.util.Map; import java.util.Optional; +import static com.github.fengyuchenglun.apidoc.core.common.Constants.TAG_CUSTOM_JAVA_DOC_DATA; import static com.github.fengyuchenglun.apidoc.core.common.Constants.TAG_CUSTOM_JAVA_DOC_MOCK; /** @@ -78,6 +79,12 @@ public abstract class TypeDescription { */ protected Boolean required = false; + + /** + * The Level. + */ + protected Integer level = 0; + /** * Is available boolean. * @@ -180,7 +187,7 @@ public abstract class TypeDescription { if (remark == null) { remark = value; } else { - remark += " " + value; + remark = StringUtils.isNotBlank(remark) ? remark : value; } } @@ -206,9 +213,9 @@ public abstract class TypeDescription { return Lists.newArrayList(); } String def; - if (null != tags.get(TAG_CUSTOM_JAVA_DOC_MOCK)) { - def = tags.get(TAG_CUSTOM_JAVA_DOC_MOCK).getContent(); - } else if (defaultValue != null) { + + + if (defaultValue != null) { def = String.valueOf(defaultValue); } else if (value != null) { def = String.valueOf(value); @@ -216,11 +223,20 @@ public abstract class TypeDescription { def = ""; } + String mock = def; + if (null != tags.get(TAG_CUSTOM_JAVA_DOC_MOCK)) { + mock = tags.get(TAG_CUSTOM_JAVA_DOC_MOCK).getContent(); + } + Boolean isData = false; + if (null != tags.get(TAG_CUSTOM_JAVA_DOC_DATA)) { + isData = true; + } + // if (required != null) { // condition.append("required=").append(required); // } - return Lists.newArrayList(new Row(fullKey, type, required, condition.toString(), def, remark, parameterType)); + return Lists.newArrayList(new Row(fullKey, type, required, condition.toString(), def, remark, mock, parameterType, isData)); } diff --git a/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/common/diff/FileMatcher.java b/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/common/diff/FileMatcher.java index 753a331..db8d876 100644 --- a/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/common/diff/FileMatcher.java +++ b/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/common/diff/FileMatcher.java @@ -15,6 +15,7 @@ import java.util.List; /** * 文件对比工具 + * @author duanledexianxianxian */ @Getter public class FileMatcher { diff --git a/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/common/diff/FileSystem.java b/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/common/diff/FileSystem.java index c4d97cd..dfb9a1a 100644 --- a/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/common/diff/FileSystem.java +++ b/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/common/diff/FileSystem.java @@ -6,6 +6,9 @@ import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; +/** + * @author duanledexianxianxian + */ public class FileSystem { public static boolean open(Path path) { diff --git a/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/common/enums/FieldShowWay.java b/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/common/enums/FieldShowWay.java new file mode 100644 index 0000000..672aeec --- /dev/null +++ b/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/common/enums/FieldShowWay.java @@ -0,0 +1,17 @@ +package com.github.fengyuchenglun.apidoc.core.common.enums; + +/** + * 字段显示方式 + * + * @author duanledexianxianxian + */ +public enum FieldShowWay { + /** + * 平级方式. + */ + FLAT, + /** + * 树级目录. + */ + TREE +} diff --git a/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/common/helper/AnnotationHelper.java b/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/common/helper/AnnotationHelper.java index 3c3559e..6659acf 100644 --- a/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/common/helper/AnnotationHelper.java +++ b/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/common/helper/AnnotationHelper.java @@ -7,6 +7,9 @@ import java.util.List; import java.util.Objects; import java.util.Optional; +/** + * @author duanledexianxianxian + */ public class AnnotationHelper { public static boolean isAnnotationPresent(NodeWithAnnotations node, List annotationNames) { diff --git a/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/common/helper/ClassDeclarationHelper.java b/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/common/helper/ClassDeclarationHelper.java index 4cae235..95a4909 100644 --- a/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/common/helper/ClassDeclarationHelper.java +++ b/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/common/helper/ClassDeclarationHelper.java @@ -9,6 +9,9 @@ import lombok.extern.slf4j.Slf4j; import java.util.Optional; +/** + * @author duanledexianxianxian + */ @Slf4j public class ClassDeclarationHelper { diff --git a/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/common/helper/CommentHelper.java b/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/common/helper/CommentHelper.java index 5ab3e2c..b56be7c 100644 --- a/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/common/helper/CommentHelper.java +++ b/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/common/helper/CommentHelper.java @@ -17,6 +17,7 @@ import java.util.stream.Collectors; /** * The type Comment helper. + * @author duanledexianxianxian */ public class CommentHelper { diff --git a/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/common/helper/CompilationUnitHelper.java b/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/common/helper/CompilationUnitHelper.java index b88c4af..52f7e7c 100644 --- a/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/common/helper/CompilationUnitHelper.java +++ b/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/common/helper/CompilationUnitHelper.java @@ -5,8 +5,18 @@ import com.github.javaparser.ast.Node; import java.util.Optional; +/** + * The type Compilation unit helper. + * @author duanledexianxianxian + */ public class CompilationUnitHelper { + /** + * Gets compilation unit. + * + * @param node the node + * @return the compilation unit + */ public static Optional getCompilationUnit(Node node) { if (node instanceof CompilationUnit) { return Optional.of((CompilationUnit) node); diff --git a/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/common/helper/FieldHelper.java b/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/common/helper/FieldHelper.java index c3afa25..eda83da 100644 --- a/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/common/helper/FieldHelper.java +++ b/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/common/helper/FieldHelper.java @@ -14,6 +14,7 @@ import java.util.Optional; /** * The type Field helper. + * @author duanledexianxianxian */ public class FieldHelper { diff --git a/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/common/helper/FileHelper.java b/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/common/helper/FileHelper.java index f4ac61f..342d158 100644 --- a/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/common/helper/FileHelper.java +++ b/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/common/helper/FileHelper.java @@ -11,9 +11,19 @@ import java.nio.file.Path; import java.util.List; import java.util.stream.Collectors; +/** + * The type File helper. + * @author duanledexianxianxian + */ @Slf4j public class FileHelper { + /** + * Write. + * + * @param file the file + * @param content the content + */ public static void write(Path file, String content) { if (file.getParent() != null) { @@ -32,6 +42,13 @@ public class FileHelper { } } + /** + * Find list. + * + * @param start the start + * @param structure the structure + * @return the list + */ public static List find(Path start, String structure) { try { return Files.walk(start) diff --git a/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/common/helper/JsonPropertyHelper.java b/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/common/helper/JsonPropertyHelper.java index 1ae4e22..72adbc7 100644 --- a/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/common/helper/JsonPropertyHelper.java +++ b/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/common/helper/JsonPropertyHelper.java @@ -8,12 +8,32 @@ import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParse import java.util.Optional; +/** + * The type Json property helper. + * + * @author duanledexianxianxian + */ public class JsonPropertyHelper { + /** + * The constant ANNOTAION_JSON_PROPERTY. + */ public static final String ANNOTAION_JSON_PROPERTY = "JsonProperty"; + /** + * The constant ANNOTAION_JSON_FIELD. + */ public static final String ANNOTAION_JSON_FIELD = "JSONField"; + /** + * The constant ANNOTAION_SERIALIZED_NAME. + */ public static final String ANNOTAION_SERIALIZED_NAME = "SerializedName"; + /** + * Get json name optional. + * + * @param declaredField the declared field + * @return the optional + */ public static Optional getJsonName(ResolvedFieldDeclaration declaredField){ if(declaredField instanceof JavaParserFieldDeclaration){ FieldDeclaration fieldDeclaration = ((JavaParserFieldDeclaration) declaredField).getWrappedNode(); @@ -26,6 +46,14 @@ public class JsonPropertyHelper { return Optional.empty(); } + /** + * Get string value optional. + * + * @param fieldDeclaration the field declaration + * @param anno the anno + * @param attr the attr + * @return the optional + */ public static Optional getStringValue(FieldDeclaration fieldDeclaration, String anno, String attr){ Optional optional = fieldDeclaration.getAnnotationByName(anno); if (optional.isPresent()) { diff --git a/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/common/helper/ReferenceContext.java b/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/common/helper/ReferenceContext.java index 625fad4..d638098 100644 --- a/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/common/helper/ReferenceContext.java +++ b/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/common/helper/ReferenceContext.java @@ -6,6 +6,7 @@ import java.util.Set; /** * 解决循环依赖问题 + * @author duanledexianxianxian */ public class ReferenceContext { diff --git a/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/common/helper/StringHelper.java b/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/common/helper/StringHelper.java index f71b5df..a0ed308 100644 --- a/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/common/helper/StringHelper.java +++ b/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/common/helper/StringHelper.java @@ -2,6 +2,9 @@ package com.github.fengyuchenglun.apidoc.core.common.helper; import com.google.common.base.Strings; +/** + * @author duanledexianxianxian + */ public class StringHelper { public static boolean isBlank(String text) { diff --git a/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/common/helper/TypeNameHelper.java b/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/common/helper/TypeNameHelper.java index 90e5c10..f270fc1 100644 --- a/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/common/helper/TypeNameHelper.java +++ b/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/common/helper/TypeNameHelper.java @@ -6,8 +6,18 @@ import com.github.javaparser.ast.type.Type; import java.util.Optional; +/** + * The type Type name helper. + * @author duanledexianxianxian + */ public class TypeNameHelper { + /** + * Get name string. + * + * @param type the type + * @return the string + */ public static String getName(Type type){ String name = type.toString(); if(type.isClassOrInterfaceType()){ @@ -21,6 +31,13 @@ public class TypeNameHelper { return name; } + /** + * Get name from import string. + * + * @param name the name + * @param compilationUnit the compilation unit + * @return the string + */ private static String getNameFromImport(String name, CompilationUnit compilationUnit){ int dotPos = name.indexOf('.'); String prefix = null; diff --git a/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/common/helper/TypeParameterHelper.java b/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/common/helper/TypeParameterHelper.java index 3412991..6191149 100644 --- a/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/common/helper/TypeParameterHelper.java +++ b/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/common/helper/TypeParameterHelper.java @@ -9,6 +9,9 @@ import java.util.List; import java.util.Objects; import java.util.Optional; +/** + * @author duanledexianxianxian + */ public class TypeParameterHelper { /** diff --git a/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/common/markup/asciidoc/AsciiDoc.java b/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/common/markup/asciidoc/AsciiDoc.java index d86e0c6..abd3c01 100644 --- a/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/common/markup/asciidoc/AsciiDoc.java +++ b/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/common/markup/asciidoc/AsciiDoc.java @@ -1,66 +1,210 @@ package com.github.fengyuchenglun.apidoc.core.common.markup.asciidoc; +/** + * The enum Ascii doc. + * @author duanledexianxianxian + */ public enum AsciiDoc implements CharSequence { + /** + * Extension ascii doc. + */ EXTENSION(".adoc"), /** * 各种关键字 */ HEADER("= "), + /** + * Table ascii doc. + */ TABLE("|==="), + /** + * Table cell ascii doc. + */ TABLE_CELL("|"), + /** + * Title ascii doc. + */ TITLE("="), + /** + * Emphasized ascii doc. + */ EMPHASIZED("_"), + /** + * Strong ascii doc. + */ STRONG("*"), + /** + * Monospaced ascii doc. + */ MONOSPACED("+"), + /** + * Quoted ascii doc. + */ QUOTED("`"), + /** + * Double quoted ascii doc. + */ DOUBLE_QUOTED("``"), + /** + * Unquoted ascii doc. + */ UNQUOTED("#"), + /** + * List flag ascii doc. + */ LIST_FLAG("1. "), + /** + * List flag letter ascii doc. + */ LIST_FLAG_LETTER("a. "), + /** + * List flag letter upper ascii doc. + */ LIST_FLAG_LETTER_UPPER("A. "), + /** + * Listing ascii doc. + */ LISTING("----"), + /** + * Literal ascii doc. + */ LITERAL("...."), + /** + * Sidebar ascii doc. + */ SIDEBAR("****"), + /** + * Comment ascii doc. + */ COMMENT("////"), + /** + * Passthrough ascii doc. + */ PASSTHROUGH("++++"), + /** + * Quote ascii doc. + */ QUOTE("____"), + /** + * Example ascii doc. + */ EXAMPLE("===="), + /** + * Note ascii doc. + */ NOTE("NOTE"), + /** + * Tip ascii doc. + */ TIP("TIP"), + /** + * Important ascii doc. + */ IMPORTANT("IMPORTANT"), + /** + * Warning ascii doc. + */ WARNING("WARNING"), + /** + * Caution ascii doc. + */ CAUTION("CAUTION"), + /** + * Pagebreaks ascii doc. + */ PAGEBREAKS("<<<"), + /** + * Hardbreaks ascii doc. + */ HARDBREAKS("[%hardbreaks]"), + /** + * Whitespace ascii doc. + */ WHITESPACE(" "), + /** + * Br ascii doc. + */ BR("\r\n"), + /** + * New line ascii doc. + */ NEW_LINE("\r\n\r\n"), + /** + * Hbr ascii doc. + */ HBR(" +"), /** * 文档属性 */ TOC(":toc:"), + /** + * Left ascii doc. + */ LEFT("left"), + /** + * Toc level ascii doc. + */ TOC_LEVEL(":toclevels:"), + /** + * Toc title ascii doc. + */ TOC_TITLE(":toc-title:"), + /** + * Doctype ascii doc. + */ DOCTYPE(":doctype:"), + /** + * Book ascii doc. + */ BOOK("book"), + /** + * Source highlighter ascii doc. + */ SOURCE_HIGHLIGHTER(":source-highlighter:"), + /** + * Prettify ascii doc. + */ PRETTIFY("prettify"), + /** + * Highlightjs ascii doc. + */ HIGHLIGHTJS("highlightjs"), + /** + * Coderay ascii doc. + */ CODERAY("coderay"), /** * 文字样式 */ STYLE_BIG("big"), + /** + * Style small ascii doc. + */ STYLE_SMALL("small"), + /** + * Style underline ascii doc. + */ STYLE_UNDERLINE("underline"), + /** + * Style overline ascii doc. + */ STYLE_OVERLINE("overline"), + /** + * Style line through ascii doc. + */ STYLE_LINE_THROUGH("line-through"), ; + /** + * The Markup. + */ private final String markup; + /** + * Instantiates a new Ascii doc. + * + * @param markup the markup + */ AsciiDoc(final String markup) { this.markup = markup; } @@ -85,6 +229,13 @@ public enum AsciiDoc implements CharSequence { return markup; } + /** + * Attr char sequence. + * + * @param key the key + * @param value the value + * @return the char sequence + */ public static CharSequence attr(AsciiDoc key, Object value){ return key.toString() + " " + String.valueOf(value); } diff --git a/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/common/markup/asciidoc/AsciiDocBuilder.java b/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/common/markup/asciidoc/AsciiDocBuilder.java index dbac701..10d489e 100644 --- a/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/common/markup/asciidoc/AsciiDocBuilder.java +++ b/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/common/markup/asciidoc/AsciiDocBuilder.java @@ -9,10 +9,21 @@ import java.util.Objects; import java.util.function.Consumer; import java.util.regex.Matcher; +/** + * The type Ascii doc builder. + * + * @author duanledexianxianxian + */ public class AsciiDocBuilder implements MarkupBuilder { + /** + * The constant MAX_TITLE. + */ public static final int MAX_TITLE = 6; + /** + * The Content. + */ private StringBuilder content = new StringBuilder(); @Override @@ -241,6 +252,14 @@ public class AsciiDocBuilder implements MarkupBuilder { } + /** + * Style markup builder. + * + * @param flag the flag + * @param text the text + * @param textStyle the text style + * @return the markup builder + */ public MarkupBuilder style(CharSequence flag, String text, CharSequence... textStyle) { if (Assert.isBlank(text)) { return this; @@ -324,6 +343,12 @@ public class AsciiDocBuilder implements MarkupBuilder { content = new StringBuilder(); } + /** + * Nobr string. + * + * @param content the content + * @return the string + */ String nobr(String content) { if (Assert.isBlank(content)) { return content; diff --git a/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/common/markup/asciidoc/Color.java b/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/common/markup/asciidoc/Color.java index 64e0e76..b6f516c 100644 --- a/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/common/markup/asciidoc/Color.java +++ b/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/common/markup/asciidoc/Color.java @@ -2,6 +2,7 @@ package com.github.fengyuchenglun.apidoc.core.common.markup.asciidoc; /** * https://en.wikipedia.org/wiki/Web_colors#HTML_color_names + * @author duanledexianxianxian */ public enum Color implements CharSequence{ WHITE("white"), diff --git a/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/common/markup/markdown/Markdown.java b/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/common/markup/markdown/Markdown.java deleted file mode 100644 index f7ede24..0000000 --- a/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/common/markup/markdown/Markdown.java +++ /dev/null @@ -1,69 +0,0 @@ -package com.github.fengyuchenglun.apidoc.core.common.markup.markdown; - -public enum Markdown implements CharSequence { - EXTENSION(".md"), - /** - * 各种关键字 - */ - HEADER("# "), - TABLE_CELL("|"), - TABLE_ROW("-"), - TABLE_Header("---|"), - TITLE("#"), - EMPHASIZED("**"), - STRONG("**"), - MONOSPACED("`"), - QUOTED("**"), - DOUBLE_QUOTED("**"), - UNQUOTED("**"), - LIST_FLAG("* "), - LISTING("```"), - LITERAL("```"), - SIDEBAR("```"), - COMMENT("```"), - PASSTHROUGH("```"), - QUOTE("> "), - EXAMPLE("===="), - NOTE("NOTE"), - TIP("TIP"), - IMPORTANT("IMPORTANT"), - WARNING("WARNING"), - CAUTION("CAUTION"), - PAGEBREAKS(" "), - WHITESPACE(" "), - BR("\r\n"), - NEW_LINE("\r\n\r\n"), - HBR(" +"), - ; - - private final String markup; - - Markdown(final String markup) { - this.markup = markup; - } - - @Override - public int length() { - return markup.length(); - } - - @Override - public char charAt(int index) { - return markup.charAt(index); - } - - @Override - public CharSequence subSequence(int start, int end) { - return markup.subSequence(start, end); - } - - @Override - public String toString() { - return markup; - } - - public static CharSequence attr(Markdown key, Object value){ - return key.toString() + " " + String.valueOf(value); - } - -} diff --git a/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/common/markup/markdown/MarkdownBuilder.java b/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/common/markup/markdown/MarkdownBuilder.java deleted file mode 100644 index 882ddc4..0000000 --- a/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/common/markup/markdown/MarkdownBuilder.java +++ /dev/null @@ -1,303 +0,0 @@ -package com.github.fengyuchenglun.apidoc.core.common.markup.markdown; - -import com.github.fengyuchenglun.apidoc.core.common.Assert; -import com.github.fengyuchenglun.apidoc.core.common.markup.MarkupBuilder; -import com.google.common.base.Strings; - -import java.util.List; -import java.util.function.Consumer; -import java.util.regex.Matcher; - -public class MarkdownBuilder implements MarkupBuilder { - - public static final int MAX_TITLE = 6; - - private StringBuilder content = new StringBuilder(); - - @Override - public MarkupBuilder header(String text, CharSequence... attrs) { - Assert.notBlank(text, "header must not be blank"); - content.append(Markdown.HEADER); - content.append(nobr(text.trim())); - br(); - return this; - } - - @Override - public MarkupBuilder title(int level, String text) { - Assert.notBlank(text, "header must not be blank"); - Assert.between(level, 1, MAX_TITLE, "title level can not be " + level); - br(); - content.append(Strings.repeat(Markdown.TITLE.toString(), level + 1)).append(Markdown.WHITESPACE) - .append(nobr(text.trim())); - br(); - return this; - } - - @Override - public MarkupBuilder text(String text) { - if (Assert.isBlank(text)) { - return this; - } - content.append(text.trim()); - return this; - } - - @Override - public MarkupBuilder textLine(String text) { - if (Assert.isBlank(text)) { - return this; - } - text(nobr(text)); - br(); - return this; - } - - @Override - public MarkupBuilder paragraph(String text, CharSequence... attrs) { - if (Assert.isBlank(text)) { - return this; - } - text(text); - newLine(); - return this; - } - - @Override - public MarkupBuilder note(String text) { - content.append(Markdown.QUOTE); - paragraph(text); - return this; - } - - @Override - public MarkupBuilder tip(String text) { - content.append(Markdown.QUOTE); - paragraph(text); - return this; - } - - @Override - public MarkupBuilder important(String text) { - content.append(Markdown.QUOTE); - paragraph(text); - return this; - } - - @Override - public MarkupBuilder warning(String text) { - content.append(Markdown.QUOTE); - paragraph(text); - return this; - } - - @Override - public MarkupBuilder caution(String text) { - content.append(Markdown.QUOTE); - paragraph(text); - return this; - } - - @Override - public MarkupBuilder block(Consumer consumer, CharSequence flag, CharSequence... attrs) { - content.append(flag); - br(); - consumer.accept(this); - br(); - content.append(flag); - newLine(); - return this; - - } - - @Override - public MarkupBuilder listing(Consumer consumer, CharSequence... attrs) { - return block(consumer, Markdown.LISTING, attrs); - } - - @Override - public MarkupBuilder literal(Consumer consumer, CharSequence... attrs) { - return block(consumer, Markdown.LISTING, attrs); - } - - @Override - public MarkupBuilder sidebar(Consumer consumer, CharSequence... attrs) { - return block(consumer, Markdown.LISTING, attrs); - } - - @Override - public MarkupBuilder comment(Consumer consumer, CharSequence... attrs) { - return block(consumer, Markdown.LISTING, attrs); - } - - @Override - public MarkupBuilder passthrough(Consumer consumer, CharSequence... attrs) { - return block(consumer, Markdown.LISTING, attrs); - } - - @Override - public MarkupBuilder quote(Consumer consumer, CharSequence... attrs) { - return block(consumer, Markdown.LISTING, attrs); - } - - @Override - public MarkupBuilder example(Consumer consumer, CharSequence... attrs) { - return block(consumer, Markdown.LISTING, attrs); - } - - @Override - public MarkupBuilder list(String text) { - return list(text, Markdown.LIST_FLAG); - } - - @Override - public MarkupBuilder list(String text, CharSequence flag) { - if (!Assert.isBlank(text)) { - content.append(flag).append(nobr(text)); - } - return this; - } - - @Override - public MarkupBuilder url(String text, String url) { - if (!Assert.isBlank(text) && !Assert.isBlank(url)) { - content.append("[").append(nobr(text)).append("](").append(url).append(")"); - br(); - } - return this; - } - - @Override - public MarkupBuilder image(String text, String url) { - if (!Assert.isBlank(text) && !Assert.isBlank(url)) { - text("!"); - url(text, url); - } - return this; - } - - @Override - public MarkupBuilder table(List> data) { - return table(data, true, false); - } - - @Override - public MarkupBuilder table(List> data, boolean header, boolean footer) { - - for (int i = 0; i < data.size(); i++) { - content.append(Markdown.TABLE_CELL); - for (int j = 0; j < data.get(i).size(); j++) { - String value = data.get(i).get(j); - if(value!=null){ - content.append(data.get(i).get(j).replace(Markdown.TABLE_CELL, "\\" + Markdown.TABLE_CELL)); - }else{ - content.append(" "); - } - content.append(Markdown.TABLE_CELL); - } - br(); - if(i==0 && header){ - content.append(Markdown.TABLE_CELL); - for (int j = 0; j < data.get(i).size(); j++) { - content.append(Markdown.TABLE_Header); - } - br(); - } - if(i==data.size()-2 && footer){ - content.append(Markdown.TABLE_CELL); - for (int j = 0; j < data.get(i).size(); j++) { - content.append(Markdown.TABLE_Header); - } - br(); - } - } - newLine(); - return this; - } - - - public MarkupBuilder style(CharSequence flag, String text, CharSequence... textStyle) { - if (Assert.isBlank(text)) { - return this; - } - content.append(flag); - text(text); - content.append(flag); - return this; - - } - - @Override - public MarkupBuilder emphasized(String text, CharSequence... textStyle) { - return style(Markdown.EMPHASIZED, text, textStyle); - } - - @Override - public MarkupBuilder strong(String text, CharSequence... textStyle) { - return style(Markdown.STRONG, text, textStyle); - } - - @Override - public MarkupBuilder monospaced(String text, CharSequence... textStyle) { - return style(Markdown.MONOSPACED, text, textStyle); - } - - @Override - public MarkupBuilder quoted(String text, CharSequence... textStyle) { - return style(Markdown.QUOTE, text, textStyle); - } - - @Override - public MarkupBuilder doubleQuoted(String text, CharSequence... textStyle) { - return style(Markdown.DOUBLE_QUOTED, text, textStyle); - } - - @Override - public MarkupBuilder unquoted(String text, CharSequence... textStyle) { - return style(Markdown.UNQUOTED, text, textStyle); - } - - @Override - public MarkupBuilder br() { - content.append(Markdown.BR); - return this; - } - - @Override - public MarkupBuilder hbr() { - content.append(Markdown.HBR); - return this; - } - - @Override - public MarkupBuilder newLine() { - content.append(Markdown.NEW_LINE); - return this; - } - - @Override - public MarkupBuilder pageBreak() { - content.append(Markdown.PAGEBREAKS); - br(); - return this; - } - - @Override - public String getContent() { - return content.toString(); - } - - @Override - public void clean() { - content = new StringBuilder(); - } - - String nobr(String content) { - if (Assert.isBlank(content)) { - return content; - } - return content.replaceAll(Markdown.BR.toString(), - Matcher.quoteReplacement(Markdown.WHITESPACE.toString())); - } - -} diff --git a/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/resolver/CollectionTypeResolver.java b/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/resolver/CollectionTypeResolver.java index 6acb9d1..ac83577 100644 --- a/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/resolver/CollectionTypeResolver.java +++ b/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/resolver/CollectionTypeResolver.java @@ -10,6 +10,11 @@ import com.google.common.collect.ImmutableList; import java.util.Optional; +/** + * The type Collection type resolver. + * + * @author duanledexianxianxian + */ public class CollectionTypeResolver implements TypeResolver { @Override public boolean accept(ResolvedType type) { @@ -24,6 +29,12 @@ public class CollectionTypeResolver implements TypeResolver { .orElseGet(UnAvailableTypeDescription::new)); } + /** + * Is collection boolean. + * + * @param type the type + * @return the boolean + */ private static boolean isCollection(ResolvedType type){ if(!type.isReferenceType()){ return false; @@ -31,6 +42,12 @@ public class CollectionTypeResolver implements TypeResolver { return isCollection(type.asReferenceType().getId()); } + /** + * Is collection boolean. + * + * @param id the id + * @return the boolean + */ private static boolean isCollection(String id){ return ImmutableList.of("java.util.List", "java.util.Collection", diff --git a/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/resolver/DateTypeResolver.java b/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/resolver/DateTypeResolver.java index c6355e9..53d1d65 100644 --- a/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/resolver/DateTypeResolver.java +++ b/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/resolver/DateTypeResolver.java @@ -5,6 +5,11 @@ import com.github.fengyuchenglun.apidoc.core.common.description.StringTypeDescri import com.github.javaparser.resolution.types.ResolvedType; import com.google.common.collect.ImmutableList; +/** + * The type Date type resolver. + * + * @author duanledexianxianxian + */ public class DateTypeResolver implements TypeResolver { @Override public boolean accept(ResolvedType type) { @@ -16,6 +21,12 @@ public class DateTypeResolver implements TypeResolver { return new StringTypeDescription(type.asReferenceType().getTypeDeclaration().getName(),""); } + /** + * Is date boolean. + * + * @param type the type + * @return the boolean + */ private static boolean isDate(ResolvedType type){ if(!type.isReferenceType()){ return false; @@ -23,6 +34,12 @@ public class DateTypeResolver implements TypeResolver { return isDate(type.asReferenceType().getId()); } + /** + * Is date boolean. + * + * @param id the id + * @return the boolean + */ private static boolean isDate(String id){ return ImmutableList.of("java.util.Date", "java.time.LocalDateTime", diff --git a/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/resolver/EnumTypeResolver.java b/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/resolver/EnumTypeResolver.java index 47b417c..3b01a1d 100644 --- a/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/resolver/EnumTypeResolver.java +++ b/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/resolver/EnumTypeResolver.java @@ -6,6 +6,11 @@ import com.github.javaparser.resolution.declarations.ResolvedEnumConstantDeclara import com.github.javaparser.resolution.declarations.ResolvedEnumDeclaration; import com.github.javaparser.resolution.types.ResolvedType; +/** + * The type Enum type resolver. + * + * @author duanledexianxianxian + */ public class EnumTypeResolver implements TypeResolver { @Override public boolean accept(ResolvedType type) { diff --git a/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/resolver/MapTypeResolver.java b/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/resolver/MapTypeResolver.java index cf63d34..dad7d74 100644 --- a/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/resolver/MapTypeResolver.java +++ b/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/resolver/MapTypeResolver.java @@ -7,8 +7,16 @@ import com.google.common.collect.ImmutableList; /** * 不支持直接使用Map,建议使用DTO + * + * @author duanledexianxianxian */ public class MapTypeResolver implements TypeResolver { + /** + * Is map boolean. + * + * @param type the type + * @return the boolean + */ private static boolean isMap(ResolvedType type) { if (!type.isReferenceType()) { return false; @@ -16,6 +24,12 @@ public class MapTypeResolver implements TypeResolver { return isMap(type.asReferenceType().getId()); } + /** + * Is map boolean. + * + * @param id the id + * @return the boolean + */ private static boolean isMap(String id) { return ImmutableList.of("java.util.Map", "java.util.HashMap", diff --git a/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/resolver/ObjectTypeResolver.java b/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/resolver/ObjectTypeResolver.java index c2a5a83..8c1ea12 100644 --- a/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/resolver/ObjectTypeResolver.java +++ b/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/resolver/ObjectTypeResolver.java @@ -17,6 +17,8 @@ import java.util.Optional; /** * java bean解析 + * + * @author duanledexianxianxian */ public class ObjectTypeResolver implements TypeResolver { @@ -88,6 +90,12 @@ public class ObjectTypeResolver implements TypeResolver { } + /** + * Sets default. + * + * @param declaredField the declared field + * @param fieldDescription the field description + */ private void setDefault(ResolvedFieldDeclaration declaredField, TypeDescription fieldDescription) { Optional optional = CommentHelper.getOptionalComment(declaredField); if (optional.isPresent()) { diff --git a/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/resolver/StringTypeResolver.java b/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/resolver/StringTypeResolver.java index a4e48e4..8346fb6 100644 --- a/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/resolver/StringTypeResolver.java +++ b/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/resolver/StringTypeResolver.java @@ -5,6 +5,11 @@ import com.github.fengyuchenglun.apidoc.core.common.description.StringTypeDescri import com.github.javaparser.resolution.types.ResolvedType; import com.google.common.collect.ImmutableList; +/** + * The type String type resolver. + * + * @author duanledexianxianxian + */ public class StringTypeResolver implements TypeResolver { @Override public boolean accept(ResolvedType type) { @@ -16,6 +21,12 @@ public class StringTypeResolver implements TypeResolver { return new StringTypeDescription("String",""); } + /** + * Is string boolean. + * + * @param type the type + * @return the boolean + */ private static boolean isString(ResolvedType type){ if(!type.isReferenceType()){ return false; @@ -23,6 +34,12 @@ public class StringTypeResolver implements TypeResolver { return isString(type.asReferenceType().getId()); } + /** + * Is string boolean. + * + * @param id the id + * @return the boolean + */ private static boolean isString(String id){ return ImmutableList.of("java.lang.String", "java.lang.CharSequence" diff --git a/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/resolver/SystemObjectTypeResolver.java b/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/resolver/SystemObjectTypeResolver.java index fa9997f..f86634d 100644 --- a/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/resolver/SystemObjectTypeResolver.java +++ b/apidoc-core/src/main/java/com/github/fengyuchenglun/apidoc/core/resolver/SystemObjectTypeResolver.java @@ -4,6 +4,11 @@ import com.github.fengyuchenglun.apidoc.core.common.description.TypeDescription; import com.github.fengyuchenglun.apidoc.core.common.description.UnAvailableTypeDescription; import com.github.javaparser.resolution.types.ResolvedType; +/** + * The type System object type resolver. + * + * @author duanledexianxianxian + */ public class SystemObjectTypeResolver implements TypeResolver { @Override public boolean accept(ResolvedType type) { @@ -15,6 +20,12 @@ public class SystemObjectTypeResolver implements TypeResolver { return new UnAvailableTypeDescription(); } + /** + * Is system boolean. + * + * @param type the type + * @return the boolean + */ private static boolean isSystem(ResolvedType type){ if(!type.isReferenceType()){ return false; @@ -22,6 +33,12 @@ public class SystemObjectTypeResolver implements TypeResolver { return isSystem(type.asReferenceType().getId()); } + /** + * Is system boolean. + * + * @param id the id + * @return the boolean + */ private static boolean isSystem(String id){ return id!=null && (id.startsWith("java") ||id.startsWith("sun")); } 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 7be1f22..40797c7 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 @@ -1,10 +1,14 @@ package com.github.fengyuchenglun.apidoc.core.schema; +import com.github.fengyuchenglun.apidoc.core.ApiDoc; import com.github.fengyuchenglun.apidoc.core.common.convert.FieldTypeConvert; import com.github.fengyuchenglun.apidoc.core.common.convert.IFieldTypeConvert; +import com.github.fengyuchenglun.apidoc.core.common.enums.FieldShowWay; import lombok.*; import org.apache.commons.lang3.StringUtils; +import static com.github.fengyuchenglun.apidoc.core.common.Constants.FIELD_SPACE; + /** * The type Row. * @@ -41,12 +45,21 @@ public class Row { * 说明. */ String remark; + /** + * mock值 + */ + String mock; /** * 请求参数类型 */ String parameterType; + /** + * 是否为统一结果 + */ + Boolean isData; + /** * Instantiates a new Row. @@ -75,17 +88,41 @@ public class Row { * @return the label type */ public String getLabelType() { - String javaType=this.type; - Boolean isArray=false; - if (StringUtils.endsWith(javaType,"[]")){ - javaType=StringUtils.substringBefore(this.type,"[]"); - isArray=true; + String javaType = this.type; + Boolean isArray = false; + if (StringUtils.endsWith(javaType, "[]")) { + javaType = StringUtils.substringBefore(this.type, "[]"); + isArray = true; + } + IFieldTypeConvert fieldTypeConvert = FieldTypeConvert.javaTypeOf(javaType); + if (null == fieldTypeConvert) { + return this.type; } - IFieldTypeConvert fieldTypeConvert=FieldTypeConvert.javaTypeOf(javaType); - if (null==fieldTypeConvert){ - return this.type; + return isArray ? fieldTypeConvert.getType() + "[]" : fieldTypeConvert.getType(); + } + + /** + * Gets markdown key. + * + * @return the markdown key + */ + public String getMarkdownKey() { + if (StringUtils.isNotBlank(this.key)) { + if (FieldShowWay.TREE.equals(ApiDoc.getInstance().getContext().getFileShowWay())) { + String[] keys = StringUtils.split(this.key, "."); + if (keys.length > 1) { + StringBuilder sb = new StringBuilder(); + for (int i = 0; i < keys.length - 2; i++) { + sb.append(FIELD_SPACE); + } + sb.append("└─"); + sb.append(keys[keys.length - 1]); + return sb.toString(); + + } + } } - return isArray?fieldTypeConvert.getType()+"[]":fieldTypeConvert.getType(); + return this.key; } } 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 459e570..c2c44d9 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 @@ -13,6 +13,8 @@ import org.apache.commons.lang3.StringUtils; import java.util.*; +import static com.github.fengyuchenglun.apidoc.core.common.Constants.TAG_JAVA_DOC_RETURN; + /** * 小节,一个请求,封装为一个小节 * @@ -77,6 +79,10 @@ public class Section extends Node { * The Raw response. */ Object rawResponse; + /** + * 是否为统一结果返回 + */ + Boolean isResultData=false; /** * Sets parameter. @@ -180,7 +186,14 @@ public class Section extends Node { * @return the query parameter string */ public String getQueryParameterString() { - return new QueryStringBuilder().append((ObjectNode) queryParameters).toString(); + String qs = new QueryStringBuilder().append((ObjectNode) queryParameters).toString(); + + qs = StringUtils.replace(qs, "[\"\"]", "1,2,3"); + qs = StringUtils.replace(qs, "[0]", "1,2,3"); + qs = StringUtils.replace(qs, "[0.0]", "1.0,2.0,3.0"); + qs = StringUtils.replace(qs, "[false]", "false,true,false"); + + return qs; } /** @@ -222,11 +235,15 @@ public class Section extends Node { public void addResponseRows(Collection rows) { for (Row row : rows) { if (row.getKey() != null && !responseRows.containsKey(row.getKey())) { + if (row.getIsData()) { + Optional.ofNullable(this.tags.get(TAG_JAVA_DOC_RETURN)).ifPresent(x -> row.setRemark(x.content)); + } responseRows.put(row.getKey(), row); } } } + /** * Has response body boolean. * diff --git a/apidoc-core/src/main/resources/templates/markdown.ftl b/apidoc-core/src/main/resources/templates/markdown.ftl index 3122fba..8b5eba9 100644 --- a/apidoc-core/src/main/resources/templates/markdown.ftl +++ b/apidoc-core/src/main/resources/templates/markdown.ftl @@ -40,18 +40,23 @@ ${section.description} <#-- 请求示例--> ```HTTP -${section.method} ${section.uri!''} HTTP/1.1 - <#if section.inHeaders??> - <#list section.inHeaders as inHeaderKey,inHeaderValue> +HTTP/1.1 +<#if section.inHeaders??> + <#list section.inHeaders as inHeaderKey,inHeaderValue> ${inHeaderValue!''} - - -<#if (section.getQueryParameterString()?length gt 1)> + + + +Url: +${section.method} ${section.uri!''} -${section.getQueryParameterString()} +<#if (section.getQueryParameterString()?length gt 1)> +Query param: +?${section.getQueryParameterString()} <#if section.hasRequestBody()> +Request body: ${section.getRequestBodyParameterString()} ``` @@ -61,7 +66,7 @@ ${section.getRequestBodyParameterString()} | 字段 | 类型 | 参数类型 | 必填 | 验证 | 默认值 | 描述 | | :------- | :----- | :----- |:-------- |:-------- | :------ | :---------- | <#list section.requestRows as rowKey,rowValue> -| ${rowValue.key!''} | ${rowValue.getLabelType()!''} | **${rowValue.parameterType!''}** |${rowValue.required?string('true','false')} | ${rowValue.condition!''} | ${rowValue.def!''} | ${rowValue.getHtmlRemark()!''} | +| ${rowValue.getMarkdownKey()!''} | ${rowValue.getLabelType()!''} | **${rowValue.parameterType!''}** |${rowValue.required?string('true','false')} | ${rowValue.condition!''} | ${rowValue.def!''} | ${rowValue.getHtmlRemark()!''} | <#-- 响应--> @@ -74,10 +79,10 @@ ${section.getResponseString()} <#-- 响应参数table列表--> <#if section.responseRows?? && (section.responseRows?size>0)> -| 字段 | 类型 | 默认值 | 描述 | -| :------- | :----- |:----- | :---------- | +| 字段 | 类型 | 默认值 | 示例 | 描述 | +| :------- | :----- |:----- |:----- | :---------- | <#list section.responseRows as rowKey,rowValue> -| ${rowValue.key!''} | ${rowValue.getLabelType()!''} | ${rowValue.def!''} | ${rowValue.getHtmlRemark()!''} | +| ${rowValue.getMarkdownKey()!''} | ${rowValue.getLabelType()!''} | ${rowValue.def!''} | ${rowValue.mock!''} | ${rowValue.getHtmlRemark()!''} | diff --git a/apidoc-springmvc/src/main/java/com/github/fengyuchenglun/apidoc/springmvc/ParameterHelper.java b/apidoc-springmvc/src/main/java/com/github/fengyuchenglun/apidoc/springmvc/ParameterHelper.java index 8ec898b..485908f 100644 --- a/apidoc-springmvc/src/main/java/com/github/fengyuchenglun/apidoc/springmvc/ParameterHelper.java +++ b/apidoc-springmvc/src/main/java/com/github/fengyuchenglun/apidoc/springmvc/ParameterHelper.java @@ -5,6 +5,7 @@ import com.github.javaparser.ast.body.Parameter; /** * The type Parameter helper. + * @author duanledexianxianxian */ public class ParameterHelper { @@ -60,7 +61,7 @@ public class ParameterHelper { * 是否是请求参数 * * @param parameter the parameter - * @return boolean + * @return boolean boolean */ public static boolean isRequestParam(Parameter parameter) { if (!parameter.isAnnotationPresent(ANNOTATION_PATH_VARIABLE) && 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 8c04e1c..c330a16 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 @@ -1,5 +1,6 @@ package com.github.fengyuchenglun.apidoc.springmvc; +import com.github.fengyuchenglun.apidoc.core.common.description.ArrayTypeDescription; import com.github.fengyuchenglun.apidoc.core.common.helper.AnnotationHelper; import com.github.fengyuchenglun.apidoc.core.common.helper.ClassDeclarationHelper; import com.github.fengyuchenglun.apidoc.core.common.helper.ExpressionHelper; @@ -24,6 +25,7 @@ import com.github.fengyuchenglun.apidoc.springmvc.resovler.SpringComponentTypeRe import java.util.List; import java.util.Optional; +import static com.github.fengyuchenglun.apidoc.core.common.Constants.TAG_JAVA_DOC_RETURN; import static com.github.fengyuchenglun.apidoc.core.schema.ParameterType.*; @@ -95,6 +97,7 @@ public class SpringParser implements ParserStrategy { /** * 解析方法定义 + * * @param n 方法声明 * @param chapter 章 * @param section 节 @@ -326,20 +329,36 @@ public class SpringParser implements ParserStrategy { returnType.setTypeArguments(n.getType()); n.findCompilationUnit().get().addImport(ClassDeclarationHelper.getClassOrInterfacePackageName(resultDataClassOrInterfaceDeclaration)); n.setType(returnType); + section.setIsResultData(true); } TypeDescription description = ApiDoc.getInstance().getTypeResolvers().resolve(n.getType()); if (description.isAvailable()) { if (description.isPrimitive()) { section.setRawResponse(description.getValue()); + handleResultData(section,description); } else if (description.isString()) { section.setRawResponse(description.getValue()); + handleResultData(section,description); } else if (description.isArray()) { + ArrayTypeDescription asArray = description.asArray(); + if (asArray.getComponent().isPrimitive() || asArray.getComponent().isString()) { + handleResultData(section,description); + } section.setResponse(description.asArray().getValue()); } else if (description.isObject()) { section.setResponse(description.asObject().getValue()); } + section.addResponseRows(description.rows()); } } + private void handleResultData(Section section, TypeDescription description) { + if (!section.getIsResultData()) { + description.setKey("result"); + section.getTag(TAG_JAVA_DOC_RETURN).ifPresent(x -> description.setRemark(x.getContent())); + + } + } + } diff --git a/apidoc-springmvc/src/test/java/com/github/fengyuchenglun/example/common/Query.java b/apidoc-springmvc/src/test/java/com/github/fengyuchenglun/example/common/Query.java index 23dda4d..a53f378 100644 --- a/apidoc-springmvc/src/test/java/com/github/fengyuchenglun/example/common/Query.java +++ b/apidoc-springmvc/src/test/java/com/github/fengyuchenglun/example/common/Query.java @@ -51,9 +51,11 @@ public class Query { // /** // * 结束时间 // * 2020-07-25 01:00:00 -// */ -// private LocalDateTime endTime; +// + // + + private LocalDateTime endTime; - private List menuList; + private List queryList; } diff --git a/apidoc-springmvc/src/test/java/com/github/fengyuchenglun/example/common/ResultData.java b/apidoc-springmvc/src/test/java/com/github/fengyuchenglun/example/common/ResultData.java index 6a38052..409abcd 100644 --- a/apidoc-springmvc/src/test/java/com/github/fengyuchenglun/example/common/ResultData.java +++ b/apidoc-springmvc/src/test/java/com/github/fengyuchenglun/example/common/ResultData.java @@ -26,6 +26,8 @@ public class ResultData { String msg; /** * 数据对象. + * + * @data */ T data; diff --git a/apidoc-springmvc/src/test/java/com/github/fengyuchenglun/example/common/User.java b/apidoc-springmvc/src/test/java/com/github/fengyuchenglun/example/common/User.java index fe798e9..5201a31 100644 --- a/apidoc-springmvc/src/test/java/com/github/fengyuchenglun/example/common/User.java +++ b/apidoc-springmvc/src/test/java/com/github/fengyuchenglun/example/common/User.java @@ -20,40 +20,32 @@ import java.util.List; @Getter public class User { -// /** -// * 用户编号. -// */ -// int id; -// /** -// * 用户名称. -// */ -// @NotBlank -// String name; -// /** -// * 用户年龄. -// */ -// @Min(1) -// @NotNull -// Integer age; -// /** -// * 创建时间. -// */ -// Date createAt; -// /** -// * 性别. -// */ -// @NotBlank -// @JsonProperty("Sex") -// String sex; - /** - * 用户. + * 用户编号. */ - private UserQuery query; - + int id; + /** + * 用户名称. + */ + @NotBlank + String name; + /** + * 用户年龄. + * @mock 20 + */ + @Min(1) + @NotNull + Integer age; + /** + * 创建时间. + * @mock 2020-07-28 + */ + Date createAt; /** - * 用户. + * 性别. */ - private List menus; + @NotBlank + @JsonProperty("Sex") + String sex; } 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 abf01c1..19ee86a 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 @@ -27,133 +27,170 @@ public class UserController { * 查看用户详情 * * @param userId 用户编号 - * @param age 年龄 - * @param query 过滤条件 - * @return 用户对象 user + * @return the user */ @PostMapping(value = "/{userId}") - public User detail(@PathVariable String userId, String age, @RequestBody Query query) { + public User detail(@PathVariable("userId")Long userId) { + User user = new User(); + return user; + } + + /** + * 查看用户详情 + * 测试get的query对象 + * + * @param query 过滤条件 + * @return 用户对象 user + */ + @GetMapping(value = "/detail1") + public User detail1(Query query) { + User user = new User(); + return user; + } + + + /** + * + * 测试返回List + * + * @param query 过滤条件 + * @return 用户对象 user + */ + @GetMapping(value = "/getList") + public List getList(Query query) { + return null; + } + + /** + * + * 测试返回List + * + * @param query 过滤条件 + * @return 用户对象 user + */ + @GetMapping(value = "/getStringList") + public List getStringList(Query query) { + return null; + } + + + /** + * + * 测试返回List + * + * @param query 过滤条件 + * @return 用户对象 user + */ + @GetMapping(value = "/getStringArrayList") + public List> getStringArrayList(Query query) { + return null; + } + + /** + * 测试get的query对象,带RequestParam注解 + * + * @param query the query + * @return 用户对象 user + */ + @GetMapping(value = "/detail3") + public User detail3(Query query) { User user = new User(); return user; } -// -// /** -// * 查看用户详情 -// * 测试get的query对象 -// * -// * @param query 过滤条件 -// * @return 用户对象 user -// */ -// @GetMapping(value = "/detail1") -// public User detail1(Query query) { -// User user = new User(); -// return user; -// } -// -// -// -// /** -// * 测试get的query对象,带RequestParam注解 -// * -// * @param query the query -// * @return 用户对象 user -// */ -// @GetMapping(value = "/detail3") -// public User detail3(Query query) { -// User user = new User(); -// return user; -// } -// -// /** -// * 测试get的query对象,带RequestParam注解,required=false -// * -// * @param query 过滤条件 -// * @return 用户对象 user -// */ -// @GetMapping(value = "/detail4") -// public User detail4(@RequestParam(required = false) String query) { -// User user = new User(); -// return user; -// } -// -// /** -// * get-无查询参数 -// * -// * @return 用户对象 user -// */ -// @GetMapping(value = "/detail5") -// public List detail5() { -// return null; -// } -// -// /** -// * get-原始对象+查询对象 -// * -// * @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; -// } -// -// /** -// * post- -// * -// * @return 用户对象 user -// */ -// @GetMapping(value = "/post1") -// public UserQuery post1() { -// return null; -// } -// -// -// /** -// * 删除用户 -// * -// * @param userId the user id -// * @return boolean 是否成功 -// */ -// @DeleteMapping(value = "/{userId}") -// public Boolean deleteUser(@PathVariable("userId") Long userId) { -// return true; -// } -// -// -// /** -// * 用户表单对象. -// * -// * @author duanledexianxianxian -// */ -// @Data -// public static class UserForm implements Serializable { -// -// private static final long serialVersionUID = 5681371348688016281L; -// /** -// * 用户名 -// */ -// private String userName; -// /** -// * 地址 -// */ -// private String address; -// /** -// * 年龄 -// */ -// private Integer age; -// } -// -// /** -// * 添加用户 -// * -// * @param form 用户表单对象 -// * @return integer 返回记录 -// */ -// @PostMapping -// public Integer add(@RequestBody UserForm form) { -// return null; -// } + + /** + * 测试get的query对象,带RequestParam注解,required=false + * + * @param query 过滤条件 + * @return 用户对象 user + */ + @GetMapping(value = "/detail4") + public User detail4(@RequestParam(required = false) String query) { + User user = new User(); + return user; + } + + /** + * get-无查询参数 + * + * @return 用户对象 user + */ + @GetMapping(value = "/detail5") + public List detail5() { + return null; + } + + /** + * get-原始对象+查询对象 + * + * @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; + } + + /** + * post- + * + * @return 用户对象 user + */ + @GetMapping(value = "/post1") + public UserQuery post1() { + return null; + } + + + /** + * 删除用户 + * + * @param userId the user id + * @return boolean 是否成功 + */ + @DeleteMapping(value = "/{userId}") + public Boolean deleteUser(@PathVariable("userId") Long userId) { + return true; + } + + + /** + * 用户表单对象. + * + * @author duanledexianxianxian + */ + @Data + public static class UserForm implements Serializable { + + /** + * The constant serialVersionUID. + */ + private static final long serialVersionUID = 5681371348688016281L; + /** + * 用户名 + */ + private String userName; + /** + * 地址 + */ + private String address; + /** + * 年龄 + */ + private Integer age; + } + + /** + * 添加用户 + * + * @param form 用户表单对象 + * @return 返回记录 boolean + */ + @PostMapping + public Boolean add(@RequestBody UserForm form) { + return null; + } } -- GitLab