From ee858e055395a406c8e6e87aa197396a475cf1e4 Mon Sep 17 00:00:00 2001 From: duanledexianxianxian Date: Mon, 13 Apr 2020 22:39:14 +0800 Subject: [PATCH] Revert "Merge branch 'dev' into 'master'" This reverts merge request !1 --- apidoc-core/build.gradle | 1 - .../com/kim/apidoc/core/common/Constants.java | 19 -- .../common/description/TypeDescription.java | 214 ------------------ .../apidoc/core/common/helper/EnumHelper.java | 55 ----- .../core/common/helper/FieldHelper.java | 82 ------- .../kim/apidoc/core/parser/VisitorParser.java | 134 ----------- .../apidoc/core/render/MarkdownRender.java | 65 ------ .../com/kim/apidoc/core/schema/Appendix.java | 74 ------ .../java/com/kim/apidoc/core/schema/Cell.java | 130 ----------- .../core/schema/RequestParameterType.java | 23 -- .../{com => }/kim/apidoc/core/ApiDoc.java | 22 +- .../{com => }/kim/apidoc/core/Context.java | 36 ++- .../kim/apidoc/core/common/Assert.java | 2 +- .../kim/apidoc/core/common/ObjectMappers.java | 2 +- .../core/common/QueryStringBuilder.java | 2 +- .../{com => }/kim/apidoc/core/common/URI.java | 4 +- .../description/ArrayTypeDescription.java | 9 +- .../description/ObjectTypeDescription.java | 44 +--- .../description/PrimitiveTypeDescription.java | 16 +- .../description/StringTypeDescription.java | 11 +- .../common/description/TypeDescription.java | 100 ++++++++ .../UnAvailableTypeDescription.java | 4 +- .../apidoc/core/common/diff/FileMatcher.java | 2 +- .../apidoc/core/common/diff/FileSystem.java | 2 +- .../apidoc/core/common/diff/MatchPatcher.java | 2 +- .../core/common/helper/AnnotationHelper.java | 8 +- .../common/helper/ClassDeclarationHelper.java | 21 +- .../core/common/helper/CommentHelper.java | 50 ++-- .../common/helper/CompilationUnitHelper.java | 8 +- .../core/common/helper/ExpressionHelper.java | 2 +- .../core/common/helper/FieldHelper.java | 38 ++++ .../apidoc/core/common/helper/FileHelper.java | 6 +- .../common/helper/JsonPropertyHelper.java | 2 +- .../core/common/helper/OptionalHelper.java | 6 +- .../core/common/helper/ReferenceContext.java | 2 +- .../core/common/helper/StringHelper.java | 12 +- .../core/common/helper/TypeNameHelper.java | 2 +- .../common/helper/TypeParameterHelper.java | 2 +- .../core/common/helper/ValidationHelper.java | 2 +- .../core/common/markup/MarkupBuilder.java | 4 +- .../core/common/markup/asciidoc/AsciiDoc.java | 2 +- .../markup/asciidoc/AsciiDocBuilder.java | 6 +- .../core/common/markup/asciidoc/Color.java | 2 +- .../core/common/markup/markdown/Markdown.java | 2 +- .../markup/markdown/MarkdownBuilder.java | 6 +- .../kim/apidoc/core/common/postman/Body.java | 2 +- .../apidoc/core/common/postman/BodyMode.java | 2 +- .../apidoc/core/common/postman/Folder.java | 2 +- .../kim/apidoc/core/common/postman/Info.java | 2 +- .../kim/apidoc/core/common/postman/Item.java | 2 +- .../apidoc/core/common/postman/Parameter.java | 4 +- .../apidoc/core/common/postman/Postman.java | 2 +- .../apidoc/core/common/postman/Request.java | 6 +- .../apidoc/core/common/postman/Response.java | 4 +- .../kim/apidoc/core/common/postman/Url.java | 2 +- .../apidoc/core/parser/ParserStrategy.java | 6 +- .../kim/apidoc/core/parser/VisitorParser.java | 77 +++++++ .../apidoc/core/render/AsciiDocRender.java | 22 +- .../apidoc/core/render/MarkdownRender.java | 18 ++ .../kim/apidoc/core/render/PostmanRender.java | 30 +-- .../kim/apidoc/core/render/ProjectRender.java | 4 +- .../core/resolver/ArrayTypeResolver.java | 8 +- .../core/resolver/CollectionTypeResolver.java | 12 +- .../core/resolver/DateTypeResolver.java | 6 +- .../core/resolver/EnumTypeResolver.java | 6 +- .../apidoc/core/resolver/MapTypeResolver.java | 6 +- .../core/resolver/ObjectTypeResolver.java | 28 ++- .../core/resolver/PrimitiveTypeResolver.java | 38 ++-- .../core/resolver/StringTypeResolver.java | 6 +- .../resolver/SystemObjectTypeResolver.java | 6 +- .../core/resolver/TypeNameResolver.java | 4 +- .../apidoc/core/resolver/TypeResolver.java | 4 +- .../apidoc/core/resolver/TypeResolvers.java | 34 ++- .../kim/apidoc/core/schema/Book.java | 2 +- .../kim/apidoc/core/schema/Chapter.java | 5 +- .../kim/apidoc/core/schema/Header.java | 2 +- .../kim/apidoc/core/schema/Method.java | 2 +- .../kim/apidoc/core/schema/Node.java | 20 +- .../kim/apidoc/core/schema/Project.java | 14 +- .../{com => }/kim/apidoc/core/schema/Row.java | 16 +- .../kim/apidoc/core/schema/Section.java | 18 +- .../{com => }/kim/apidoc/core/schema/Tag.java | 2 +- .../src/main/resources/templates/markdown.ftl | 89 -------- .../springmvc/RequestMappingHelper.java | 10 +- .../apidoc/springmvc/SpringMVCContext.java | 2 +- .../kim/apidoc/springmvc/SpringParser.java | 45 ++-- .../resovler/SpringComponentTypeResolver.java | 12 +- ... => kim.apidoc.core.parser.ParserStrategy} | 0 .../com/kim/apidoc/example/ApigccTest.java | 4 +- .../kim/apidoc/example/common/ResultData.java | 30 +-- .../com/kim/apidoc/example/common/Role.java | 22 +- .../com/kim/apidoc/example/common/User.java | 22 +- .../apidoc/example/spring/BaseController.java | 11 + .../spring/advanced/AuthController.java | 25 ++ .../spring/advanced/EmptyController.java | 15 ++ .../spring/advanced/IgnoreController.java | 20 ++ .../spring/advanced/KimUserController.java | 21 +- .../spring/advanced/PageController.java | 140 ++++++++++++ .../spring/advanced/UserController.java | 139 ++++++++++++ .../apidoc/example/spring/hello/Greeting.java | 26 +++ .../spring/hello/GreetingController.java | 44 ++++ .../com/kim/apidoc/springmvc/SpringTest.java | 6 +- build.gradle | 2 +- ...45\345\217\243\346\250\241\347\211\210.md" | 86 ++----- 104 files changed, 968 insertions(+), 1465 deletions(-) delete mode 100644 apidoc-core/src/main/java/com/kim/apidoc/core/common/Constants.java delete mode 100644 apidoc-core/src/main/java/com/kim/apidoc/core/common/description/TypeDescription.java delete mode 100644 apidoc-core/src/main/java/com/kim/apidoc/core/common/helper/EnumHelper.java delete mode 100644 apidoc-core/src/main/java/com/kim/apidoc/core/common/helper/FieldHelper.java delete mode 100644 apidoc-core/src/main/java/com/kim/apidoc/core/parser/VisitorParser.java delete mode 100644 apidoc-core/src/main/java/com/kim/apidoc/core/render/MarkdownRender.java delete mode 100644 apidoc-core/src/main/java/com/kim/apidoc/core/schema/Appendix.java delete mode 100644 apidoc-core/src/main/java/com/kim/apidoc/core/schema/Cell.java delete mode 100644 apidoc-core/src/main/java/com/kim/apidoc/core/schema/RequestParameterType.java rename apidoc-core/src/main/java/{com => }/kim/apidoc/core/ApiDoc.java (90%) rename apidoc-core/src/main/java/{com => }/kim/apidoc/core/Context.java (74%) rename apidoc-core/src/main/java/{com => }/kim/apidoc/core/common/Assert.java (94%) rename apidoc-core/src/main/java/{com => }/kim/apidoc/core/common/ObjectMappers.java (96%) rename apidoc-core/src/main/java/{com => }/kim/apidoc/core/common/QueryStringBuilder.java (96%) rename apidoc-core/src/main/java/{com => }/kim/apidoc/core/common/URI.java (93%) rename apidoc-core/src/main/java/{com => }/kim/apidoc/core/common/description/ArrayTypeDescription.java (94%) rename apidoc-core/src/main/java/{com => }/kim/apidoc/core/common/description/ObjectTypeDescription.java (79%) rename apidoc-core/src/main/java/{com => }/kim/apidoc/core/common/description/PrimitiveTypeDescription.java (86%) rename apidoc-core/src/main/java/{com => }/kim/apidoc/core/common/description/StringTypeDescription.java (56%) create mode 100644 apidoc-core/src/main/java/kim/apidoc/core/common/description/TypeDescription.java rename apidoc-core/src/main/java/{com => }/kim/apidoc/core/common/description/UnAvailableTypeDescription.java (83%) rename apidoc-core/src/main/java/{com => }/kim/apidoc/core/common/diff/FileMatcher.java (98%) rename apidoc-core/src/main/java/{com => }/kim/apidoc/core/common/diff/FileSystem.java (97%) rename apidoc-core/src/main/java/{com => }/kim/apidoc/core/common/diff/MatchPatcher.java (99%) rename apidoc-core/src/main/java/{com => }/kim/apidoc/core/common/helper/AnnotationHelper.java (91%) rename apidoc-core/src/main/java/{com => }/kim/apidoc/core/common/helper/ClassDeclarationHelper.java (69%) rename apidoc-core/src/main/java/{com => }/kim/apidoc/core/common/helper/CommentHelper.java (72%) rename apidoc-core/src/main/java/{com => }/kim/apidoc/core/common/helper/CompilationUnitHelper.java (73%) rename apidoc-core/src/main/java/{com => }/kim/apidoc/core/common/helper/ExpressionHelper.java (98%) create mode 100644 apidoc-core/src/main/java/kim/apidoc/core/common/helper/FieldHelper.java rename apidoc-core/src/main/java/{com => }/kim/apidoc/core/common/helper/FileHelper.java (85%) rename apidoc-core/src/main/java/{com => }/kim/apidoc/core/common/helper/JsonPropertyHelper.java (97%) rename apidoc-core/src/main/java/{com => }/kim/apidoc/core/common/helper/OptionalHelper.java (60%) rename apidoc-core/src/main/java/{com => }/kim/apidoc/core/common/helper/ReferenceContext.java (94%) rename apidoc-core/src/main/java/{com => }/kim/apidoc/core/common/helper/StringHelper.java (77%) rename apidoc-core/src/main/java/{com => }/kim/apidoc/core/common/helper/TypeNameHelper.java (97%) rename apidoc-core/src/main/java/{com => }/kim/apidoc/core/common/helper/TypeParameterHelper.java (98%) rename apidoc-core/src/main/java/{com => }/kim/apidoc/core/common/helper/ValidationHelper.java (97%) rename apidoc-core/src/main/java/{com => }/kim/apidoc/core/common/markup/MarkupBuilder.java (97%) rename apidoc-core/src/main/java/{com => }/kim/apidoc/core/common/markup/asciidoc/AsciiDoc.java (97%) rename apidoc-core/src/main/java/{com => }/kim/apidoc/core/common/markup/asciidoc/AsciiDocBuilder.java (98%) rename apidoc-core/src/main/java/{com => }/kim/apidoc/core/common/markup/asciidoc/Color.java (94%) rename apidoc-core/src/main/java/{com => }/kim/apidoc/core/common/markup/markdown/Markdown.java (96%) rename apidoc-core/src/main/java/{com => }/kim/apidoc/core/common/markup/markdown/MarkdownBuilder.java (98%) rename apidoc-core/src/main/java/{com => }/kim/apidoc/core/common/postman/Body.java (86%) rename apidoc-core/src/main/java/{com => }/kim/apidoc/core/common/postman/BodyMode.java (69%) rename apidoc-core/src/main/java/{com => }/kim/apidoc/core/common/postman/Folder.java (87%) rename apidoc-core/src/main/java/{com => }/kim/apidoc/core/common/postman/Info.java (85%) rename apidoc-core/src/main/java/{com => }/kim/apidoc/core/common/postman/Item.java (89%) rename apidoc-core/src/main/java/{com => }/kim/apidoc/core/common/postman/Parameter.java (85%) rename apidoc-core/src/main/java/{com => }/kim/apidoc/core/common/postman/Postman.java (88%) rename apidoc-core/src/main/java/{com => }/kim/apidoc/core/common/postman/Request.java (68%) rename apidoc-core/src/main/java/{com => }/kim/apidoc/core/common/postman/Response.java (79%) rename apidoc-core/src/main/java/{com => }/kim/apidoc/core/common/postman/Url.java (86%) rename apidoc-core/src/main/java/{com => }/kim/apidoc/core/parser/ParserStrategy.java (89%) create mode 100644 apidoc-core/src/main/java/kim/apidoc/core/parser/VisitorParser.java rename apidoc-core/src/main/java/{com => }/kim/apidoc/core/render/AsciiDocRender.java (90%) create mode 100644 apidoc-core/src/main/java/kim/apidoc/core/render/MarkdownRender.java rename apidoc-core/src/main/java/{com => }/kim/apidoc/core/render/PostmanRender.java (83%) rename apidoc-core/src/main/java/{com => }/kim/apidoc/core/render/ProjectRender.java (72%) rename apidoc-core/src/main/java/{com => }/kim/apidoc/core/resolver/ArrayTypeResolver.java (67%) rename apidoc-core/src/main/java/{com => }/kim/apidoc/core/resolver/CollectionTypeResolver.java (78%) rename apidoc-core/src/main/java/{com => }/kim/apidoc/core/resolver/DateTypeResolver.java (83%) rename apidoc-core/src/main/java/{com => }/kim/apidoc/core/resolver/EnumTypeResolver.java (84%) rename apidoc-core/src/main/java/{com => }/kim/apidoc/core/resolver/MapTypeResolver.java (84%) rename apidoc-core/src/main/java/{com => }/kim/apidoc/core/resolver/ObjectTypeResolver.java (73%) rename apidoc-core/src/main/java/{com => }/kim/apidoc/core/resolver/PrimitiveTypeResolver.java (75%) rename apidoc-core/src/main/java/{com => }/kim/apidoc/core/resolver/StringTypeResolver.java (81%) rename apidoc-core/src/main/java/{com => }/kim/apidoc/core/resolver/SystemObjectTypeResolver.java (79%) rename apidoc-core/src/main/java/{com => }/kim/apidoc/core/resolver/TypeNameResolver.java (61%) rename apidoc-core/src/main/java/{com => }/kim/apidoc/core/resolver/TypeResolver.java (64%) rename apidoc-core/src/main/java/{com => }/kim/apidoc/core/resolver/TypeResolvers.java (70%) rename apidoc-core/src/main/java/{com => }/kim/apidoc/core/schema/Book.java (93%) rename apidoc-core/src/main/java/{com => }/kim/apidoc/core/schema/Chapter.java (87%) rename apidoc-core/src/main/java/{com => }/kim/apidoc/core/schema/Header.java (97%) rename apidoc-core/src/main/java/{com => }/kim/apidoc/core/schema/Method.java (96%) rename apidoc-core/src/main/java/{com => }/kim/apidoc/core/schema/Node.java (87%) rename apidoc-core/src/main/java/{com => }/kim/apidoc/core/schema/Project.java (70%) rename apidoc-core/src/main/java/{com => }/kim/apidoc/core/schema/Row.java (73%) rename apidoc-core/src/main/java/{com => }/kim/apidoc/core/schema/Section.java (93%) rename apidoc-core/src/main/java/{com => }/kim/apidoc/core/schema/Tag.java (95%) delete mode 100644 apidoc-core/src/main/resources/templates/markdown.ftl rename apidoc-springmvc/src/main/resources/META-INF/services/{com.kim.apidoc.core.parser.ParserStrategy => kim.apidoc.core.parser.ParserStrategy} (100%) create mode 100644 apidoc-springmvc/src/test/java/com/kim/apidoc/example/spring/BaseController.java create mode 100644 apidoc-springmvc/src/test/java/com/kim/apidoc/example/spring/advanced/AuthController.java create mode 100644 apidoc-springmvc/src/test/java/com/kim/apidoc/example/spring/advanced/EmptyController.java create mode 100644 apidoc-springmvc/src/test/java/com/kim/apidoc/example/spring/advanced/IgnoreController.java create mode 100644 apidoc-springmvc/src/test/java/com/kim/apidoc/example/spring/advanced/PageController.java create mode 100644 apidoc-springmvc/src/test/java/com/kim/apidoc/example/spring/advanced/UserController.java create mode 100644 apidoc-springmvc/src/test/java/com/kim/apidoc/example/spring/hello/Greeting.java create mode 100644 apidoc-springmvc/src/test/java/com/kim/apidoc/example/spring/hello/GreetingController.java diff --git a/apidoc-core/build.gradle b/apidoc-core/build.gradle index dffa1ee..2a1eec7 100644 --- a/apidoc-core/build.gradle +++ b/apidoc-core/build.gradle @@ -2,5 +2,4 @@ dependencies { compile 'com.github.javaparser:javaparser-symbol-solver-core:3.14.4' compile 'com.fasterxml.jackson.core:jackson-databind:2.5.2' compile 'org.asciidoctor:asciidoctorj:2.1.0' - compile group: 'org.freemarker', name: 'freemarker', version: '2.3.30' } diff --git a/apidoc-core/src/main/java/com/kim/apidoc/core/common/Constants.java b/apidoc-core/src/main/java/com/kim/apidoc/core/common/Constants.java deleted file mode 100644 index a28605a..0000000 --- a/apidoc-core/src/main/java/com/kim/apidoc/core/common/Constants.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.kim.apidoc.core.common; - -import java.nio.charset.StandardCharsets; - -/** - * 常量类 - * - * @author duanledexianxianxian - * @version 1.0.0 - * @date 2020 /3/26 23:00 - * @since 1.0.0 - */ -public class Constants { - public static final String UTF8 = StandardCharsets.UTF_8.name(); - public static final String SLASH = "/"; - public static final String MARKDOWN_EXTENSION = ".md"; - public static final String MARKDOWN_TEMPLATE = "/templates/markdown.ftl"; - -} diff --git a/apidoc-core/src/main/java/com/kim/apidoc/core/common/description/TypeDescription.java b/apidoc-core/src/main/java/com/kim/apidoc/core/common/description/TypeDescription.java deleted file mode 100644 index 0727e22..0000000 --- a/apidoc-core/src/main/java/com/kim/apidoc/core/common/description/TypeDescription.java +++ /dev/null @@ -1,214 +0,0 @@ -package com.kim.apidoc.core.common.description; - -import com.github.javaparser.ast.comments.Comment; -import com.github.javaparser.javadoc.Javadoc; -import com.google.common.collect.Lists; -import com.kim.apidoc.core.common.helper.CommentHelper; -import com.kim.apidoc.core.common.helper.StringHelper; -import com.kim.apidoc.core.schema.Row; -import lombok.Getter; -import lombok.Setter; - -import java.util.Collection; - -/** - * The type Type description. - */ -@Setter -@Getter -public abstract class TypeDescription { - - /** - * The Prefix. - */ - protected String prefix = ""; - /** - * The Key. - */ - protected String key = ""; - /** - * The Type. - */ - protected String type; - /** - * The Condition. - */ - protected StringBuilder condition = new StringBuilder(); - /** - * 说明. - */ - protected String remark; - /** - * 值. - */ - protected Object value; - /** - * 默认值. - */ - protected Object defaultValue; - /** - * 是否必填. - */ - protected Boolean required; - - /** - * Is available boolean. - * - * @return the boolean - */ - public boolean isAvailable() { - return !isUnAvailable(); - } - - /** - * Is un available boolean. - * - * @return the boolean - */ - public boolean isUnAvailable() { - return this instanceof UnAvailableTypeDescription; - } - - /** - * Is primitive boolean. - * - * @return the boolean - */ - public boolean isPrimitive() { - return this instanceof PrimitiveTypeDescription; - } - - /** - * As primitive primitive type description. - * - * @return the primitive type description - */ - public PrimitiveTypeDescription asPrimitive() { - return (PrimitiveTypeDescription) this; - } - - /** - * Is string boolean. - * - * @return the boolean - */ - public boolean isString() { - return this instanceof StringTypeDescription; - } - - /** - * As string string type description. - * - * @return the string type description - */ - public StringTypeDescription asString() { - return (StringTypeDescription) this; - } - - /** - * Is array boolean. - * - * @return the boolean - */ - public boolean isArray() { - return this instanceof ArrayTypeDescription; - } - - /** - * As array array type description. - * - * @return the array type description - */ - public ArrayTypeDescription asArray() { - return (ArrayTypeDescription) this; - } - - /** - * Is object boolean. - * - * @return the boolean - */ - public boolean isObject() { - return this instanceof ObjectTypeDescription; - } - - /** - * As object object type description. - * - * @return the object type description - */ - public ObjectTypeDescription asObject() { - return (ObjectTypeDescription) this; - } - - /** - * Add remark. - * - * @param value the value - */ - public void addRemark(String value) { - if (value == null) { - return; - } - if (remark == null) { - remark = value; - } else { - remark += " " + value; - } - } - - /** - * Full key string. - * - * @return the string - */ - public String fullKey() { - return StringHelper.join(".", prefix, key); - } - - /** - * Rows collection. - * - * @return the collection - */ - public Collection rows(String requestParameterType) { - String fullKey = fullKey(); - if (StringHelper.isBlank(fullKey)) { - return Lists.newArrayList(); - } - String def; - if (defaultValue != null) { - def = String.valueOf(defaultValue); - } else if (value != null) { - def = String.valueOf(value); - } else { - def = ""; - } - - if (required != null) { - condition.append("required=").append(required); - } - - return Lists.newArrayList(new Row(key, type, false, condition.toString(), def, remark, requestParameterType)); - } - - - /** - * Rows collection. - * - * @return the collection - */ - public Collection rows() { - return this.rows(null); - } - - public void accept(Comment comment) { - if (!comment.isJavadocComment()) { - setRemark(comment.getContent()); - return; - } - Javadoc javadoc = comment.asJavadocComment().parse(); - setRemark(CommentHelper.getDescription(javadoc.getDescription())); - } - -} diff --git a/apidoc-core/src/main/java/com/kim/apidoc/core/common/helper/EnumHelper.java b/apidoc-core/src/main/java/com/kim/apidoc/core/common/helper/EnumHelper.java deleted file mode 100644 index 558b268..0000000 --- a/apidoc-core/src/main/java/com/kim/apidoc/core/common/helper/EnumHelper.java +++ /dev/null @@ -1,55 +0,0 @@ -package com.kim.apidoc.core.common.helper; - -import com.github.javaparser.ast.body.EnumConstantDeclaration; -import com.github.javaparser.ast.body.EnumDeclaration; -import com.github.javaparser.ast.expr.Expression; -import com.github.javaparser.resolution.declarations.ResolvedEnumConstantDeclaration; -import com.github.javaparser.resolution.declarations.ResolvedEnumDeclaration; -import com.kim.apidoc.core.schema.Cell; - -import java.util.ArrayList; -import java.util.List; - -/** - * The type Enum helper. - */ -public class EnumHelper { - - /** - * Get names string. - * - * @param enumDeclaration the enum declaration - * @return the string - */ - public static String getNames(ResolvedEnumDeclaration enumDeclaration){ - StringBuilder sb = new StringBuilder(); - for (ResolvedEnumConstantDeclaration resolvedEnumConstantDeclaration : enumDeclaration.getEnumConstants()) { - if(sb.length()>0){ - sb.append(","); - } - sb.append(resolvedEnumConstantDeclaration.getName()); - } - return sb.toString(); - } - - /** - * To details list. - * - * @param declaration the declaration - * @return the list - */ - public static List> toDetails(EnumDeclaration declaration){ - List> cells = new ArrayList<>(); - for (EnumConstantDeclaration constant : declaration.getEntries()) { - Cell cell = new Cell<>(); - cell.add(constant.getNameAsString()); - for (Expression expression : constant.getArguments()) { - Object value = ExpressionHelper.getValue(expression); - cell.add(String.valueOf(value)); - } - cells.add(cell); - } - return cells; - } - -} diff --git a/apidoc-core/src/main/java/com/kim/apidoc/core/common/helper/FieldHelper.java b/apidoc-core/src/main/java/com/kim/apidoc/core/common/helper/FieldHelper.java deleted file mode 100644 index c098ede..0000000 --- a/apidoc-core/src/main/java/com/kim/apidoc/core/common/helper/FieldHelper.java +++ /dev/null @@ -1,82 +0,0 @@ -package com.kim.apidoc.core.common.helper; - -import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; -import com.github.javaparser.ast.body.FieldDeclaration; -import com.github.javaparser.ast.body.VariableDeclarator; -import com.github.javaparser.ast.comments.Comment; -import com.github.javaparser.ast.expr.Expression; -import com.github.javaparser.resolution.declarations.ResolvedFieldDeclaration; -import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserFieldDeclaration; -import com.kim.apidoc.core.schema.Cell; - -import java.util.ArrayList; -import java.util.List; -import java.util.Optional; - -/** - * The type Field helper. - */ -public class FieldHelper { - - /** - * 通过access方法,获取属性名 - * - * @param methodName access方法名 - * @return 属性名 string - */ - public static String getByAccessMethod(String methodName) { - if (methodName.startsWith("is") && methodName.length() > 2) { - String first = methodName.substring(2, 3); - String less = methodName.substring(3); - return first.toLowerCase() + less; - } - if (methodName.startsWith("get") && methodName.length() > 3) { - String first = methodName.substring(3, 4); - String less = methodName.substring(4); - return first.toLowerCase() + less; - } - return null; - } - - /** - * Get initializer optional. - * - * @param declaredField the declared field - * @return the optional - */ - public static Optional getInitializer(ResolvedFieldDeclaration declaredField) { - if (declaredField instanceof JavaParserFieldDeclaration) { - JavaParserFieldDeclaration field = (JavaParserFieldDeclaration) declaredField; - return field.getVariableDeclarator().getInitializer(); - } - return Optional.empty(); - } - - - /** - * 获取常量 - * - * @param declaration the declaration - * @return constants - */ - public static List> getConstants(ClassOrInterfaceDeclaration declaration) { - List> cells = new ArrayList<>(); - for (FieldDeclaration field : declaration.getFields()) { - if (field.isStatic() && field.isPublic() && field.isFinal()) { - VariableDeclarator variable = field.getVariable(0); - String value = null; - String description = null; - if (variable.getInitializer().isPresent()) { - value = String.valueOf(ExpressionHelper.getValue(variable.getInitializer().get())); - } - if (field.getComment().isPresent()) { - description = CommentHelper.getContent(field.getComment().get()); - } - cells.add(new Cell<>(variable.getNameAsString(), value, description)); - } - } - - return cells; - } - -} diff --git a/apidoc-core/src/main/java/com/kim/apidoc/core/parser/VisitorParser.java b/apidoc-core/src/main/java/com/kim/apidoc/core/parser/VisitorParser.java deleted file mode 100644 index f3a00bb..0000000 --- a/apidoc-core/src/main/java/com/kim/apidoc/core/parser/VisitorParser.java +++ /dev/null @@ -1,134 +0,0 @@ -package com.kim.apidoc.core.parser; - -import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; -import com.github.javaparser.ast.body.EnumDeclaration; -import com.github.javaparser.ast.body.MethodDeclaration; -import com.github.javaparser.ast.comments.JavadocComment; -import com.github.javaparser.ast.visitor.VoidVisitorAdapter; -import com.kim.apidoc.core.ApiDoc; -import com.kim.apidoc.core.common.helper.OptionalHelper; -import com.kim.apidoc.core.schema.*; - - -/** - * The type Visitor parser. - */ -public class VisitorParser extends VoidVisitorAdapter { - - /** - * The Parser strategy. - */ - private ParserStrategy parserStrategy; - - /** - * Sets parser strategy. - * - * @param parserStrategy the parser strategy - */ - public void setParserStrategy(ParserStrategy parserStrategy) { - this.parserStrategy = parserStrategy; - } - - @Override - public void visit(final EnumDeclaration enumDeclaration, final Node arg) { - // 访问枚举 - if (arg instanceof Project) { - Project project = (Project) arg; - // 章节 - Chapter chapter = new Chapter(); - enumDeclaration.getFullyQualifiedName().ifPresent(chapter::setId); - chapter.setName(enumDeclaration.getNameAsString()); - enumDeclaration.getComment().ifPresent(chapter::accept); - OptionalHelper.any(chapter.getTag("book"), chapter.getTag("group")) - .ifPresent(tag -> chapter.setBookName(tag.getContent())); - project.addChapter(chapter); - super.visit(enumDeclaration, chapter); - } - } - - - /** - * 类或者接口声明 - * - * @param classOrInterfaceDeclaration - * @param arg - */ - @Override - public void visit(final ClassOrInterfaceDeclaration classOrInterfaceDeclaration, final Node arg) { - if (arg instanceof Project) { - Project project = (Project) arg; - // 章节 - Chapter chapter = new Chapter(); - classOrInterfaceDeclaration.getFullyQualifiedName().ifPresent(chapter::setId); - chapter.setName(classOrInterfaceDeclaration.getNameAsString()); - classOrInterfaceDeclaration.getComment().ifPresent(chapter::accept); - - OptionalHelper.any(chapter.getTag("book"), chapter.getTag("group")) - .ifPresent(tag -> chapter.setBookName(tag.getContent())); - - if (parserStrategy.accept(classOrInterfaceDeclaration)) { - parserStrategy.visit(classOrInterfaceDeclaration, chapter); - project.addChapter(chapter); - } - super.visit(classOrInterfaceDeclaration, chapter); - } - } - - - @Override - public void visit(JavadocComment javadocComment, Node arg) { - if (arg instanceof Chapter) { - Chapter chapter = (Chapter) arg; - OptionalHelper.any(chapter.getTag("code")) - .ifPresent(tag -> { - if (javadocComment.getCommentedNode().isPresent()) { - com.github.javaparser.ast.Node commentedNode = javadocComment.getCommentedNode().get(); - // 常量类||枚举类 - if (commentedNode instanceof ClassOrInterfaceDeclaration - || commentedNode instanceof EnumDeclaration) { - Appendix appendix = Appendix.parse(javadocComment); - if (appendix != null) { - ApiDoc.getInstance().getProject().getAppendices().add(appendix); - } - } - } - }); - - OptionalHelper.any(chapter.getTag("resultData")) - .ifPresent(tag -> { - if (javadocComment.getCommentedNode().isPresent()) { - com.github.javaparser.ast.Node commentedNode = javadocComment.getCommentedNode().get(); - // 常量类||枚举类 - if (commentedNode instanceof ClassOrInterfaceDeclaration) { - ClassOrInterfaceDeclaration classOrInterfaceDeclaration = (ClassOrInterfaceDeclaration) commentedNode; - ApiDoc.getInstance().getProject().setResultDataClassOrInterfaceDeclaration(classOrInterfaceDeclaration); - } - } - }); - } - super.visit(javadocComment, arg); - } - - /** - * 方法声明 - * - * @param methodDeclaration - * @param arg - */ - @Override - public void visit(final MethodDeclaration methodDeclaration, final Node arg) { - if (arg instanceof Chapter && parserStrategy.accept(methodDeclaration)) { - Chapter chapter = (Chapter) arg; - Section section = new Section(); - section.setId(methodDeclaration.getNameAsString()); - section.setName(methodDeclaration.getNameAsString()); - section.setIndex(chapter.getSections().size()); - methodDeclaration.getComment().ifPresent(section::accept); - - parserStrategy.visit(methodDeclaration, chapter, section); - chapter.getSections().add(section); - super.visit(methodDeclaration, section); - } - } - -} diff --git a/apidoc-core/src/main/java/com/kim/apidoc/core/render/MarkdownRender.java b/apidoc-core/src/main/java/com/kim/apidoc/core/render/MarkdownRender.java deleted file mode 100644 index 4943527..0000000 --- a/apidoc-core/src/main/java/com/kim/apidoc/core/render/MarkdownRender.java +++ /dev/null @@ -1,65 +0,0 @@ -package com.kim.apidoc.core.render; - -import com.kim.apidoc.core.ApiDoc; -import com.kim.apidoc.core.common.Constants; -import com.kim.apidoc.core.common.ObjectMappers; -import com.kim.apidoc.core.common.helper.FileHelper; -import com.kim.apidoc.core.schema.Project; -import freemarker.template.Configuration; -import freemarker.template.Template; -import lombok.extern.slf4j.Slf4j; - -import java.io.FileOutputStream; -import java.io.OutputStreamWriter; -import java.io.StringWriter; -import java.nio.file.Path; - - -/** - * 生成markdown api文档 - * - * @author duanledexianxianxian - * @version 1.0.0 - * @date 2020 /3/26 19:03 - * @since 1.0.0 - */ -@Slf4j -public class MarkdownRender implements ProjectRender { - private Configuration configuration; - - public MarkdownRender init() { - configuration = new Configuration(Configuration.DEFAULT_INCOMPATIBLE_IMPROVEMENTS); - configuration.setDefaultEncoding(Constants.UTF8); - configuration.setClassForTemplateLoading(MarkdownRender.class, Constants.SLASH); - return this; - } - - - @Override - public void render(Project project) { - this.init(); - try { - this.build(project); - } catch (Exception e) { - log.error("Build Markdown Fail {}", e.getMessage()); - } - } - - private void build(Project project) throws Exception { - String templatePath = ApiDoc.getInstance().getContext().getMarkdownTemplate(); - String id = ApiDoc.getInstance().getContext().getId(); - Path buildPath = ApiDoc.getInstance().getContext().getBuildPath(); - Path markdownFile = buildPath.resolve(id).resolve(id + Constants.MARKDOWN_EXTENSION); - - Template template = configuration.getTemplate(templatePath); - - StringWriter writer = new StringWriter(); - template.process(project, writer); - writer.flush(); - writer.close(); - - FileHelper.write(markdownFile, writer.getBuffer().toString()); - log.info("Build Markdown {}", markdownFile); - - } -} diff --git a/apidoc-core/src/main/java/com/kim/apidoc/core/schema/Appendix.java b/apidoc-core/src/main/java/com/kim/apidoc/core/schema/Appendix.java deleted file mode 100644 index b2148ff..0000000 --- a/apidoc-core/src/main/java/com/kim/apidoc/core/schema/Appendix.java +++ /dev/null @@ -1,74 +0,0 @@ -package com.kim.apidoc.core.schema; - -import com.github.javaparser.ast.body.BodyDeclaration; -import com.github.javaparser.ast.comments.JavadocComment; -import com.github.javaparser.ast.nodeTypes.NodeWithSimpleName; -import com.kim.apidoc.core.common.helper.EnumHelper; -import com.kim.apidoc.core.common.helper.FieldHelper; -import com.kim.apidoc.core.common.helper.FileHelper; -import lombok.Getter; -import lombok.Setter; - -import javax.annotation.Nullable; -import java.util.ArrayList; -import java.util.List; - -/** - * 附录 - */ -@Setter -@Getter -public class Appendix extends Node { - - /** - * The Cells. - */ - List> cells = new ArrayList<>(); - - /** - * Is empty boolean. - * - * @return the boolean - */ - public boolean isEmpty() { - return cells.isEmpty(); - } - - /** - * Parse appendix. - * - * @param n the n - * @return the appendix - */ - @Nullable - public static Appendix parse(JavadocComment n) { - if (!n.getCommentedNode().isPresent()) { - return null; - } - final com.github.javaparser.ast.Node node = n.getCommentedNode().get(); - if (!(node instanceof BodyDeclaration)) { - return null; - } - final BodyDeclaration bodyDeclaration = (BodyDeclaration) node; - // 不是枚举且不是类 - if (!bodyDeclaration.isEnumDeclaration() && !bodyDeclaration.isClassOrInterfaceDeclaration()) { - return null; - } - Appendix appendix = new Appendix(); - // 是枚举 - if (bodyDeclaration.isEnumDeclaration()) { - appendix.getCells().addAll(EnumHelper.toDetails(bodyDeclaration.asEnumDeclaration())); - } else if (bodyDeclaration.isClassOrInterfaceDeclaration()) { - // 常量类 - appendix.getCells().addAll(FieldHelper.getConstants(bodyDeclaration.asClassOrInterfaceDeclaration())); - } - if (node instanceof NodeWithSimpleName) { - appendix.setName(((NodeWithSimpleName) node).getNameAsString()); - } - if (node.getComment().isPresent()) { - appendix.accept(node.getComment().get()); - } - return appendix; - } - -} diff --git a/apidoc-core/src/main/java/com/kim/apidoc/core/schema/Cell.java b/apidoc-core/src/main/java/com/kim/apidoc/core/schema/Cell.java deleted file mode 100644 index 91739e0..0000000 --- a/apidoc-core/src/main/java/com/kim/apidoc/core/schema/Cell.java +++ /dev/null @@ -1,130 +0,0 @@ -package com.kim.apidoc.core.schema; - -import com.google.common.collect.Lists; - -import java.util.List; - -/** - * 多个数据的组合 - * - * @param the type parameter - */ -public class Cell { - - /** - * The Values. - */ - private List values; - - /** - * The Enable. - */ - private boolean enable; - - /** - * Instantiates a new Cell. - * - * @param values the values - */ - @SafeVarargs - public Cell(T ... values) { - this(true,values); - } - - /** - * Instantiates a new Cell. - * - * @param enable the enable - * @param values the values - */ - @SafeVarargs - public Cell(boolean enable, T ... values) { - this(enable, Lists.newArrayList(values)); - } - - /** - * Instantiates a new Cell. - * - * @param enable the enable - * @param values the values - */ - public Cell(boolean enable, List values) { - this.values = values; - this.enable = enable; - } - - /** - * To list list. - * - * @return the list - */ - public List toList(){ - return values; - } - - /** - * Is enable boolean. - * - * @return the boolean - */ - public boolean isEnable() { - return enable; - } - - /** - * Add. - * - * @param value the value - */ - public void add(T value){ - values.add(value); - } - - /** - * Size int. - * - * @return the int - */ - public int size(){ - return values.size(); - } - - /** - * Set. - * - * @param index the index - * @param t the t - */ - public void set(int index, T t){ - values.set(index, t); - } - - /** - * Get t. - * - * @param index the index - * @return the t - */ - public T get(int index){ - return values.get(index); - } - - /** - * Duplicate cell. - * - * @return the cell - */ - public Cell duplicate(){ - return new Cell<>(isEnable(), Lists.newArrayList(values)); - } - - /** - * Sets enable. - * - * @param enable the enable - */ - public void setEnable(boolean enable) { - this.enable = enable; - } - -} diff --git a/apidoc-core/src/main/java/com/kim/apidoc/core/schema/RequestParameterType.java b/apidoc-core/src/main/java/com/kim/apidoc/core/schema/RequestParameterType.java deleted file mode 100644 index dc17e8a..0000000 --- a/apidoc-core/src/main/java/com/kim/apidoc/core/schema/RequestParameterType.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.kim.apidoc.core.schema; - -/** - * 请求参数枚举类型 - * - * @author duanledexianxianxian - * @date 2020 /3/29 0:37 - * @since 1.0.0 - */ -public enum RequestParameterType { - /** - * 查询参数. - */ - QUERY, - /** - * 路径参数. - */ - PATH, - /** - * 请求参数体. - */ - BODY -} diff --git a/apidoc-core/src/main/java/com/kim/apidoc/core/ApiDoc.java b/apidoc-core/src/main/java/kim/apidoc/core/ApiDoc.java similarity index 90% rename from apidoc-core/src/main/java/com/kim/apidoc/core/ApiDoc.java rename to apidoc-core/src/main/java/kim/apidoc/core/ApiDoc.java index 6984ddd..fc12199 100644 --- a/apidoc-core/src/main/java/com/kim/apidoc/core/ApiDoc.java +++ b/apidoc-core/src/main/java/kim/apidoc/core/ApiDoc.java @@ -1,11 +1,11 @@ -package com.kim.apidoc.core; - -import com.kim.apidoc.core.common.helper.StringHelper; -import com.kim.apidoc.core.parser.ParserStrategy; -import com.kim.apidoc.core.parser.VisitorParser; -import com.kim.apidoc.core.render.ProjectRender; -import com.kim.apidoc.core.resolver.TypeResolvers; -import com.kim.apidoc.core.schema.Project; +package kim.apidoc.core; + +import kim.apidoc.core.common.helper.StringHelper; +import kim.apidoc.core.parser.ParserStrategy; +import kim.apidoc.core.parser.VisitorParser; +import kim.apidoc.core.render.ProjectRender; +import kim.apidoc.core.resolver.TypeResolvers; +import kim.apidoc.core.schema.Project; import com.github.javaparser.ParseResult; import com.github.javaparser.ParserConfiguration; import com.github.javaparser.ast.CompilationUnit; @@ -135,15 +135,15 @@ public class ApiDoc { if (strategies.isEmpty()) { throw new IllegalArgumentException("no ParserStrategy implements found"); } - if (StringHelper.isBlank(context.getFramework())) { + if (StringHelper.isBlank(context.framework)) { return strategies.get(0); } for (ParserStrategy strategy : strategies) { - if (Objects.equals(context.getFramework(), strategy.name())) { + if (Objects.equals(context.framework, strategy.name())) { return strategy; } } - throw new IllegalArgumentException("no ParserStrategy implements found for " + context.getFramework()); + throw new IllegalArgumentException("no ParserStrategy implements found for " + context.framework); } /** diff --git a/apidoc-core/src/main/java/com/kim/apidoc/core/Context.java b/apidoc-core/src/main/java/kim/apidoc/core/Context.java similarity index 74% rename from apidoc-core/src/main/java/com/kim/apidoc/core/Context.java rename to apidoc-core/src/main/java/kim/apidoc/core/Context.java index bb58954..01d1ed0 100644 --- a/apidoc-core/src/main/java/com/kim/apidoc/core/Context.java +++ b/apidoc-core/src/main/java/kim/apidoc/core/Context.java @@ -1,10 +1,11 @@ -package com.kim.apidoc.core; +package kim.apidoc.core; +import kim.apidoc.core.common.helper.FileHelper; +import kim.apidoc.core.render.AsciiDocRender; +import kim.apidoc.core.render.PostmanRender; +import kim.apidoc.core.render.ProjectRender; import com.google.common.collect.Lists; import com.google.common.collect.Maps; -import com.kim.apidoc.core.common.helper.FileHelper; -import com.kim.apidoc.core.render.MarkdownRender; -import com.kim.apidoc.core.render.ProjectRender; import lombok.Getter; import lombok.Setter; @@ -13,8 +14,6 @@ import java.nio.file.Paths; import java.util.List; import java.util.Map; -import static com.kim.apidoc.core.common.Constants.MARKDOWN_TEMPLATE; - /** * The type Context. * @@ -45,16 +44,15 @@ public class Context { * 设置当前解析框架 */ @Setter - private String framework; + public String framework; /** * The Renders. */ @Setter - private List renders = Lists.newArrayList( - //new AsciiDocRender(), - //new PostmanRender(), - new MarkdownRender()); + public List renders = Lists.newArrayList( + new AsciiDocRender(), + new PostmanRender()); /** * 编译目录 @@ -104,24 +102,17 @@ public class Context { @Setter private String css; - - /** - * markdown模版文件路径 - */ - @Setter - private String markdownTemplate = MARKDOWN_TEMPLATE; - /** * 自定义扩展参数 */ - private Map ext = Maps.newHashMap(); + private Map ext= Maps.newHashMap(); /** * Add source. * * @param path the path */ - public void addSource(Path path) { + public void addSource(Path path){ sources.add(path); sources.addAll(FileHelper.find(path, DEFAULT_CODE_STRUCTURE)); addDependency(path); @@ -132,7 +123,7 @@ public class Context { * * @param path the path */ - public void addDependency(Path path) { + public void addDependency(Path path){ dependencies.add(path); dependencies.addAll(FileHelper.find(path, DEFAULT_CODE_STRUCTURE)); } @@ -142,9 +133,10 @@ public class Context { * * @param path the path */ - public void addJar(Path path) { + public void addJar(Path path){ jars.add(path); } + } diff --git a/apidoc-core/src/main/java/com/kim/apidoc/core/common/Assert.java b/apidoc-core/src/main/java/kim/apidoc/core/common/Assert.java similarity index 94% rename from apidoc-core/src/main/java/com/kim/apidoc/core/common/Assert.java rename to apidoc-core/src/main/java/kim/apidoc/core/common/Assert.java index ea8bcb2..a98d17d 100644 --- a/apidoc-core/src/main/java/com/kim/apidoc/core/common/Assert.java +++ b/apidoc-core/src/main/java/kim/apidoc/core/common/Assert.java @@ -1,4 +1,4 @@ -package com.kim.apidoc.core.common; +package kim.apidoc.core.common; import com.google.common.base.Strings; diff --git a/apidoc-core/src/main/java/com/kim/apidoc/core/common/ObjectMappers.java b/apidoc-core/src/main/java/kim/apidoc/core/common/ObjectMappers.java similarity index 96% rename from apidoc-core/src/main/java/com/kim/apidoc/core/common/ObjectMappers.java rename to apidoc-core/src/main/java/kim/apidoc/core/common/ObjectMappers.java index d8fa44b..685cb26 100644 --- a/apidoc-core/src/main/java/com/kim/apidoc/core/common/ObjectMappers.java +++ b/apidoc-core/src/main/java/kim/apidoc/core/common/ObjectMappers.java @@ -1,4 +1,4 @@ -package com.kim.apidoc.core.common; +package kim.apidoc.core.common; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.core.JsonProcessingException; diff --git a/apidoc-core/src/main/java/com/kim/apidoc/core/common/QueryStringBuilder.java b/apidoc-core/src/main/java/kim/apidoc/core/common/QueryStringBuilder.java similarity index 96% rename from apidoc-core/src/main/java/com/kim/apidoc/core/common/QueryStringBuilder.java rename to apidoc-core/src/main/java/kim/apidoc/core/common/QueryStringBuilder.java index 1bfb727..9cfafa5 100644 --- a/apidoc-core/src/main/java/com/kim/apidoc/core/common/QueryStringBuilder.java +++ b/apidoc-core/src/main/java/kim/apidoc/core/common/QueryStringBuilder.java @@ -1,4 +1,4 @@ -package com.kim.apidoc.core.common; +package kim.apidoc.core.common; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.node.ObjectNode; diff --git a/apidoc-core/src/main/java/com/kim/apidoc/core/common/URI.java b/apidoc-core/src/main/java/kim/apidoc/core/common/URI.java similarity index 93% rename from apidoc-core/src/main/java/com/kim/apidoc/core/common/URI.java rename to apidoc-core/src/main/java/kim/apidoc/core/common/URI.java index c053981..909071c 100644 --- a/apidoc-core/src/main/java/com/kim/apidoc/core/common/URI.java +++ b/apidoc-core/src/main/java/kim/apidoc/core/common/URI.java @@ -1,6 +1,6 @@ -package com.kim.apidoc.core.common; +package kim.apidoc.core.common; -import com.kim.apidoc.core.common.helper.StringHelper; +import kim.apidoc.core.common.helper.StringHelper; import com.google.common.collect.Lists; import lombok.EqualsAndHashCode; import lombok.Getter; diff --git a/apidoc-core/src/main/java/com/kim/apidoc/core/common/description/ArrayTypeDescription.java b/apidoc-core/src/main/java/kim/apidoc/core/common/description/ArrayTypeDescription.java similarity index 94% rename from apidoc-core/src/main/java/com/kim/apidoc/core/common/description/ArrayTypeDescription.java rename to apidoc-core/src/main/java/kim/apidoc/core/common/description/ArrayTypeDescription.java index 4b05db0..8359d86 100644 --- a/apidoc-core/src/main/java/com/kim/apidoc/core/common/description/ArrayTypeDescription.java +++ b/apidoc-core/src/main/java/kim/apidoc/core/common/description/ArrayTypeDescription.java @@ -1,15 +1,12 @@ -package com.kim.apidoc.core.common.description; +package kim.apidoc.core.common.description; -import com.kim.apidoc.core.schema.Row; -import com.kim.apidoc.core.common.ObjectMappers; +import kim.apidoc.core.common.ObjectMappers; +import kim.apidoc.core.schema.Row; import com.fasterxml.jackson.databind.node.ArrayNode; import java.util.ArrayList; import java.util.Collection; -/** - * 数组类型描述 - */ public class ArrayTypeDescription extends TypeDescription { protected ArrayNode value; diff --git a/apidoc-core/src/main/java/com/kim/apidoc/core/common/description/ObjectTypeDescription.java b/apidoc-core/src/main/java/kim/apidoc/core/common/description/ObjectTypeDescription.java similarity index 79% rename from apidoc-core/src/main/java/com/kim/apidoc/core/common/description/ObjectTypeDescription.java rename to apidoc-core/src/main/java/kim/apidoc/core/common/description/ObjectTypeDescription.java index 8aba8aa..f614fd1 100644 --- a/apidoc-core/src/main/java/com/kim/apidoc/core/common/description/ObjectTypeDescription.java +++ b/apidoc-core/src/main/java/kim/apidoc/core/common/description/ObjectTypeDescription.java @@ -1,7 +1,7 @@ -package com.kim.apidoc.core.common.description; +package kim.apidoc.core.common.description; -import com.kim.apidoc.core.schema.Row; -import com.kim.apidoc.core.common.ObjectMappers; +import kim.apidoc.core.common.ObjectMappers; +import kim.apidoc.core.schema.Row; import com.fasterxml.jackson.databind.node.ObjectNode; import com.google.common.collect.Lists; import lombok.Getter; @@ -10,40 +10,18 @@ import lombok.Setter; import java.util.Collection; import java.util.List; -/** - * 对象类型描述 - * - * @author fengyuchenglun - * @version 1.0.0 - */ @Setter @Getter public class ObjectTypeDescription extends TypeDescription { - /** - * The Members. - */ protected List members = Lists.newArrayList(); - /** - * The Value. - */ private ObjectNode value = ObjectMappers.instance.createObjectNode(); - /** - * Merge. - * - * @param other the other - */ public void merge(ObjectTypeDescription other) { value.setAll(other.getValue()); members.addAll(other.members); } - /** - * Add. - * - * @param component the component - */ public void add(TypeDescription component) { members.add(component); if (component.isPrimitive()) { @@ -57,11 +35,6 @@ public class ObjectTypeDescription extends TypeDescription { } } - /** - * Primitive. - * - * @param typeDescription the type description - */ public void primitive(PrimitiveTypeDescription typeDescription) { switch (typeDescription.getType()) { case "byte": @@ -128,15 +101,4 @@ public class ObjectTypeDescription extends TypeDescription { } return rows; } - - @Override - public Collection rows(String requestParameterType) { - Collection rows = super.rows(null); - for (TypeDescription member : members) { - if (member.isAvailable()) { - rows.addAll(member.rows(requestParameterType)); - } - } - return rows; - } } diff --git a/apidoc-core/src/main/java/com/kim/apidoc/core/common/description/PrimitiveTypeDescription.java b/apidoc-core/src/main/java/kim/apidoc/core/common/description/PrimitiveTypeDescription.java similarity index 86% rename from apidoc-core/src/main/java/com/kim/apidoc/core/common/description/PrimitiveTypeDescription.java rename to apidoc-core/src/main/java/kim/apidoc/core/common/description/PrimitiveTypeDescription.java index 84e53a5..0eb349e 100644 --- a/apidoc-core/src/main/java/com/kim/apidoc/core/common/description/PrimitiveTypeDescription.java +++ b/apidoc-core/src/main/java/kim/apidoc/core/common/description/PrimitiveTypeDescription.java @@ -1,18 +1,11 @@ -package com.kim.apidoc.core.common.description; +package kim.apidoc.core.common.description; import com.github.javaparser.resolution.types.ResolvedPrimitiveType; import com.github.javaparser.resolution.types.ResolvedReferenceType; -/** - * 原始类型描述 - */ + public class PrimitiveTypeDescription extends TypeDescription { - /** - * Instantiates a new Primitive type description. - * - * @param referenceType the reference type - */ public PrimitiveTypeDescription(ResolvedReferenceType referenceType) { switch (referenceType.getId()) { case "java.lang.Byte": @@ -51,11 +44,6 @@ public class PrimitiveTypeDescription extends TypeDescription { } - /** - * Instantiates a new Primitive type description. - * - * @param resolvedPrimitiveType the resolved primitive type - */ public PrimitiveTypeDescription(ResolvedPrimitiveType resolvedPrimitiveType) { type = resolvedPrimitiveType.describe(); switch (resolvedPrimitiveType) { diff --git a/apidoc-core/src/main/java/com/kim/apidoc/core/common/description/StringTypeDescription.java b/apidoc-core/src/main/java/kim/apidoc/core/common/description/StringTypeDescription.java similarity index 56% rename from apidoc-core/src/main/java/com/kim/apidoc/core/common/description/StringTypeDescription.java rename to apidoc-core/src/main/java/kim/apidoc/core/common/description/StringTypeDescription.java index 021bd95..f8d589b 100644 --- a/apidoc-core/src/main/java/com/kim/apidoc/core/common/description/StringTypeDescription.java +++ b/apidoc-core/src/main/java/kim/apidoc/core/common/description/StringTypeDescription.java @@ -1,16 +1,7 @@ -package com.kim.apidoc.core.common.description; +package kim.apidoc.core.common.description; -/** - * 字符串类型 - */ public class StringTypeDescription extends TypeDescription { - /** - * Instantiates a new String type description. - * - * @param type the type - * @param charSequence the char sequence - */ public StringTypeDescription(String type, CharSequence charSequence) { this.type = type; value = charSequence.toString(); diff --git a/apidoc-core/src/main/java/kim/apidoc/core/common/description/TypeDescription.java b/apidoc-core/src/main/java/kim/apidoc/core/common/description/TypeDescription.java new file mode 100644 index 0000000..57b7cc9 --- /dev/null +++ b/apidoc-core/src/main/java/kim/apidoc/core/common/description/TypeDescription.java @@ -0,0 +1,100 @@ +package kim.apidoc.core.common.description; + +import kim.apidoc.core.common.helper.StringHelper; +import kim.apidoc.core.schema.Row; +import com.google.common.collect.Lists; +import lombok.Getter; +import lombok.Setter; + +import java.util.Collection; + +@Setter +@Getter +public abstract class TypeDescription { + + protected String prefix = ""; + protected String key = ""; + protected String type; + protected StringBuilder condition = new StringBuilder(); + protected String remark; + protected Object value; + protected Object defaultValue; + protected Boolean required; + + public boolean isAvailable() { + return !isUnAvailable(); + } + + public boolean isUnAvailable() { + return this instanceof UnAvailableTypeDescription; + } + + public boolean isPrimitive() { + return this instanceof PrimitiveTypeDescription; + } + + public PrimitiveTypeDescription asPrimitive() { + return (PrimitiveTypeDescription) this; + } + + public boolean isString() { + return this instanceof StringTypeDescription; + } + + public StringTypeDescription asString() { + return (StringTypeDescription) this; + } + + public boolean isArray() { + return this instanceof ArrayTypeDescription; + } + + public ArrayTypeDescription asArray() { + return (ArrayTypeDescription) this; + } + + public boolean isObject() { + return this instanceof ObjectTypeDescription; + } + + public ObjectTypeDescription asObject() { + return (ObjectTypeDescription) this; + } + + public void addRemark(String value) { + if (value == null) { + return; + } + if (remark == null) { + remark = value; + } else { + remark += " " + value; + } + } + + public String fullKey() { + return StringHelper.join(".", prefix, key); + } + + public Collection rows() { + String key = fullKey(); + if (StringHelper.isBlank(key)) { + return Lists.newArrayList(); + } + String def; + if (defaultValue != null) { + def = String.valueOf(defaultValue); + } else if (value != null) { + def = String.valueOf(value); + } else { + def = ""; + } + + if (required != null) { + condition.append("required=").append(required); + } + + return Lists.newArrayList(new Row(key, type, condition.toString(), def, remark)); + } + +} diff --git a/apidoc-core/src/main/java/com/kim/apidoc/core/common/description/UnAvailableTypeDescription.java b/apidoc-core/src/main/java/kim/apidoc/core/common/description/UnAvailableTypeDescription.java similarity index 83% rename from apidoc-core/src/main/java/com/kim/apidoc/core/common/description/UnAvailableTypeDescription.java rename to apidoc-core/src/main/java/kim/apidoc/core/common/description/UnAvailableTypeDescription.java index a294121..d40e90e 100644 --- a/apidoc-core/src/main/java/com/kim/apidoc/core/common/description/UnAvailableTypeDescription.java +++ b/apidoc-core/src/main/java/kim/apidoc/core/common/description/UnAvailableTypeDescription.java @@ -1,6 +1,6 @@ -package com.kim.apidoc.core.common.description; +package kim.apidoc.core.common.description; -import com.kim.apidoc.core.schema.Row; +import kim.apidoc.core.schema.Row; import java.util.Collection; diff --git a/apidoc-core/src/main/java/com/kim/apidoc/core/common/diff/FileMatcher.java b/apidoc-core/src/main/java/kim/apidoc/core/common/diff/FileMatcher.java similarity index 98% rename from apidoc-core/src/main/java/com/kim/apidoc/core/common/diff/FileMatcher.java rename to apidoc-core/src/main/java/kim/apidoc/core/common/diff/FileMatcher.java index 14031b8..52b5806 100644 --- a/apidoc-core/src/main/java/com/kim/apidoc/core/common/diff/FileMatcher.java +++ b/apidoc-core/src/main/java/kim/apidoc/core/common/diff/FileMatcher.java @@ -1,4 +1,4 @@ -package com.kim.apidoc.core.common.diff; +package kim.apidoc.core.common.diff; import com.google.common.base.Charsets; import lombok.Getter; diff --git a/apidoc-core/src/main/java/com/kim/apidoc/core/common/diff/FileSystem.java b/apidoc-core/src/main/java/kim/apidoc/core/common/diff/FileSystem.java similarity index 97% rename from apidoc-core/src/main/java/com/kim/apidoc/core/common/diff/FileSystem.java rename to apidoc-core/src/main/java/kim/apidoc/core/common/diff/FileSystem.java index 0f6115f..447274b 100644 --- a/apidoc-core/src/main/java/com/kim/apidoc/core/common/diff/FileSystem.java +++ b/apidoc-core/src/main/java/kim/apidoc/core/common/diff/FileSystem.java @@ -1,4 +1,4 @@ -package com.kim.apidoc.core.common.diff; +package kim.apidoc.core.common.diff; import java.awt.*; import java.io.File; diff --git a/apidoc-core/src/main/java/com/kim/apidoc/core/common/diff/MatchPatcher.java b/apidoc-core/src/main/java/kim/apidoc/core/common/diff/MatchPatcher.java similarity index 99% rename from apidoc-core/src/main/java/com/kim/apidoc/core/common/diff/MatchPatcher.java rename to apidoc-core/src/main/java/kim/apidoc/core/common/diff/MatchPatcher.java index 311bf40..0d0da4b 100644 --- a/apidoc-core/src/main/java/com/kim/apidoc/core/common/diff/MatchPatcher.java +++ b/apidoc-core/src/main/java/kim/apidoc/core/common/diff/MatchPatcher.java @@ -15,7 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.kim.apidoc.core.common.diff; +package kim.apidoc.core.common.diff; import java.io.UnsupportedEncodingException; import java.net.URLDecoder; diff --git a/apidoc-core/src/main/java/com/kim/apidoc/core/common/helper/AnnotationHelper.java b/apidoc-core/src/main/java/kim/apidoc/core/common/helper/AnnotationHelper.java similarity index 91% rename from apidoc-core/src/main/java/com/kim/apidoc/core/common/helper/AnnotationHelper.java rename to apidoc-core/src/main/java/kim/apidoc/core/common/helper/AnnotationHelper.java index a539365..4304fec 100644 --- a/apidoc-core/src/main/java/com/kim/apidoc/core/common/helper/AnnotationHelper.java +++ b/apidoc-core/src/main/java/kim/apidoc/core/common/helper/AnnotationHelper.java @@ -1,4 +1,4 @@ -package com.kim.apidoc.core.common.helper; +package kim.apidoc.core.common.helper; import com.github.javaparser.ast.expr.*; import com.github.javaparser.ast.nodeTypes.NodeWithAnnotations; @@ -24,7 +24,7 @@ public class AnnotationHelper { } if (annotationExpr.isNormalAnnotationExpr()) { for (MemberValuePair pair : annotationExpr.asNormalAnnotationExpr().getPairs()) { - if (Objects.equals(key, pair.getNameAsString())) { + if (Objects.equals(key, pair.getNameAsString())){ return Optional.of(pair.getValue()); } } @@ -32,10 +32,10 @@ public class AnnotationHelper { return Optional.empty(); } - public static Optional getAnyAttribute(AnnotationExpr annotationExpr, String... keys) { + public static Optional getAnyAttribute(AnnotationExpr annotationExpr, String ... keys) { for (String key : keys) { Optional optional = getAttribute(annotationExpr, key); - if (optional.isPresent()) { + if(optional.isPresent()){ return optional; } } diff --git a/apidoc-core/src/main/java/com/kim/apidoc/core/common/helper/ClassDeclarationHelper.java b/apidoc-core/src/main/java/kim/apidoc/core/common/helper/ClassDeclarationHelper.java similarity index 69% rename from apidoc-core/src/main/java/com/kim/apidoc/core/common/helper/ClassDeclarationHelper.java rename to apidoc-core/src/main/java/kim/apidoc/core/common/helper/ClassDeclarationHelper.java index 3ea0d10..cc0a05f 100644 --- a/apidoc-core/src/main/java/com/kim/apidoc/core/common/helper/ClassDeclarationHelper.java +++ b/apidoc-core/src/main/java/kim/apidoc/core/common/helper/ClassDeclarationHelper.java @@ -1,12 +1,15 @@ -package com.kim.apidoc.core.common.helper; +package kim.apidoc.core.common.helper; import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; +import com.github.javaparser.ast.body.FieldDeclaration; import com.github.javaparser.ast.type.ClassOrInterfaceType; import com.github.javaparser.resolution.types.ResolvedReferenceType; import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserClassDeclaration; import com.github.javaparser.symbolsolver.reflectionmodel.ReflectionClassDeclaration; import lombok.extern.slf4j.Slf4j; +import java.util.ArrayList; +import java.util.List; import java.util.Optional; @Slf4j @@ -25,9 +28,9 @@ public class ClassDeclarationHelper { if (resolvedReferenceType.getTypeDeclaration() instanceof JavaParserClassDeclaration) { JavaParserClassDeclaration typeDeclaration = (JavaParserClassDeclaration) resolvedReferenceType.getTypeDeclaration(); return Optional.of(typeDeclaration.getWrappedNode()); - } else if (resolvedReferenceType.getTypeDeclaration() instanceof ReflectionClassDeclaration) { + }else if(resolvedReferenceType.getTypeDeclaration() instanceof ReflectionClassDeclaration){ ReflectionClassDeclaration typeDeclaration = (ReflectionClassDeclaration) resolvedReferenceType.getTypeDeclaration(); - System.out.println("type Declaration:" + typeDeclaration); + System.out.println("type Declaration:"+typeDeclaration); //TODO } } catch (Exception e) { @@ -36,16 +39,4 @@ public class ClassDeclarationHelper { return Optional.empty(); } - public static String getClassOrInterfacePackageName(ClassOrInterfaceDeclaration classOrInterfaceDeclaration) { - final String[] result = {null}; - classOrInterfaceDeclaration.findCompilationUnit().ifPresent(x -> { - x.getPackageDeclaration().ifPresent(y -> { - result[0] = y.getNameAsString() + "." + classOrInterfaceDeclaration.getName(); - }); - }); - return result[0]; - - } - } - diff --git a/apidoc-core/src/main/java/com/kim/apidoc/core/common/helper/CommentHelper.java b/apidoc-core/src/main/java/kim/apidoc/core/common/helper/CommentHelper.java similarity index 72% rename from apidoc-core/src/main/java/com/kim/apidoc/core/common/helper/CommentHelper.java rename to apidoc-core/src/main/java/kim/apidoc/core/common/helper/CommentHelper.java index 86e8f7e..86234f2 100644 --- a/apidoc-core/src/main/java/com/kim/apidoc/core/common/helper/CommentHelper.java +++ b/apidoc-core/src/main/java/kim/apidoc/core/common/helper/CommentHelper.java @@ -1,4 +1,4 @@ -package com.kim.apidoc.core.common.helper; +package kim.apidoc.core.common.helper; import com.github.javaparser.ast.body.FieldDeclaration; import com.github.javaparser.ast.body.MethodDeclaration; @@ -15,73 +15,49 @@ import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParse import java.util.Optional; import java.util.stream.Collectors; -/** - * The type Comment helper. - */ public class CommentHelper { /** * 获取完整注释字符串 - * - * @param description the description - * @return string + * @param description + * @return */ - public static String getDescription(JavadocDescription description) { + public static String getDescription(JavadocDescription description){ return description.getElements() .stream() .filter(e -> !(e instanceof JavadocInlineTag)) .map(JavadocDescriptionElement::toText).collect(Collectors.joining()); } - /** - * Get content string. - * - * @param comment the comment - * @return the string - */ - public static String getContent(Comment comment) { - if (!comment.isJavadocComment()) { + public static String getContent(Comment comment){ + if(!comment.isJavadocComment()){ return comment.getContent(); } return getDescription(comment.asJavadocComment().parse().getDescription()); } - /** - * Get comment string. - * - * @param it the it - * @return the string - */ - public static String getComment(MethodUsage it) { + public static String getComment(MethodUsage it){ if (it.getDeclaration() instanceof JavaParserMethodDeclaration) { MethodDeclaration wrappedNode = ((JavaParserMethodDeclaration) it.getDeclaration()).getWrappedNode(); Optional optional = wrappedNode.getComment(); - if (optional.isPresent()) { + if(optional.isPresent()){ return CommentHelper.getContent(optional.get()); } } return null; } - - /** - * Get comment string. - * - * @param it the it - * @return the string - */ - public static String getComment(ResolvedFieldDeclaration it) { - if (it instanceof JavaParserFieldDeclaration) { + public static String getComment(ResolvedFieldDeclaration it){ + if(it instanceof JavaParserFieldDeclaration){ FieldDeclaration wrappedNode = ((JavaParserFieldDeclaration) it).getWrappedNode(); Optional optional = wrappedNode.getComment(); - if (optional.isPresent()) { + if(optional.isPresent()){ return CommentHelper.getContent(optional.get()); } - } else if (it instanceof JavaParserClassDeclaration) { + }else if(it instanceof JavaParserClassDeclaration){ JavaParserClassDeclaration classDeclaration = (JavaParserClassDeclaration) it; + } return null; } - - } diff --git a/apidoc-core/src/main/java/com/kim/apidoc/core/common/helper/CompilationUnitHelper.java b/apidoc-core/src/main/java/kim/apidoc/core/common/helper/CompilationUnitHelper.java similarity index 73% rename from apidoc-core/src/main/java/com/kim/apidoc/core/common/helper/CompilationUnitHelper.java rename to apidoc-core/src/main/java/kim/apidoc/core/common/helper/CompilationUnitHelper.java index dbb34bf..5cd7591 100644 --- a/apidoc-core/src/main/java/com/kim/apidoc/core/common/helper/CompilationUnitHelper.java +++ b/apidoc-core/src/main/java/kim/apidoc/core/common/helper/CompilationUnitHelper.java @@ -1,4 +1,4 @@ -package com.kim.apidoc.core.common.helper; +package kim.apidoc.core.common.helper; import com.github.javaparser.ast.CompilationUnit; import com.github.javaparser.ast.Node; @@ -7,11 +7,11 @@ import java.util.Optional; public class CompilationUnitHelper { - public static Optional getCompilationUnit(Node node) { - if (node instanceof CompilationUnit) { + public static Optional getCompilationUnit(Node node){ + if(node instanceof CompilationUnit){ return Optional.of((CompilationUnit) node); } - if (node.getParentNode().isPresent()) { + if (node.getParentNode().isPresent()){ return getCompilationUnit(node.getParentNode().get()); } return Optional.empty(); diff --git a/apidoc-core/src/main/java/com/kim/apidoc/core/common/helper/ExpressionHelper.java b/apidoc-core/src/main/java/kim/apidoc/core/common/helper/ExpressionHelper.java similarity index 98% rename from apidoc-core/src/main/java/com/kim/apidoc/core/common/helper/ExpressionHelper.java rename to apidoc-core/src/main/java/kim/apidoc/core/common/helper/ExpressionHelper.java index a208309..13adf03 100644 --- a/apidoc-core/src/main/java/com/kim/apidoc/core/common/helper/ExpressionHelper.java +++ b/apidoc-core/src/main/java/kim/apidoc/core/common/helper/ExpressionHelper.java @@ -1,4 +1,4 @@ -package com.kim.apidoc.core.common.helper; +package kim.apidoc.core.common.helper; import com.github.javaparser.ast.NodeList; import com.github.javaparser.ast.expr.*; diff --git a/apidoc-core/src/main/java/kim/apidoc/core/common/helper/FieldHelper.java b/apidoc-core/src/main/java/kim/apidoc/core/common/helper/FieldHelper.java new file mode 100644 index 0000000..fcb8c53 --- /dev/null +++ b/apidoc-core/src/main/java/kim/apidoc/core/common/helper/FieldHelper.java @@ -0,0 +1,38 @@ +package kim.apidoc.core.common.helper; + +import com.github.javaparser.ast.expr.Expression; +import com.github.javaparser.resolution.declarations.ResolvedFieldDeclaration; +import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserFieldDeclaration; + +import java.util.Optional; + +public class FieldHelper { + + /** + * 通过access方法,获取属性名 + * @param methodName access方法名 + * @return 属性名 + */ + public static String getByAccessMethod(String methodName){ + if(methodName.startsWith("is") && methodName.length()>2){ + String first = methodName.substring(2, 3); + String less = methodName.substring(3); + return first.toLowerCase() + less; + } + if(methodName.startsWith("get") && methodName.length()>3){ + String first = methodName.substring(3, 4); + String less = methodName.substring(4); + return first.toLowerCase() + less; + } + return null; + } + + public static Optional getInitializer(ResolvedFieldDeclaration declaredField){ + if(declaredField instanceof JavaParserFieldDeclaration){ + JavaParserFieldDeclaration field = (JavaParserFieldDeclaration) declaredField; + return field.getVariableDeclarator().getInitializer(); + } + return Optional.empty(); + } + +} diff --git a/apidoc-core/src/main/java/com/kim/apidoc/core/common/helper/FileHelper.java b/apidoc-core/src/main/java/kim/apidoc/core/common/helper/FileHelper.java similarity index 85% rename from apidoc-core/src/main/java/com/kim/apidoc/core/common/helper/FileHelper.java rename to apidoc-core/src/main/java/kim/apidoc/core/common/helper/FileHelper.java index 59247b8..7a78036 100644 --- a/apidoc-core/src/main/java/com/kim/apidoc/core/common/helper/FileHelper.java +++ b/apidoc-core/src/main/java/kim/apidoc/core/common/helper/FileHelper.java @@ -1,4 +1,4 @@ -package com.kim.apidoc.core.common.helper; +package kim.apidoc.core.common.helper; import com.google.common.collect.Lists; import lombok.extern.slf4j.Slf4j; @@ -32,10 +32,10 @@ public class FileHelper { } } - public static List find(Path start, String structure) { + public static List find(Path start, String structure){ try { return Files.walk(start) - .filter(p -> p.endsWith(structure)).collect(Collectors.toList()); + .filter(p->p.endsWith(structure)).collect(Collectors.toList()); } catch (IOException e) { log.warn("find path error:{} {}", start, e.getMessage()); } diff --git a/apidoc-core/src/main/java/com/kim/apidoc/core/common/helper/JsonPropertyHelper.java b/apidoc-core/src/main/java/kim/apidoc/core/common/helper/JsonPropertyHelper.java similarity index 97% rename from apidoc-core/src/main/java/com/kim/apidoc/core/common/helper/JsonPropertyHelper.java rename to apidoc-core/src/main/java/kim/apidoc/core/common/helper/JsonPropertyHelper.java index 447b79d..63c748a 100644 --- a/apidoc-core/src/main/java/com/kim/apidoc/core/common/helper/JsonPropertyHelper.java +++ b/apidoc-core/src/main/java/kim/apidoc/core/common/helper/JsonPropertyHelper.java @@ -1,4 +1,4 @@ -package com.kim.apidoc.core.common.helper; +package kim.apidoc.core.common.helper; import com.github.javaparser.ast.body.FieldDeclaration; import com.github.javaparser.ast.expr.AnnotationExpr; diff --git a/apidoc-core/src/main/java/com/kim/apidoc/core/common/helper/OptionalHelper.java b/apidoc-core/src/main/java/kim/apidoc/core/common/helper/OptionalHelper.java similarity index 60% rename from apidoc-core/src/main/java/com/kim/apidoc/core/common/helper/OptionalHelper.java rename to apidoc-core/src/main/java/kim/apidoc/core/common/helper/OptionalHelper.java index 8aab28b..661243d 100644 --- a/apidoc-core/src/main/java/com/kim/apidoc/core/common/helper/OptionalHelper.java +++ b/apidoc-core/src/main/java/kim/apidoc/core/common/helper/OptionalHelper.java @@ -1,13 +1,13 @@ -package com.kim.apidoc.core.common.helper; +package kim.apidoc.core.common.helper; import java.util.Optional; public class OptionalHelper { @SafeVarargs - public static Optional any(Optional... optionals) { + public static Optional any(Optional ... optionals){ for (Optional optional : optionals) { - if (optional.isPresent()) { + if(optional.isPresent()){ return optional; } } diff --git a/apidoc-core/src/main/java/com/kim/apidoc/core/common/helper/ReferenceContext.java b/apidoc-core/src/main/java/kim/apidoc/core/common/helper/ReferenceContext.java similarity index 94% rename from apidoc-core/src/main/java/com/kim/apidoc/core/common/helper/ReferenceContext.java rename to apidoc-core/src/main/java/kim/apidoc/core/common/helper/ReferenceContext.java index 8ef8fcd..20daa40 100644 --- a/apidoc-core/src/main/java/com/kim/apidoc/core/common/helper/ReferenceContext.java +++ b/apidoc-core/src/main/java/kim/apidoc/core/common/helper/ReferenceContext.java @@ -1,4 +1,4 @@ -package com.kim.apidoc.core.common.helper; +package kim.apidoc.core.common.helper; import com.google.common.collect.Sets; diff --git a/apidoc-core/src/main/java/com/kim/apidoc/core/common/helper/StringHelper.java b/apidoc-core/src/main/java/kim/apidoc/core/common/helper/StringHelper.java similarity index 77% rename from apidoc-core/src/main/java/com/kim/apidoc/core/common/helper/StringHelper.java rename to apidoc-core/src/main/java/kim/apidoc/core/common/helper/StringHelper.java index 14f9f4e..08e98fe 100644 --- a/apidoc-core/src/main/java/com/kim/apidoc/core/common/helper/StringHelper.java +++ b/apidoc-core/src/main/java/kim/apidoc/core/common/helper/StringHelper.java @@ -1,4 +1,4 @@ -package com.kim.apidoc.core.common.helper; +package kim.apidoc.core.common.helper; import com.google.common.base.Strings; @@ -13,26 +13,26 @@ public class StringHelper { } public static boolean isBlank(Object text) { - if (text instanceof String) { + if(text instanceof String){ return isBlank(((String) text)); } return isBlank(String.valueOf(text)); } public static boolean nonBlank(Object text) { - if (text instanceof String) { + if(text instanceof String){ return nonBlank(((String) text)); } return nonBlank(String.valueOf(text)); } - public static String join(String delimiter, String... values) { + public static String join(String delimiter, String ... values){ StringBuilder builder = new StringBuilder(); for (String value : values) { - if (isBlank(value)) { + if(isBlank(value)){ continue; } - if (builder.length() > 0) { + if(builder.length()>0){ builder.append(delimiter); } builder.append(value); diff --git a/apidoc-core/src/main/java/com/kim/apidoc/core/common/helper/TypeNameHelper.java b/apidoc-core/src/main/java/kim/apidoc/core/common/helper/TypeNameHelper.java similarity index 97% rename from apidoc-core/src/main/java/com/kim/apidoc/core/common/helper/TypeNameHelper.java rename to apidoc-core/src/main/java/kim/apidoc/core/common/helper/TypeNameHelper.java index 64fef12..38efcaf 100644 --- a/apidoc-core/src/main/java/com/kim/apidoc/core/common/helper/TypeNameHelper.java +++ b/apidoc-core/src/main/java/kim/apidoc/core/common/helper/TypeNameHelper.java @@ -1,4 +1,4 @@ -package com.kim.apidoc.core.common.helper; +package kim.apidoc.core.common.helper; import com.github.javaparser.ast.CompilationUnit; import com.github.javaparser.ast.ImportDeclaration; diff --git a/apidoc-core/src/main/java/com/kim/apidoc/core/common/helper/TypeParameterHelper.java b/apidoc-core/src/main/java/kim/apidoc/core/common/helper/TypeParameterHelper.java similarity index 98% rename from apidoc-core/src/main/java/com/kim/apidoc/core/common/helper/TypeParameterHelper.java rename to apidoc-core/src/main/java/kim/apidoc/core/common/helper/TypeParameterHelper.java index 42ad047..722d0b0 100644 --- a/apidoc-core/src/main/java/com/kim/apidoc/core/common/helper/TypeParameterHelper.java +++ b/apidoc-core/src/main/java/kim/apidoc/core/common/helper/TypeParameterHelper.java @@ -1,4 +1,4 @@ -package com.kim.apidoc.core.common.helper; +package kim.apidoc.core.common.helper; import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration; import com.github.javaparser.resolution.types.ResolvedReferenceType; diff --git a/apidoc-core/src/main/java/com/kim/apidoc/core/common/helper/ValidationHelper.java b/apidoc-core/src/main/java/kim/apidoc/core/common/helper/ValidationHelper.java similarity index 97% rename from apidoc-core/src/main/java/com/kim/apidoc/core/common/helper/ValidationHelper.java rename to apidoc-core/src/main/java/kim/apidoc/core/common/helper/ValidationHelper.java index 44f849b..0d42101 100644 --- a/apidoc-core/src/main/java/com/kim/apidoc/core/common/helper/ValidationHelper.java +++ b/apidoc-core/src/main/java/kim/apidoc/core/common/helper/ValidationHelper.java @@ -1,4 +1,4 @@ -package com.kim.apidoc.core.common.helper; +package kim.apidoc.core.common.helper; import com.github.javaparser.ast.body.FieldDeclaration; import com.github.javaparser.ast.expr.AnnotationExpr; diff --git a/apidoc-core/src/main/java/com/kim/apidoc/core/common/markup/MarkupBuilder.java b/apidoc-core/src/main/java/kim/apidoc/core/common/markup/MarkupBuilder.java similarity index 97% rename from apidoc-core/src/main/java/com/kim/apidoc/core/common/markup/MarkupBuilder.java rename to apidoc-core/src/main/java/kim/apidoc/core/common/markup/MarkupBuilder.java index 629ef8f..0dd0a03 100644 --- a/apidoc-core/src/main/java/com/kim/apidoc/core/common/markup/MarkupBuilder.java +++ b/apidoc-core/src/main/java/kim/apidoc/core/common/markup/MarkupBuilder.java @@ -1,6 +1,6 @@ -package com.kim.apidoc.core.common.markup; +package kim.apidoc.core.common.markup; -import com.kim.apidoc.core.common.markup.asciidoc.AsciiDocBuilder; +import kim.apidoc.core.common.markup.asciidoc.AsciiDocBuilder; import java.util.List; import java.util.function.Consumer; diff --git a/apidoc-core/src/main/java/com/kim/apidoc/core/common/markup/asciidoc/AsciiDoc.java b/apidoc-core/src/main/java/kim/apidoc/core/common/markup/asciidoc/AsciiDoc.java similarity index 97% rename from apidoc-core/src/main/java/com/kim/apidoc/core/common/markup/asciidoc/AsciiDoc.java rename to apidoc-core/src/main/java/kim/apidoc/core/common/markup/asciidoc/AsciiDoc.java index c114e5e..18e4ca4 100644 --- a/apidoc-core/src/main/java/com/kim/apidoc/core/common/markup/asciidoc/AsciiDoc.java +++ b/apidoc-core/src/main/java/kim/apidoc/core/common/markup/asciidoc/AsciiDoc.java @@ -1,4 +1,4 @@ -package com.kim.apidoc.core.common.markup.asciidoc; +package kim.apidoc.core.common.markup.asciidoc; public enum AsciiDoc implements CharSequence { EXTENSION(".adoc"), diff --git a/apidoc-core/src/main/java/com/kim/apidoc/core/common/markup/asciidoc/AsciiDocBuilder.java b/apidoc-core/src/main/java/kim/apidoc/core/common/markup/asciidoc/AsciiDocBuilder.java similarity index 98% rename from apidoc-core/src/main/java/com/kim/apidoc/core/common/markup/asciidoc/AsciiDocBuilder.java rename to apidoc-core/src/main/java/kim/apidoc/core/common/markup/asciidoc/AsciiDocBuilder.java index 9642f9a..5d95e67 100644 --- a/apidoc-core/src/main/java/com/kim/apidoc/core/common/markup/asciidoc/AsciiDocBuilder.java +++ b/apidoc-core/src/main/java/kim/apidoc/core/common/markup/asciidoc/AsciiDocBuilder.java @@ -1,7 +1,7 @@ -package com.kim.apidoc.core.common.markup.asciidoc; +package kim.apidoc.core.common.markup.asciidoc; -import com.kim.apidoc.core.common.markup.MarkupBuilder; -import com.kim.apidoc.core.common.Assert; +import kim.apidoc.core.common.Assert; +import kim.apidoc.core.common.markup.MarkupBuilder; import com.google.common.base.Strings; import java.util.List; diff --git a/apidoc-core/src/main/java/com/kim/apidoc/core/common/markup/asciidoc/Color.java b/apidoc-core/src/main/java/kim/apidoc/core/common/markup/asciidoc/Color.java similarity index 94% rename from apidoc-core/src/main/java/com/kim/apidoc/core/common/markup/asciidoc/Color.java rename to apidoc-core/src/main/java/kim/apidoc/core/common/markup/asciidoc/Color.java index b7ca387..301f70e 100644 --- a/apidoc-core/src/main/java/com/kim/apidoc/core/common/markup/asciidoc/Color.java +++ b/apidoc-core/src/main/java/kim/apidoc/core/common/markup/asciidoc/Color.java @@ -1,4 +1,4 @@ -package com.kim.apidoc.core.common.markup.asciidoc; +package kim.apidoc.core.common.markup.asciidoc; /** * https://en.wikipedia.org/wiki/Web_colors#HTML_color_names diff --git a/apidoc-core/src/main/java/com/kim/apidoc/core/common/markup/markdown/Markdown.java b/apidoc-core/src/main/java/kim/apidoc/core/common/markup/markdown/Markdown.java similarity index 96% rename from apidoc-core/src/main/java/com/kim/apidoc/core/common/markup/markdown/Markdown.java rename to apidoc-core/src/main/java/kim/apidoc/core/common/markup/markdown/Markdown.java index 8fdb93f..22f0014 100644 --- a/apidoc-core/src/main/java/com/kim/apidoc/core/common/markup/markdown/Markdown.java +++ b/apidoc-core/src/main/java/kim/apidoc/core/common/markup/markdown/Markdown.java @@ -1,4 +1,4 @@ -package com.kim.apidoc.core.common.markup.markdown; +package kim.apidoc.core.common.markup.markdown; public enum Markdown implements CharSequence { EXTENSION(".md"), diff --git a/apidoc-core/src/main/java/com/kim/apidoc/core/common/markup/markdown/MarkdownBuilder.java b/apidoc-core/src/main/java/kim/apidoc/core/common/markup/markdown/MarkdownBuilder.java similarity index 98% rename from apidoc-core/src/main/java/com/kim/apidoc/core/common/markup/markdown/MarkdownBuilder.java rename to apidoc-core/src/main/java/kim/apidoc/core/common/markup/markdown/MarkdownBuilder.java index 1c80669..2b012d5 100644 --- a/apidoc-core/src/main/java/com/kim/apidoc/core/common/markup/markdown/MarkdownBuilder.java +++ b/apidoc-core/src/main/java/kim/apidoc/core/common/markup/markdown/MarkdownBuilder.java @@ -1,7 +1,7 @@ -package com.kim.apidoc.core.common.markup.markdown; +package kim.apidoc.core.common.markup.markdown; -import com.kim.apidoc.core.common.markup.MarkupBuilder; -import com.kim.apidoc.core.common.Assert; +import kim.apidoc.core.common.Assert; +import kim.apidoc.core.common.markup.MarkupBuilder; import com.google.common.base.Strings; import java.util.List; diff --git a/apidoc-core/src/main/java/com/kim/apidoc/core/common/postman/Body.java b/apidoc-core/src/main/java/kim/apidoc/core/common/postman/Body.java similarity index 86% rename from apidoc-core/src/main/java/com/kim/apidoc/core/common/postman/Body.java rename to apidoc-core/src/main/java/kim/apidoc/core/common/postman/Body.java index b3a32fe..47487e5 100644 --- a/apidoc-core/src/main/java/com/kim/apidoc/core/common/postman/Body.java +++ b/apidoc-core/src/main/java/kim/apidoc/core/common/postman/Body.java @@ -1,4 +1,4 @@ -package com.kim.apidoc.core.common.postman; +package kim.apidoc.core.common.postman; import lombok.Getter; import lombok.Setter; diff --git a/apidoc-core/src/main/java/com/kim/apidoc/core/common/postman/BodyMode.java b/apidoc-core/src/main/java/kim/apidoc/core/common/postman/BodyMode.java similarity index 69% rename from apidoc-core/src/main/java/com/kim/apidoc/core/common/postman/BodyMode.java rename to apidoc-core/src/main/java/kim/apidoc/core/common/postman/BodyMode.java index 3972bd9..7d56b3c 100644 --- a/apidoc-core/src/main/java/com/kim/apidoc/core/common/postman/BodyMode.java +++ b/apidoc-core/src/main/java/kim/apidoc/core/common/postman/BodyMode.java @@ -1,4 +1,4 @@ -package com.kim.apidoc.core.common.postman; +package kim.apidoc.core.common.postman; /** * 对应postman定义的mode diff --git a/apidoc-core/src/main/java/com/kim/apidoc/core/common/postman/Folder.java b/apidoc-core/src/main/java/kim/apidoc/core/common/postman/Folder.java similarity index 87% rename from apidoc-core/src/main/java/com/kim/apidoc/core/common/postman/Folder.java rename to apidoc-core/src/main/java/kim/apidoc/core/common/postman/Folder.java index be112fb..8620ef9 100644 --- a/apidoc-core/src/main/java/com/kim/apidoc/core/common/postman/Folder.java +++ b/apidoc-core/src/main/java/kim/apidoc/core/common/postman/Folder.java @@ -1,4 +1,4 @@ -package com.kim.apidoc.core.common.postman; +package kim.apidoc.core.common.postman; import com.fasterxml.jackson.annotation.JsonInclude; import lombok.Getter; diff --git a/apidoc-core/src/main/java/com/kim/apidoc/core/common/postman/Info.java b/apidoc-core/src/main/java/kim/apidoc/core/common/postman/Info.java similarity index 85% rename from apidoc-core/src/main/java/com/kim/apidoc/core/common/postman/Info.java rename to apidoc-core/src/main/java/kim/apidoc/core/common/postman/Info.java index 32ea847..5fceb85 100644 --- a/apidoc-core/src/main/java/com/kim/apidoc/core/common/postman/Info.java +++ b/apidoc-core/src/main/java/kim/apidoc/core/common/postman/Info.java @@ -1,4 +1,4 @@ -package com.kim.apidoc.core.common.postman; +package kim.apidoc.core.common.postman; import lombok.Getter; import lombok.Setter; diff --git a/apidoc-core/src/main/java/com/kim/apidoc/core/common/postman/Item.java b/apidoc-core/src/main/java/kim/apidoc/core/common/postman/Item.java similarity index 89% rename from apidoc-core/src/main/java/com/kim/apidoc/core/common/postman/Item.java rename to apidoc-core/src/main/java/kim/apidoc/core/common/postman/Item.java index 9cd90f5..4a25b19 100644 --- a/apidoc-core/src/main/java/com/kim/apidoc/core/common/postman/Item.java +++ b/apidoc-core/src/main/java/kim/apidoc/core/common/postman/Item.java @@ -1,4 +1,4 @@ -package com.kim.apidoc.core.common.postman; +package kim.apidoc.core.common.postman; import lombok.Getter; import lombok.Setter; diff --git a/apidoc-core/src/main/java/com/kim/apidoc/core/common/postman/Parameter.java b/apidoc-core/src/main/java/kim/apidoc/core/common/postman/Parameter.java similarity index 85% rename from apidoc-core/src/main/java/com/kim/apidoc/core/common/postman/Parameter.java rename to apidoc-core/src/main/java/kim/apidoc/core/common/postman/Parameter.java index 26f8aaa..5f3baf7 100644 --- a/apidoc-core/src/main/java/com/kim/apidoc/core/common/postman/Parameter.java +++ b/apidoc-core/src/main/java/kim/apidoc/core/common/postman/Parameter.java @@ -1,7 +1,7 @@ -package com.kim.apidoc.core.common.postman; +package kim.apidoc.core.common.postman; -import com.kim.apidoc.core.schema.Row; +import kim.apidoc.core.schema.Row; import lombok.Getter; import lombok.Setter; diff --git a/apidoc-core/src/main/java/com/kim/apidoc/core/common/postman/Postman.java b/apidoc-core/src/main/java/kim/apidoc/core/common/postman/Postman.java similarity index 88% rename from apidoc-core/src/main/java/com/kim/apidoc/core/common/postman/Postman.java rename to apidoc-core/src/main/java/kim/apidoc/core/common/postman/Postman.java index 1d6be5d..549e7a9 100644 --- a/apidoc-core/src/main/java/com/kim/apidoc/core/common/postman/Postman.java +++ b/apidoc-core/src/main/java/kim/apidoc/core/common/postman/Postman.java @@ -1,4 +1,4 @@ -package com.kim.apidoc.core.common.postman; +package kim.apidoc.core.common.postman; import lombok.Getter; import lombok.Setter; diff --git a/apidoc-core/src/main/java/com/kim/apidoc/core/common/postman/Request.java b/apidoc-core/src/main/java/kim/apidoc/core/common/postman/Request.java similarity index 68% rename from apidoc-core/src/main/java/com/kim/apidoc/core/common/postman/Request.java rename to apidoc-core/src/main/java/kim/apidoc/core/common/postman/Request.java index e54cbcb..6ddf403 100644 --- a/apidoc-core/src/main/java/com/kim/apidoc/core/common/postman/Request.java +++ b/apidoc-core/src/main/java/kim/apidoc/core/common/postman/Request.java @@ -1,7 +1,7 @@ -package com.kim.apidoc.core.common.postman; +package kim.apidoc.core.common.postman; -import com.kim.apidoc.core.schema.Header; -import com.kim.apidoc.core.schema.Method; +import kim.apidoc.core.schema.Header; +import kim.apidoc.core.schema.Method; import lombok.Getter; import lombok.Setter; diff --git a/apidoc-core/src/main/java/com/kim/apidoc/core/common/postman/Response.java b/apidoc-core/src/main/java/kim/apidoc/core/common/postman/Response.java similarity index 79% rename from apidoc-core/src/main/java/com/kim/apidoc/core/common/postman/Response.java rename to apidoc-core/src/main/java/kim/apidoc/core/common/postman/Response.java index b8ef739..3854cda 100644 --- a/apidoc-core/src/main/java/com/kim/apidoc/core/common/postman/Response.java +++ b/apidoc-core/src/main/java/kim/apidoc/core/common/postman/Response.java @@ -1,6 +1,6 @@ -package com.kim.apidoc.core.common.postman; +package kim.apidoc.core.common.postman; -import com.kim.apidoc.core.schema.Header; +import kim.apidoc.core.schema.Header; import lombok.Getter; import lombok.Setter; diff --git a/apidoc-core/src/main/java/com/kim/apidoc/core/common/postman/Url.java b/apidoc-core/src/main/java/kim/apidoc/core/common/postman/Url.java similarity index 86% rename from apidoc-core/src/main/java/com/kim/apidoc/core/common/postman/Url.java rename to apidoc-core/src/main/java/kim/apidoc/core/common/postman/Url.java index 3cb84e0..5fc565d 100644 --- a/apidoc-core/src/main/java/com/kim/apidoc/core/common/postman/Url.java +++ b/apidoc-core/src/main/java/kim/apidoc/core/common/postman/Url.java @@ -1,4 +1,4 @@ -package com.kim.apidoc.core.common.postman; +package kim.apidoc.core.common.postman; import lombok.Getter; import lombok.Setter; diff --git a/apidoc-core/src/main/java/com/kim/apidoc/core/parser/ParserStrategy.java b/apidoc-core/src/main/java/kim/apidoc/core/parser/ParserStrategy.java similarity index 89% rename from apidoc-core/src/main/java/com/kim/apidoc/core/parser/ParserStrategy.java rename to apidoc-core/src/main/java/kim/apidoc/core/parser/ParserStrategy.java index f7e3331..699a3a0 100644 --- a/apidoc-core/src/main/java/com/kim/apidoc/core/parser/ParserStrategy.java +++ b/apidoc-core/src/main/java/kim/apidoc/core/parser/ParserStrategy.java @@ -1,7 +1,7 @@ -package com.kim.apidoc.core.parser; +package kim.apidoc.core.parser; -import com.kim.apidoc.core.schema.Chapter; -import com.kim.apidoc.core.schema.Section; +import kim.apidoc.core.schema.Chapter; +import kim.apidoc.core.schema.Section; import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; import com.github.javaparser.ast.body.MethodDeclaration; diff --git a/apidoc-core/src/main/java/kim/apidoc/core/parser/VisitorParser.java b/apidoc-core/src/main/java/kim/apidoc/core/parser/VisitorParser.java new file mode 100644 index 0000000..8567ecc --- /dev/null +++ b/apidoc-core/src/main/java/kim/apidoc/core/parser/VisitorParser.java @@ -0,0 +1,77 @@ +package kim.apidoc.core.parser; + +import kim.apidoc.core.common.helper.OptionalHelper; +import kim.apidoc.core.schema.Chapter; +import kim.apidoc.core.schema.Node; +import kim.apidoc.core.schema.Project; +import kim.apidoc.core.schema.Section; +import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; +import com.github.javaparser.ast.body.MethodDeclaration; +import com.github.javaparser.ast.visitor.VoidVisitorAdapter; + +/** + * The type Visitor parser. + */ +public class VisitorParser extends VoidVisitorAdapter { + + /** + * The Parser strategy. + */ + private ParserStrategy parserStrategy; + + /** + * Sets parser strategy. + * + * @param parserStrategy the parser strategy + */ + public void setParserStrategy(ParserStrategy parserStrategy) { + this.parserStrategy = parserStrategy; + } + + /** + * 类或者接口声明 + * @param classOrInterfaceDeclaration + * @param arg + */ + @Override + public void visit(final ClassOrInterfaceDeclaration classOrInterfaceDeclaration, final Node arg) { + + if (arg instanceof Project && parserStrategy.accept(classOrInterfaceDeclaration)) { + Project project = (Project) arg; + // 章节 + Chapter chapter = new Chapter(); + classOrInterfaceDeclaration.getFullyQualifiedName().ifPresent(chapter::setId); + chapter.setName(classOrInterfaceDeclaration.getNameAsString()); + classOrInterfaceDeclaration.getComment().ifPresent(chapter::accept); + + OptionalHelper.any(chapter.getTag("book"),chapter.getTag("group")) + .ifPresent(tag -> chapter.setBookName(tag.getContent())); + + parserStrategy.visit(classOrInterfaceDeclaration, chapter); + project.addChapter(chapter); + super.visit(classOrInterfaceDeclaration, chapter); + } + } + + /** + * 方法声明 + * @param methodDeclaration + * @param arg + */ + @Override + public void visit(final MethodDeclaration methodDeclaration, final Node arg) { + if (arg instanceof Chapter && parserStrategy.accept(methodDeclaration)) { + Chapter chapter = (Chapter) arg; + Section section = new Section(); + section.setId(methodDeclaration.getNameAsString()); + section.setName(methodDeclaration.getNameAsString()); + section.setIndex(chapter.getSections().size()); + methodDeclaration.getComment().ifPresent(section::accept); + + parserStrategy.visit(methodDeclaration, chapter, section); + chapter.getSections().add(section); + super.visit(methodDeclaration, section); + } + } + +} diff --git a/apidoc-core/src/main/java/com/kim/apidoc/core/render/AsciiDocRender.java b/apidoc-core/src/main/java/kim/apidoc/core/render/AsciiDocRender.java similarity index 90% rename from apidoc-core/src/main/java/com/kim/apidoc/core/render/AsciiDocRender.java rename to apidoc-core/src/main/java/kim/apidoc/core/render/AsciiDocRender.java index 491dc2e..c1e7b24 100644 --- a/apidoc-core/src/main/java/com/kim/apidoc/core/render/AsciiDocRender.java +++ b/apidoc-core/src/main/java/kim/apidoc/core/render/AsciiDocRender.java @@ -1,12 +1,12 @@ -package com.kim.apidoc.core.render; +package kim.apidoc.core.render; +import kim.apidoc.core.ApiDoc; +import kim.apidoc.core.common.helper.FileHelper; +import kim.apidoc.core.common.helper.StringHelper; +import kim.apidoc.core.common.markup.MarkupBuilder; +import kim.apidoc.core.common.markup.asciidoc.AsciiDoc; import com.google.common.collect.Lists; -import com.kim.apidoc.core.ApiDoc; -import com.kim.apidoc.core.common.helper.FileHelper; -import com.kim.apidoc.core.common.helper.StringHelper; -import com.kim.apidoc.core.common.markup.MarkupBuilder; -import com.kim.apidoc.core.common.markup.asciidoc.AsciiDoc; -import com.kim.apidoc.core.schema.*; +import kim.apidoc.core.schema.*; import lombok.extern.slf4j.Slf4j; import org.asciidoctor.Asciidoctor; import org.asciidoctor.AttributesBuilder; @@ -46,7 +46,7 @@ public class AsciiDocRender implements ProjectRender { project.getBooks().forEach((name, book) -> { MarkupBuilder builder = MarkupBuilder.getInstance(); String displayName = project.getName(); - if (!Objects.equals(Book.DEFAULT, name)) { + if(!Objects.equals(Book.DEFAULT, name)){ displayName += " - " + name; } builder.header(displayName, attrs); @@ -61,7 +61,7 @@ public class AsciiDocRender implements ProjectRender { builder.title(1, chapter.getName()); builder.paragraph(chapter.getDescription()); for (Section section : chapter.getSections()) { - if (section.isIgnore()) { + if(section.isIgnore()){ continue; } builder.title(2, section.getName()); @@ -71,7 +71,7 @@ public class AsciiDocRender implements ProjectRender { builder.title(4, "request"); builder.listing(b -> { b.textLine(section.getRequestLine()); - section.getInHeaders().values().forEach(header -> builder.textLine(header.toString())); + section.getInHeaders().values().forEach(header->builder.textLine(header.toString())); if (section.hasRequestBody()) { b.br(); b.text(section.getParameterString()); @@ -87,7 +87,7 @@ public class AsciiDocRender implements ProjectRender { if (section.hasResponseBody()) { b.br(); b.text(section.getResponseString()); - } else { + }else{ b.text("N/A"); } }, "source,JSON"); diff --git a/apidoc-core/src/main/java/kim/apidoc/core/render/MarkdownRender.java b/apidoc-core/src/main/java/kim/apidoc/core/render/MarkdownRender.java new file mode 100644 index 0000000..739d24a --- /dev/null +++ b/apidoc-core/src/main/java/kim/apidoc/core/render/MarkdownRender.java @@ -0,0 +1,18 @@ +package kim.apidoc.core.render; + +import kim.apidoc.core.schema.Project; + +/** + * 生成markdown api文档 + * + * @author duanledexianxianxian + * @version 1.0.0 + * @date 2020 /3/26 19:03 + * @since 1.0.0 + */ +public class MarkdownRender implements ProjectRender { + @Override + public void render(Project project) { + + } +} diff --git a/apidoc-core/src/main/java/com/kim/apidoc/core/render/PostmanRender.java b/apidoc-core/src/main/java/kim/apidoc/core/render/PostmanRender.java similarity index 83% rename from apidoc-core/src/main/java/com/kim/apidoc/core/render/PostmanRender.java rename to apidoc-core/src/main/java/kim/apidoc/core/render/PostmanRender.java index 325add5..1afe2df 100644 --- a/apidoc-core/src/main/java/com/kim/apidoc/core/render/PostmanRender.java +++ b/apidoc-core/src/main/java/kim/apidoc/core/render/PostmanRender.java @@ -1,11 +1,11 @@ -package com.kim.apidoc.core.render; +package kim.apidoc.core.render; import com.fasterxml.jackson.databind.node.ObjectNode; -import com.kim.apidoc.core.ApiDoc; -import com.kim.apidoc.core.common.ObjectMappers; -import com.kim.apidoc.core.common.helper.FileHelper; -import com.kim.apidoc.core.common.postman.*; -import com.kim.apidoc.core.schema.*; +import kim.apidoc.core.ApiDoc; +import kim.apidoc.core.common.ObjectMappers; +import kim.apidoc.core.common.helper.FileHelper; +import kim.apidoc.core.common.postman.*; +import kim.apidoc.core.schema.*; import lombok.extern.slf4j.Slf4j; import java.nio.file.Path; @@ -38,14 +38,14 @@ public class PostmanRender implements ProjectRender { Folder folder = new Folder(); folder.setName(book.getId()); for (Chapter chapter : book.getChapters()) { - if (chapter.isIgnore() || chapter.getSections().isEmpty()) { + if(chapter.isIgnore() || chapter.getSections().isEmpty()){ continue; } Folder chapterFolder = new Folder(); chapterFolder.setName(chapter.getName()); chapterFolder.setDescription(chapter.getDescription()); for (Section section : chapter.getSections()) { - if (section.isIgnore()) { + if(section.isIgnore()){ continue; } chapterFolder.getItem().add(build(section)); @@ -55,7 +55,7 @@ public class PostmanRender implements ProjectRender { postman.getItem().add(folder); } - if (postman.getItem().size() == 1) { + if(postman.getItem().size()==1){ Folder folder = postman.getItem().get(0); postman.setItem(folder.getItem()); } @@ -74,18 +74,18 @@ public class PostmanRender implements ProjectRender { request.setMethod(section.getMethod()); request.getHeaders().addAll(section.getInHeaders().values()); - if (section.isQueryParameter()) { - if (Method.GET.equals(request.getMethod())) { - ObjectNode objectNode = (ObjectNode) section.getParameter(); + if(section.isQueryParameter()){ + if(Method.GET.equals(request.getMethod())){ + ObjectNode objectNode = (ObjectNode)section.getParameter(); for (String key : section.getRequestRows().keySet()) { if (objectNode.has(key)) { Row row = section.getRequestRows().get(key); request.getUrl().getQuery().add(Parameter.of(row)); } } - } else { + }else{ request.getBody().setMode(BodyMode.urlencoded); - ObjectNode objectNode = (ObjectNode) section.getParameter(); + ObjectNode objectNode = (ObjectNode)section.getParameter(); for (String key : section.getRequestRows().keySet()) { if (objectNode.has(key)) { Row row = section.getRequestRows().get(key); @@ -93,7 +93,7 @@ public class PostmanRender implements ProjectRender { } } } - } else { + }else{ request.getBody().setMode(BodyMode.raw); request.getBody().setRaw(section.getParameterString()); } diff --git a/apidoc-core/src/main/java/com/kim/apidoc/core/render/ProjectRender.java b/apidoc-core/src/main/java/kim/apidoc/core/render/ProjectRender.java similarity index 72% rename from apidoc-core/src/main/java/com/kim/apidoc/core/render/ProjectRender.java rename to apidoc-core/src/main/java/kim/apidoc/core/render/ProjectRender.java index c2c3661..2e12666 100644 --- a/apidoc-core/src/main/java/com/kim/apidoc/core/render/ProjectRender.java +++ b/apidoc-core/src/main/java/kim/apidoc/core/render/ProjectRender.java @@ -1,6 +1,6 @@ -package com.kim.apidoc.core.render; +package kim.apidoc.core.render; -import com.kim.apidoc.core.schema.Project; +import kim.apidoc.core.schema.Project; /** * The interface Project render. diff --git a/apidoc-core/src/main/java/com/kim/apidoc/core/resolver/ArrayTypeResolver.java b/apidoc-core/src/main/java/kim/apidoc/core/resolver/ArrayTypeResolver.java similarity index 67% rename from apidoc-core/src/main/java/com/kim/apidoc/core/resolver/ArrayTypeResolver.java rename to apidoc-core/src/main/java/kim/apidoc/core/resolver/ArrayTypeResolver.java index 76f2296..db9e2c6 100644 --- a/apidoc-core/src/main/java/com/kim/apidoc/core/resolver/ArrayTypeResolver.java +++ b/apidoc-core/src/main/java/kim/apidoc/core/resolver/ArrayTypeResolver.java @@ -1,8 +1,8 @@ -package com.kim.apidoc.core.resolver; +package kim.apidoc.core.resolver; -import com.kim.apidoc.core.ApiDoc; -import com.kim.apidoc.core.common.description.TypeDescription; -import com.kim.apidoc.core.common.description.ArrayTypeDescription; +import kim.apidoc.core.ApiDoc; +import kim.apidoc.core.common.description.TypeDescription; +import kim.apidoc.core.common.description.ArrayTypeDescription; import com.github.javaparser.resolution.types.ResolvedType; public class ArrayTypeResolver implements TypeResolver { diff --git a/apidoc-core/src/main/java/com/kim/apidoc/core/resolver/CollectionTypeResolver.java b/apidoc-core/src/main/java/kim/apidoc/core/resolver/CollectionTypeResolver.java similarity index 78% rename from apidoc-core/src/main/java/com/kim/apidoc/core/resolver/CollectionTypeResolver.java rename to apidoc-core/src/main/java/kim/apidoc/core/resolver/CollectionTypeResolver.java index f08cc10..89e6356 100644 --- a/apidoc-core/src/main/java/com/kim/apidoc/core/resolver/CollectionTypeResolver.java +++ b/apidoc-core/src/main/java/kim/apidoc/core/resolver/CollectionTypeResolver.java @@ -1,10 +1,10 @@ -package com.kim.apidoc.core.resolver; +package kim.apidoc.core.resolver; -import com.kim.apidoc.core.ApiDoc; -import com.kim.apidoc.core.common.helper.TypeParameterHelper; -import com.kim.apidoc.core.common.description.ArrayTypeDescription; -import com.kim.apidoc.core.common.description.TypeDescription; -import com.kim.apidoc.core.common.description.UnAvailableTypeDescription; +import kim.apidoc.core.ApiDoc; +import kim.apidoc.core.common.helper.TypeParameterHelper; +import kim.apidoc.core.common.description.ArrayTypeDescription; +import kim.apidoc.core.common.description.TypeDescription; +import kim.apidoc.core.common.description.UnAvailableTypeDescription; import com.github.javaparser.resolution.types.ResolvedType; import com.google.common.collect.ImmutableList; diff --git a/apidoc-core/src/main/java/com/kim/apidoc/core/resolver/DateTypeResolver.java b/apidoc-core/src/main/java/kim/apidoc/core/resolver/DateTypeResolver.java similarity index 83% rename from apidoc-core/src/main/java/com/kim/apidoc/core/resolver/DateTypeResolver.java rename to apidoc-core/src/main/java/kim/apidoc/core/resolver/DateTypeResolver.java index 9c9f20d..b163b84 100644 --- a/apidoc-core/src/main/java/com/kim/apidoc/core/resolver/DateTypeResolver.java +++ b/apidoc-core/src/main/java/kim/apidoc/core/resolver/DateTypeResolver.java @@ -1,7 +1,7 @@ -package com.kim.apidoc.core.resolver; +package kim.apidoc.core.resolver; -import com.kim.apidoc.core.common.description.TypeDescription; -import com.kim.apidoc.core.common.description.StringTypeDescription; +import kim.apidoc.core.common.description.TypeDescription; +import kim.apidoc.core.common.description.StringTypeDescription; import com.github.javaparser.resolution.types.ResolvedType; import com.google.common.collect.ImmutableList; diff --git a/apidoc-core/src/main/java/com/kim/apidoc/core/resolver/EnumTypeResolver.java b/apidoc-core/src/main/java/kim/apidoc/core/resolver/EnumTypeResolver.java similarity index 84% rename from apidoc-core/src/main/java/com/kim/apidoc/core/resolver/EnumTypeResolver.java rename to apidoc-core/src/main/java/kim/apidoc/core/resolver/EnumTypeResolver.java index 306f27c..6138033 100644 --- a/apidoc-core/src/main/java/com/kim/apidoc/core/resolver/EnumTypeResolver.java +++ b/apidoc-core/src/main/java/kim/apidoc/core/resolver/EnumTypeResolver.java @@ -1,7 +1,7 @@ -package com.kim.apidoc.core.resolver; +package kim.apidoc.core.resolver; -import com.kim.apidoc.core.common.description.StringTypeDescription; -import com.kim.apidoc.core.common.description.TypeDescription; +import kim.apidoc.core.common.description.StringTypeDescription; +import kim.apidoc.core.common.description.TypeDescription; import com.github.javaparser.resolution.declarations.ResolvedEnumConstantDeclaration; import com.github.javaparser.resolution.declarations.ResolvedEnumDeclaration; import com.github.javaparser.resolution.types.ResolvedType; diff --git a/apidoc-core/src/main/java/com/kim/apidoc/core/resolver/MapTypeResolver.java b/apidoc-core/src/main/java/kim/apidoc/core/resolver/MapTypeResolver.java similarity index 84% rename from apidoc-core/src/main/java/com/kim/apidoc/core/resolver/MapTypeResolver.java rename to apidoc-core/src/main/java/kim/apidoc/core/resolver/MapTypeResolver.java index 8118dab..9cba7e1 100644 --- a/apidoc-core/src/main/java/com/kim/apidoc/core/resolver/MapTypeResolver.java +++ b/apidoc-core/src/main/java/kim/apidoc/core/resolver/MapTypeResolver.java @@ -1,7 +1,7 @@ -package com.kim.apidoc.core.resolver; +package kim.apidoc.core.resolver; -import com.kim.apidoc.core.common.description.TypeDescription; -import com.kim.apidoc.core.common.description.UnAvailableTypeDescription; +import kim.apidoc.core.common.description.TypeDescription; +import kim.apidoc.core.common.description.UnAvailableTypeDescription; import com.github.javaparser.resolution.types.ResolvedType; import com.google.common.collect.ImmutableList; diff --git a/apidoc-core/src/main/java/com/kim/apidoc/core/resolver/ObjectTypeResolver.java b/apidoc-core/src/main/java/kim/apidoc/core/resolver/ObjectTypeResolver.java similarity index 73% rename from apidoc-core/src/main/java/com/kim/apidoc/core/resolver/ObjectTypeResolver.java rename to apidoc-core/src/main/java/kim/apidoc/core/resolver/ObjectTypeResolver.java index 8a9bf37..b9302f9 100644 --- a/apidoc-core/src/main/java/com/kim/apidoc/core/resolver/ObjectTypeResolver.java +++ b/apidoc-core/src/main/java/kim/apidoc/core/resolver/ObjectTypeResolver.java @@ -1,13 +1,12 @@ -package com.kim.apidoc.core.resolver; +package kim.apidoc.core.resolver; import com.github.javaparser.resolution.declarations.ResolvedFieldDeclaration; import com.github.javaparser.resolution.types.ResolvedReferenceType; import com.github.javaparser.resolution.types.ResolvedType; -import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserClassDeclaration; -import com.kim.apidoc.core.ApiDoc; -import com.kim.apidoc.core.common.description.ObjectTypeDescription; -import com.kim.apidoc.core.common.description.TypeDescription; -import com.kim.apidoc.core.common.helper.*; +import kim.apidoc.core.ApiDoc; +import kim.apidoc.core.common.description.ObjectTypeDescription; +import kim.apidoc.core.common.description.TypeDescription; +import kim.apidoc.core.common.helper.*; import java.util.Optional; @@ -28,16 +27,15 @@ public class ObjectTypeResolver implements TypeResolver { ObjectTypeDescription typeDescription = new ObjectTypeDescription(); typeDescription.setType(referenceType.getTypeDeclaration().getName()); - ((JavaParserClassDeclaration) referenceType.getTypeDeclaration()).getWrappedNode().getComment().ifPresent(typeDescription::accept); //类型解析缓冲池,防止循环引用 - if (!ReferenceContext.getInstance().push(referenceType.describe())) { + if(!ReferenceContext.getInstance().push(referenceType.describe())){ return typeDescription; } //解析父类属性,并合并至当前 for (ResolvedReferenceType directAncestor : referenceType.getDirectAncestors()) { TypeDescription ancestorDescription = ApiDoc.getInstance().getTypeResolvers().resolve(directAncestor); - if (ancestorDescription.isAvailable() && ancestorDescription.isObject()) { + if(ancestorDescription.isAvailable() && ancestorDescription.isObject()){ typeDescription.merge(ancestorDescription.asObject()); } } @@ -45,19 +43,19 @@ public class ObjectTypeResolver implements TypeResolver { //TODO fix use access method for (ResolvedFieldDeclaration declaredField : referenceType.getTypeDeclaration().getDeclaredFields()) { - if (declaredField.isStatic()) { + if(declaredField.isStatic()){ continue; } ResolvedType fieldType = declaredField.getType(); - if (fieldType.isReferenceType()) { + if(fieldType.isReferenceType()){ //将父类的T,传递给 属性的T - fieldType = TypeParameterHelper.useClassTypeParameter(referenceType, fieldType.asReferenceType()); + fieldType = TypeParameterHelper.useClassTypeParameter(referenceType,fieldType.asReferenceType()); } - if (declaredField.getType().isTypeVariable()) { + if(declaredField.getType().isTypeVariable()){ //类型为T,这种泛型 Optional optional = TypeParameterHelper.getTypeParameter(referenceType, declaredField.getType().asTypeParameter().getName()); - if (optional.isPresent()) { + if(optional.isPresent()){ fieldType = optional.get(); } } @@ -73,7 +71,7 @@ public class ObjectTypeResolver implements TypeResolver { fieldDescription.getCondition().append(validation).append(" "); } //查找字段初始化值 - FieldHelper.getInitializer(declaredField).ifPresent(expr -> fieldDescription.setDefaultValue(ExpressionHelper.getValue(expr))); + FieldHelper.getInitializer(declaredField).ifPresent(expr-> fieldDescription.setDefaultValue(ExpressionHelper.getValue(expr))); typeDescription.add(fieldDescription); } diff --git a/apidoc-core/src/main/java/com/kim/apidoc/core/resolver/PrimitiveTypeResolver.java b/apidoc-core/src/main/java/kim/apidoc/core/resolver/PrimitiveTypeResolver.java similarity index 75% rename from apidoc-core/src/main/java/com/kim/apidoc/core/resolver/PrimitiveTypeResolver.java rename to apidoc-core/src/main/java/kim/apidoc/core/resolver/PrimitiveTypeResolver.java index fde1fe2..cdd456b 100644 --- a/apidoc-core/src/main/java/com/kim/apidoc/core/resolver/PrimitiveTypeResolver.java +++ b/apidoc-core/src/main/java/kim/apidoc/core/resolver/PrimitiveTypeResolver.java @@ -1,13 +1,27 @@ -package com.kim.apidoc.core.resolver; +package kim.apidoc.core.resolver; -import com.kim.apidoc.core.common.description.PrimitiveTypeDescription; -import com.kim.apidoc.core.common.description.TypeDescription; +import kim.apidoc.core.common.description.PrimitiveTypeDescription; +import kim.apidoc.core.common.description.TypeDescription; import com.github.javaparser.resolution.types.ResolvedType; import com.google.common.collect.ImmutableList; public class PrimitiveTypeResolver implements TypeResolver { - private static boolean isBoxing(ResolvedType type) { - if (!type.isReferenceType()) { + @Override + public boolean accept(ResolvedType type) { + return type.isPrimitive() || isBoxing(type); + } + + @Override + public TypeDescription resolve(ResolvedType type) { + if(type.isPrimitive()){ + return new PrimitiveTypeDescription(type.asPrimitive()); + }else{ + return new PrimitiveTypeDescription(type.asReferenceType()); + } + } + + private static boolean isBoxing(ResolvedType type){ + if(!type.isReferenceType()){ return false; } String id = type.asReferenceType().getId(); @@ -23,18 +37,4 @@ public class PrimitiveTypeResolver implements TypeResolver { ).contains(id); } - @Override - public boolean accept(ResolvedType type) { - return type.isPrimitive() || isBoxing(type); - } - - @Override - public TypeDescription resolve(ResolvedType type) { - if (type.isPrimitive()) { - return new PrimitiveTypeDescription(type.asPrimitive()); - } else { - return new PrimitiveTypeDescription(type.asReferenceType()); - } - } - } diff --git a/apidoc-core/src/main/java/com/kim/apidoc/core/resolver/StringTypeResolver.java b/apidoc-core/src/main/java/kim/apidoc/core/resolver/StringTypeResolver.java similarity index 81% rename from apidoc-core/src/main/java/com/kim/apidoc/core/resolver/StringTypeResolver.java rename to apidoc-core/src/main/java/kim/apidoc/core/resolver/StringTypeResolver.java index 2954444..b2942c4 100644 --- a/apidoc-core/src/main/java/com/kim/apidoc/core/resolver/StringTypeResolver.java +++ b/apidoc-core/src/main/java/kim/apidoc/core/resolver/StringTypeResolver.java @@ -1,7 +1,7 @@ -package com.kim.apidoc.core.resolver; +package kim.apidoc.core.resolver; -import com.kim.apidoc.core.common.description.TypeDescription; -import com.kim.apidoc.core.common.description.StringTypeDescription; +import kim.apidoc.core.common.description.TypeDescription; +import kim.apidoc.core.common.description.StringTypeDescription; import com.github.javaparser.resolution.types.ResolvedType; import com.google.common.collect.ImmutableList; diff --git a/apidoc-core/src/main/java/com/kim/apidoc/core/resolver/SystemObjectTypeResolver.java b/apidoc-core/src/main/java/kim/apidoc/core/resolver/SystemObjectTypeResolver.java similarity index 79% rename from apidoc-core/src/main/java/com/kim/apidoc/core/resolver/SystemObjectTypeResolver.java rename to apidoc-core/src/main/java/kim/apidoc/core/resolver/SystemObjectTypeResolver.java index da8ffb3..5fe5e56 100644 --- a/apidoc-core/src/main/java/com/kim/apidoc/core/resolver/SystemObjectTypeResolver.java +++ b/apidoc-core/src/main/java/kim/apidoc/core/resolver/SystemObjectTypeResolver.java @@ -1,7 +1,7 @@ -package com.kim.apidoc.core.resolver; +package kim.apidoc.core.resolver; -import com.kim.apidoc.core.common.description.TypeDescription; -import com.kim.apidoc.core.common.description.UnAvailableTypeDescription; +import kim.apidoc.core.common.description.TypeDescription; +import kim.apidoc.core.common.description.UnAvailableTypeDescription; import com.github.javaparser.resolution.types.ResolvedType; public class SystemObjectTypeResolver implements TypeResolver { diff --git a/apidoc-core/src/main/java/com/kim/apidoc/core/resolver/TypeNameResolver.java b/apidoc-core/src/main/java/kim/apidoc/core/resolver/TypeNameResolver.java similarity index 61% rename from apidoc-core/src/main/java/com/kim/apidoc/core/resolver/TypeNameResolver.java rename to apidoc-core/src/main/java/kim/apidoc/core/resolver/TypeNameResolver.java index 92efd8e..7a12503 100644 --- a/apidoc-core/src/main/java/com/kim/apidoc/core/resolver/TypeNameResolver.java +++ b/apidoc-core/src/main/java/kim/apidoc/core/resolver/TypeNameResolver.java @@ -1,6 +1,6 @@ -package com.kim.apidoc.core.resolver; +package kim.apidoc.core.resolver; -import com.kim.apidoc.core.common.description.TypeDescription; +import kim.apidoc.core.common.description.TypeDescription; import com.github.javaparser.ast.type.Type; public interface TypeNameResolver { diff --git a/apidoc-core/src/main/java/com/kim/apidoc/core/resolver/TypeResolver.java b/apidoc-core/src/main/java/kim/apidoc/core/resolver/TypeResolver.java similarity index 64% rename from apidoc-core/src/main/java/com/kim/apidoc/core/resolver/TypeResolver.java rename to apidoc-core/src/main/java/kim/apidoc/core/resolver/TypeResolver.java index 3d9a3c7..469a691 100644 --- a/apidoc-core/src/main/java/com/kim/apidoc/core/resolver/TypeResolver.java +++ b/apidoc-core/src/main/java/kim/apidoc/core/resolver/TypeResolver.java @@ -1,6 +1,6 @@ -package com.kim.apidoc.core.resolver; +package kim.apidoc.core.resolver; -import com.kim.apidoc.core.common.description.TypeDescription; +import kim.apidoc.core.common.description.TypeDescription; import com.github.javaparser.resolution.types.ResolvedType; public interface TypeResolver { diff --git a/apidoc-core/src/main/java/com/kim/apidoc/core/resolver/TypeResolvers.java b/apidoc-core/src/main/java/kim/apidoc/core/resolver/TypeResolvers.java similarity index 70% rename from apidoc-core/src/main/java/com/kim/apidoc/core/resolver/TypeResolvers.java rename to apidoc-core/src/main/java/kim/apidoc/core/resolver/TypeResolvers.java index 4858478..fc8a6b1 100644 --- a/apidoc-core/src/main/java/com/kim/apidoc/core/resolver/TypeResolvers.java +++ b/apidoc-core/src/main/java/kim/apidoc/core/resolver/TypeResolvers.java @@ -1,8 +1,8 @@ -package com.kim.apidoc.core.resolver; +package kim.apidoc.core.resolver; -import com.kim.apidoc.core.common.description.TypeDescription; -import com.kim.apidoc.core.common.helper.TypeNameHelper; -import com.kim.apidoc.core.common.description.UnAvailableTypeDescription; +import kim.apidoc.core.common.description.TypeDescription; +import kim.apidoc.core.common.helper.TypeNameHelper; +import kim.apidoc.core.common.description.UnAvailableTypeDescription; import com.github.javaparser.ast.type.Type; import com.github.javaparser.resolution.UnsolvedSymbolException; import com.github.javaparser.resolution.types.ResolvedType; @@ -34,57 +34,55 @@ public class TypeResolvers { /** * 获取类型信息 - * * @param type * @return */ - public TypeDescription resolve(Type type) { - try { + public TypeDescription resolve(Type type){ + try{ ResolvedType resolvedType = type.resolve(); return resolve(resolvedType); - } catch (UnsolvedSymbolException e) { + } catch (UnsolvedSymbolException e){ //解析失败时,尝试降级,使用名称解析 return nameResolve(type); - } catch (Exception e) { - log.error(e.getMessage(), e); + } catch (Exception e){ + log.error(e.getMessage(),e); } return new UnAvailableTypeDescription(); } /** * 解析类型信息 - * * @param type * @return */ - public TypeDescription resolve(ResolvedType type) { + public TypeDescription resolve(ResolvedType type){ for (TypeResolver typeResolver : resolvers) { - if (typeResolver.accept(type)) { + if(typeResolver.accept(type)){ return typeResolver.resolve(type); } } - if (objectTypeResolver.accept(type)) { + if(objectTypeResolver.accept(type)){ return objectTypeResolver.resolve(type); } return new UnAvailableTypeDescription(); } - public TypeDescription nameResolve(Type type) { + public TypeDescription nameResolve(Type type){ String id = TypeNameHelper.getName(type); for (TypeNameResolver nameResolver : nameResolvers) { if (nameResolver.accept(id)) { return nameResolver.resolve(type); } } - log.warn("type({}) resolve failed", id); + log.warn("type({}) resolve failed",id); return new UnAvailableTypeDescription(); } - public void addResolver(TypeResolver typeResolver) { + public void addResolver(TypeResolver typeResolver){ resolvers.add(typeResolver); } - public void addNameResolver(TypeNameResolver nameResolver) { + public void addNameResolver(TypeNameResolver nameResolver){ nameResolvers.add(nameResolver); } diff --git a/apidoc-core/src/main/java/com/kim/apidoc/core/schema/Book.java b/apidoc-core/src/main/java/kim/apidoc/core/schema/Book.java similarity index 93% rename from apidoc-core/src/main/java/com/kim/apidoc/core/schema/Book.java rename to apidoc-core/src/main/java/kim/apidoc/core/schema/Book.java index dfd2da2..99b9edd 100644 --- a/apidoc-core/src/main/java/com/kim/apidoc/core/schema/Book.java +++ b/apidoc-core/src/main/java/kim/apidoc/core/schema/Book.java @@ -1,4 +1,4 @@ -package com.kim.apidoc.core.schema; +package kim.apidoc.core.schema; import lombok.Getter; import lombok.Setter; diff --git a/apidoc-core/src/main/java/com/kim/apidoc/core/schema/Chapter.java b/apidoc-core/src/main/java/kim/apidoc/core/schema/Chapter.java similarity index 87% rename from apidoc-core/src/main/java/com/kim/apidoc/core/schema/Chapter.java rename to apidoc-core/src/main/java/kim/apidoc/core/schema/Chapter.java index 99b7e64..59e699d 100644 --- a/apidoc-core/src/main/java/com/kim/apidoc/core/schema/Chapter.java +++ b/apidoc-core/src/main/java/kim/apidoc/core/schema/Chapter.java @@ -1,4 +1,4 @@ -package com.kim.apidoc.core.schema; +package kim.apidoc.core.schema; import lombok.Getter; import lombok.Setter; @@ -15,13 +15,12 @@ import java.util.TreeSet; @Setter @Getter public class Chapter extends Node { + /** * The Book name. */ String bookName; - Project project; - /** * The Sections. */ diff --git a/apidoc-core/src/main/java/com/kim/apidoc/core/schema/Header.java b/apidoc-core/src/main/java/kim/apidoc/core/schema/Header.java similarity index 97% rename from apidoc-core/src/main/java/com/kim/apidoc/core/schema/Header.java rename to apidoc-core/src/main/java/kim/apidoc/core/schema/Header.java index cd99d64..962f0f2 100644 --- a/apidoc-core/src/main/java/com/kim/apidoc/core/schema/Header.java +++ b/apidoc-core/src/main/java/kim/apidoc/core/schema/Header.java @@ -1,4 +1,4 @@ -package com.kim.apidoc.core.schema; +package kim.apidoc.core.schema; import lombok.Getter; import lombok.NoArgsConstructor; diff --git a/apidoc-core/src/main/java/com/kim/apidoc/core/schema/Method.java b/apidoc-core/src/main/java/kim/apidoc/core/schema/Method.java similarity index 96% rename from apidoc-core/src/main/java/com/kim/apidoc/core/schema/Method.java rename to apidoc-core/src/main/java/kim/apidoc/core/schema/Method.java index 31c09d7..4cf18f6 100644 --- a/apidoc-core/src/main/java/com/kim/apidoc/core/schema/Method.java +++ b/apidoc-core/src/main/java/kim/apidoc/core/schema/Method.java @@ -1,4 +1,4 @@ -package com.kim.apidoc.core.schema; +package kim.apidoc.core.schema; import lombok.extern.slf4j.Slf4j; diff --git a/apidoc-core/src/main/java/com/kim/apidoc/core/schema/Node.java b/apidoc-core/src/main/java/kim/apidoc/core/schema/Node.java similarity index 87% rename from apidoc-core/src/main/java/com/kim/apidoc/core/schema/Node.java rename to apidoc-core/src/main/java/kim/apidoc/core/schema/Node.java index 63d628c..0abf6c1 100644 --- a/apidoc-core/src/main/java/com/kim/apidoc/core/schema/Node.java +++ b/apidoc-core/src/main/java/kim/apidoc/core/schema/Node.java @@ -1,10 +1,10 @@ -package com.kim.apidoc.core.schema; +package kim.apidoc.core.schema; +import kim.apidoc.core.Context; +import kim.apidoc.core.common.helper.CommentHelper; +import kim.apidoc.core.common.helper.StringHelper; import com.github.javaparser.ast.comments.Comment; import com.github.javaparser.javadoc.Javadoc; -import com.kim.apidoc.core.Context; -import com.kim.apidoc.core.common.helper.CommentHelper; -import com.kim.apidoc.core.common.helper.StringHelper; import lombok.Getter; import lombok.Setter; @@ -22,10 +22,7 @@ import java.util.Optional; @Setter @Getter public class Node implements Comparable { - /** - * 节点类型 - */ - String type; + /** * 节点编号 */ @@ -55,9 +52,6 @@ public class Node implements Comparable { @Override public int compareTo(@Nonnull Node other) { - if (this.type != null && other.type != null) { - return this.type.compareTo(other.type); - } if (this.index != other.index) { return this.index - other.index; } @@ -126,7 +120,7 @@ public class Node implements Comparable { * @return the param tag */ public Optional getParamTag(String id) { - return Optional.ofNullable(tags.get("param:" + id)); + return Optional.ofNullable(tags.get("param:"+id)); } /** @@ -136,7 +130,7 @@ public class Node implements Comparable { */ public void putTag(Tag tag) { String id = tag.id; - if (StringHelper.nonBlank(tag.getKey())) { + if(StringHelper.nonBlank(tag.getKey())){ id += ":" + tag.getKey(); } tags.put(id, tag); diff --git a/apidoc-core/src/main/java/com/kim/apidoc/core/schema/Project.java b/apidoc-core/src/main/java/kim/apidoc/core/schema/Project.java similarity index 70% rename from apidoc-core/src/main/java/com/kim/apidoc/core/schema/Project.java rename to apidoc-core/src/main/java/kim/apidoc/core/schema/Project.java index ae219b6..6cbf3fb 100644 --- a/apidoc-core/src/main/java/com/kim/apidoc/core/schema/Project.java +++ b/apidoc-core/src/main/java/kim/apidoc/core/schema/Project.java @@ -1,12 +1,10 @@ -package com.kim.apidoc.core.schema; +package kim.apidoc.core.schema; -import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; import lombok.Getter; import lombok.Setter; import java.util.*; - /** * 项目 * @@ -27,22 +25,12 @@ public class Project extends Node { */ Map books = new TreeMap<>(); - /** - * 附录 - */ - List appendices = new LinkedList<>(); - /** - * 统一结果 - */ - ClassOrInterfaceDeclaration resultDataClassOrInterfaceDeclaration; - /** * Add chapter. * * @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/kim/apidoc/core/schema/Row.java b/apidoc-core/src/main/java/kim/apidoc/core/schema/Row.java similarity index 73% rename from apidoc-core/src/main/java/com/kim/apidoc/core/schema/Row.java rename to apidoc-core/src/main/java/kim/apidoc/core/schema/Row.java index 9d3a51b..b3ea98b 100644 --- a/apidoc-core/src/main/java/com/kim/apidoc/core/schema/Row.java +++ b/apidoc-core/src/main/java/kim/apidoc/core/schema/Row.java @@ -1,4 +1,4 @@ -package com.kim.apidoc.core.schema; +package kim.apidoc.core.schema; import lombok.*; @@ -23,29 +23,19 @@ public class Row { * The Type. */ String type; - /** - * 是否必填. - */ - Boolean required; /** * The Condition. */ String condition; /** - * 默认值. + * The Def. */ String def; /** - * 说明. + * The Remark. */ String remark; - /** - * 请求参数类型 - */ - String requestParameterType; - - /** * Instantiates a new Row. * diff --git a/apidoc-core/src/main/java/com/kim/apidoc/core/schema/Section.java b/apidoc-core/src/main/java/kim/apidoc/core/schema/Section.java similarity index 93% rename from apidoc-core/src/main/java/com/kim/apidoc/core/schema/Section.java rename to apidoc-core/src/main/java/kim/apidoc/core/schema/Section.java index 00da4e2..7dcff54 100644 --- a/apidoc-core/src/main/java/com/kim/apidoc/core/schema/Section.java +++ b/apidoc-core/src/main/java/kim/apidoc/core/schema/Section.java @@ -1,8 +1,8 @@ -package com.kim.apidoc.core.schema; +package kim.apidoc.core.schema; -import com.kim.apidoc.core.common.ObjectMappers; -import com.kim.apidoc.core.common.QueryStringBuilder; -import com.kim.apidoc.core.common.helper.StringHelper; +import kim.apidoc.core.common.ObjectMappers; +import kim.apidoc.core.common.QueryStringBuilder; +import kim.apidoc.core.common.helper.StringHelper; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.node.ObjectNode; import lombok.Getter; @@ -21,19 +21,19 @@ import java.util.*; public class Section extends Node { /** - * 请求方法. + * The Method. */ Method method; /** - * 请求url. + * The Uri. */ String uri; /** - * 请求头. + * The In headers. */ Map inHeaders = new LinkedHashMap<>(); /** - * 路径变量. + * The Path variable. */ ObjectNode pathVariable = ObjectMappers.instance.createObjectNode(); /** @@ -44,7 +44,6 @@ public class Section extends Node { * The Query parameter. */ boolean queryParameter = true; - /** * The Request rows. */ @@ -67,7 +66,6 @@ public class Section extends Node { */ Object rawResponse; - /** * Add request row. * diff --git a/apidoc-core/src/main/java/com/kim/apidoc/core/schema/Tag.java b/apidoc-core/src/main/java/kim/apidoc/core/schema/Tag.java similarity index 95% rename from apidoc-core/src/main/java/com/kim/apidoc/core/schema/Tag.java rename to apidoc-core/src/main/java/kim/apidoc/core/schema/Tag.java index 899ed62..753ae7c 100644 --- a/apidoc-core/src/main/java/com/kim/apidoc/core/schema/Tag.java +++ b/apidoc-core/src/main/java/kim/apidoc/core/schema/Tag.java @@ -1,4 +1,4 @@ -package com.kim.apidoc.core.schema; +package kim.apidoc.core.schema; import lombok.Getter; import lombok.Setter; diff --git a/apidoc-core/src/main/resources/templates/markdown.ftl b/apidoc-core/src/main/resources/templates/markdown.ftl deleted file mode 100644 index d258fc7..0000000 --- a/apidoc-core/src/main/resources/templates/markdown.ftl +++ /dev/null @@ -1,89 +0,0 @@ -[TOC] - - - - -<#-- ---------- BEGIN 循环遍历book ----------> -<#if books??> - <#list books as bookKey,bookValue> - <#if bookValue.name??> - -<#--book名称--> -# ${bookValue.name} - - <#-- ---------- BEGIN 循环遍历chapter ----------> - <#assign chapterIndex=0> - <#list bookValue.chapters as chapter> - <#if !chapter.isIgnore()> - -<#assign chapterIndex++> -<#-- 章节名称--> -## ${chapterIndex}. ${chapter.name} -<#-- 章节描述--> - <#if chapter.description??> - -${chapter.description} - - <#-- ---------- BEGIN 循环遍历section ----------> - <#assign sectionIndex=0> - <#list chapter.sections as section> - <#if !section.isIgnore()> -<#assign sectionIndex++/> -<#-- 接口名称--> -### ${chapterIndex}.${sectionIndex} ${section.name} -<#-- 接口描述--> - <#if section.description??> - -${section.description} - - -<#-- 请求--> -**请求** - -<#-- 请求示例--> -```HTTP -${section.method} ${section.uri!''} HTTP/1.1 - <#if section.inHeaders??> - <#list section.inHeaders as inHeaderKey,inHeaderValue> -${inHeaderValue!''} - - - <#if section.hasRequestBody()> - -${section.getParameterString()} - -``` -<#-- 请求参数table列表--> - <#if section.requestRows?? && (section.requestRows?size>0)> - -| 字段 | 类型 | 参数类型 | 是否必填 | 验证 | 默认值 | 描述 | -| :------- | :----- | :----- |:-------- |:-------- | :------ | :---------- | - <#list section.requestRows as rowKey,rowValue> -| ${rowValue.key!''} | ${rowValue.type!''} | **${rowValue.requestParameterType!''}** |${rowValue.required?string('true','false')} | ${rowValue.condition!''} | ${rowValue.def!''} | ${rowValue.remark!''} | - - -<#-- 响应--> - <#if section.hasResponseBody()> -**响应** -``` -${section.getResponseString()} -``` - -<#-- 响应参数table列表--> - <#if section.responseRows?? && (section.responseRows?size>0)> - -| 字段 | 类型 | 描述 | -| :------- | :----- | :---------- | - <#list section.responseRows as rowKey,rowValue> -| ${rowValue.key!''} | ${rowValue.type!''} | ${rowValue.remark!''} | - - - - - <#------------ END 循环遍历section ----------> - - - <#------------ END 循环遍历chapter ----------> - -<#------------ END 循环遍历book ----------> - diff --git a/apidoc-springmvc/src/main/java/com/kim/apidoc/springmvc/RequestMappingHelper.java b/apidoc-springmvc/src/main/java/com/kim/apidoc/springmvc/RequestMappingHelper.java index e1624c3..ba0aa40 100644 --- a/apidoc-springmvc/src/main/java/com/kim/apidoc/springmvc/RequestMappingHelper.java +++ b/apidoc-springmvc/src/main/java/com/kim/apidoc/springmvc/RequestMappingHelper.java @@ -1,10 +1,10 @@ package com.kim.apidoc.springmvc; -import com.kim.apidoc.core.common.URI; -import com.kim.apidoc.core.common.helper.AnnotationHelper; -import com.kim.apidoc.core.common.helper.ClassDeclarationHelper; -import com.kim.apidoc.core.common.helper.ExpressionHelper; -import com.kim.apidoc.core.schema.Method; +import kim.apidoc.core.common.URI; +import kim.apidoc.core.common.helper.AnnotationHelper; +import kim.apidoc.core.common.helper.ClassDeclarationHelper; +import kim.apidoc.core.common.helper.ExpressionHelper; +import kim.apidoc.core.schema.Method; import com.github.javaparser.ast.Node; import com.github.javaparser.ast.NodeList; import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; diff --git a/apidoc-springmvc/src/main/java/com/kim/apidoc/springmvc/SpringMVCContext.java b/apidoc-springmvc/src/main/java/com/kim/apidoc/springmvc/SpringMVCContext.java index 53b65a9..e178cdb 100644 --- a/apidoc-springmvc/src/main/java/com/kim/apidoc/springmvc/SpringMVCContext.java +++ b/apidoc-springmvc/src/main/java/com/kim/apidoc/springmvc/SpringMVCContext.java @@ -1,6 +1,6 @@ package com.kim.apidoc.springmvc; -import com.kim.apidoc.core.ApiDoc; +import kim.apidoc.core.ApiDoc; import com.google.common.collect.Lists; import lombok.Data; diff --git a/apidoc-springmvc/src/main/java/com/kim/apidoc/springmvc/SpringParser.java b/apidoc-springmvc/src/main/java/com/kim/apidoc/springmvc/SpringParser.java index e80c81a..091a26f 100644 --- a/apidoc-springmvc/src/main/java/com/kim/apidoc/springmvc/SpringParser.java +++ b/apidoc-springmvc/src/main/java/com/kim/apidoc/springmvc/SpringParser.java @@ -1,28 +1,27 @@ package com.kim.apidoc.springmvc; +import com.kim.apidoc.springmvc.resovler.SpringComponentTypeResolver; +import kim.apidoc.core.ApiDoc; +import kim.apidoc.core.common.URI; +import kim.apidoc.core.common.description.ObjectTypeDescription; +import kim.apidoc.core.common.description.TypeDescription; +import kim.apidoc.core.common.helper.AnnotationHelper; +import kim.apidoc.core.common.helper.ExpressionHelper; +import kim.apidoc.core.common.helper.StringHelper; +import kim.apidoc.core.parser.ParserStrategy; +import kim.apidoc.core.schema.Chapter; +import kim.apidoc.core.schema.Header; +import kim.apidoc.core.schema.Row; +import kim.apidoc.core.schema.Section; import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; import com.github.javaparser.ast.body.MethodDeclaration; import com.github.javaparser.ast.body.Parameter; import com.github.javaparser.ast.expr.AnnotationExpr; import com.github.javaparser.ast.expr.Expression; -import com.github.javaparser.ast.type.ClassOrInterfaceType; -import com.kim.apidoc.core.ApiDoc; -import com.kim.apidoc.core.common.URI; -import com.kim.apidoc.core.common.description.ObjectTypeDescription; -import com.kim.apidoc.core.common.description.TypeDescription; -import com.kim.apidoc.core.common.helper.*; -import com.kim.apidoc.core.parser.ParserStrategy; -import com.kim.apidoc.core.schema.Chapter; -import com.kim.apidoc.core.schema.Header; -import com.kim.apidoc.core.schema.Row; -import com.kim.apidoc.core.schema.Section; -import com.kim.apidoc.springmvc.resovler.SpringComponentTypeResolver; import java.util.List; import java.util.Optional; -import static com.kim.apidoc.core.schema.RequestParameterType.*; - /** * spring 解析 @@ -44,6 +43,7 @@ public class SpringParser implements ParserStrategy { public static final String EXT_URI = "uri"; + @Override public String name() { return FRAMEWORK; @@ -157,11 +157,8 @@ public class SpringParser implements ParserStrategy { if (ParameterHelper.isPathVariable(parameter)) { section.getPathVariable().put(parameter.getNameAsString(), ""); Row row = new Row(); - row.setRequestParameterType(PATH.name()); row.setKey(parameter.getNameAsString()); row.setType(parameter.getType().toString()); - // 路径参数必填 - row.setRequired(true); section.getParamTag(row.getKey()).ifPresent(tag -> row.setRemark(tag.getContent())); section.addRequestRow(row); } @@ -236,7 +233,7 @@ public class SpringParser implements ParserStrategy { } else if (description.isObject()) { section.setParameter(description.asObject().getValue()); } - section.addRequestRows(description.rows(BODY.name())); + section.addRequestRows(description.rows()); } break; } @@ -295,25 +292,17 @@ public class SpringParser implements ParserStrategy { } } section.setParameter(objectTypeDescription.getValue()); - section.addRequestRows(objectTypeDescription.rows(QUERY.name())); + section.addRequestRows(objectTypeDescription.rows()); } /** - * 解析方法返回参 数 + * 解析方法返回参数 * * @param n the n * @param chapter the chapter * @param section the section */ private void visitReturn(MethodDeclaration n, Chapter chapter, Section section) { - ClassOrInterfaceDeclaration resultDataClassOrInterfaceDeclaration = ApiDoc.getInstance().getProject().getResultDataClassOrInterfaceDeclaration(); - if (null != resultDataClassOrInterfaceDeclaration) { - ClassOrInterfaceType returnType = new ClassOrInterfaceType(); - returnType.setName(resultDataClassOrInterfaceDeclaration.getName()); - returnType.setTypeArguments(n.getType()); - n.findCompilationUnit().get().addImport(ClassDeclarationHelper.getClassOrInterfacePackageName(resultDataClassOrInterfaceDeclaration)); - n.setType(returnType); - } TypeDescription description = ApiDoc.getInstance().getTypeResolvers().resolve(n.getType()); if (description.isAvailable()) { if (description.isPrimitive()) { diff --git a/apidoc-springmvc/src/main/java/com/kim/apidoc/springmvc/resovler/SpringComponentTypeResolver.java b/apidoc-springmvc/src/main/java/com/kim/apidoc/springmvc/resovler/SpringComponentTypeResolver.java index 6278094..7132860 100644 --- a/apidoc-springmvc/src/main/java/com/kim/apidoc/springmvc/resovler/SpringComponentTypeResolver.java +++ b/apidoc-springmvc/src/main/java/com/kim/apidoc/springmvc/resovler/SpringComponentTypeResolver.java @@ -1,11 +1,11 @@ package com.kim.apidoc.springmvc.resovler; -import com.kim.apidoc.core.ApiDoc; -import com.kim.apidoc.core.common.description.TypeDescription; -import com.kim.apidoc.core.common.description.UnAvailableTypeDescription; -import com.kim.apidoc.core.common.helper.TypeParameterHelper; -import com.kim.apidoc.core.resolver.TypeNameResolver; -import com.kim.apidoc.core.resolver.TypeResolver; +import kim.apidoc.core.ApiDoc; +import kim.apidoc.core.common.description.TypeDescription; +import kim.apidoc.core.common.description.UnAvailableTypeDescription; +import kim.apidoc.core.common.helper.TypeParameterHelper; +import kim.apidoc.core.resolver.TypeNameResolver; +import kim.apidoc.core.resolver.TypeResolver; import com.github.javaparser.ast.NodeList; import com.github.javaparser.ast.type.Type; import com.github.javaparser.resolution.types.ResolvedType; diff --git a/apidoc-springmvc/src/main/resources/META-INF/services/com.kim.apidoc.core.parser.ParserStrategy b/apidoc-springmvc/src/main/resources/META-INF/services/kim.apidoc.core.parser.ParserStrategy similarity index 100% rename from apidoc-springmvc/src/main/resources/META-INF/services/com.kim.apidoc.core.parser.ParserStrategy rename to apidoc-springmvc/src/main/resources/META-INF/services/kim.apidoc.core.parser.ParserStrategy diff --git a/apidoc-springmvc/src/test/java/com/kim/apidoc/example/ApigccTest.java b/apidoc-springmvc/src/test/java/com/kim/apidoc/example/ApigccTest.java index f9046ea..7684aa0 100644 --- a/apidoc-springmvc/src/test/java/com/kim/apidoc/example/ApigccTest.java +++ b/apidoc-springmvc/src/test/java/com/kim/apidoc/example/ApigccTest.java @@ -1,8 +1,8 @@ package com.kim.apidoc.example; -import com.kim.apidoc.core.ApiDoc; -import com.kim.apidoc.core.Context; +import kim.apidoc.core.ApiDoc; +import kim.apidoc.core.Context; import org.junit.Test; import java.nio.file.Paths; diff --git a/apidoc-springmvc/src/test/java/com/kim/apidoc/example/common/ResultData.java b/apidoc-springmvc/src/test/java/com/kim/apidoc/example/common/ResultData.java index bfeb26b..b3f033f 100644 --- a/apidoc-springmvc/src/test/java/com/kim/apidoc/example/common/ResultData.java +++ b/apidoc-springmvc/src/test/java/com/kim/apidoc/example/common/ResultData.java @@ -3,14 +3,6 @@ package com.kim.apidoc.example.common; import lombok.Getter; import lombok.Setter; -/** - * The type Result data. - * - * @param the type parameter - * @author fengyuchenglun - * @version 1.0.0 - * @resultData - */ @Setter @Getter public class ResultData { @@ -19,33 +11,13 @@ public class ResultData { * 返回码 */ int code; - /** - * The Msg. - */ -//返回信息 + //返回信息 String msg; - /** - * The Data. - */ T data; - /** - * Ok result data. - * - * @param the type parameter - * @return the result data - */ public static ResultData ok(){ return ok(null); } - - /** - * Ok result data. - * - * @param the type parameter - * @param data the data - * @return the result data - */ public static ResultData ok(T data){ ResultData resultData = new ResultData<>(); resultData.code = 0; diff --git a/apidoc-springmvc/src/test/java/com/kim/apidoc/example/common/Role.java b/apidoc-springmvc/src/test/java/com/kim/apidoc/example/common/Role.java index 22b450e..25bdd5c 100644 --- a/apidoc-springmvc/src/test/java/com/kim/apidoc/example/common/Role.java +++ b/apidoc-springmvc/src/test/java/com/kim/apidoc/example/common/Role.java @@ -2,34 +2,14 @@ package com.kim.apidoc.example.common; /** * 用户角色 - * * @code */ public enum Role { - /** - * Admin role. - */ - ADMIN("管理员"), - /** - * User role. - */ - USER("用户"), - /** - * Vip role. - */ - VIP("会员"); + ADMIN("管理员"),USER("用户"),VIP("会员"); - /** - * The Text. - */ String text; - /** - * Instantiates a new Role. - * - * @param text the text - */ Role(String text) { this.text = text; } diff --git a/apidoc-springmvc/src/test/java/com/kim/apidoc/example/common/User.java b/apidoc-springmvc/src/test/java/com/kim/apidoc/example/common/User.java index 9724a8f..97b50a3 100644 --- a/apidoc-springmvc/src/test/java/com/kim/apidoc/example/common/User.java +++ b/apidoc-springmvc/src/test/java/com/kim/apidoc/example/common/User.java @@ -8,39 +8,19 @@ import javax.validation.constraints.Min; import javax.validation.constraints.NotBlank; import javax.validation.constraints.NotNull; import java.util.Date; +import java.util.List; -/** - * 用户对象 - * - * @author fengyuchenglun - * @version 1.0.0 - */ @Setter @Getter public class User { - /** - * 用户编号. - */ int id; - /** - * 用户名称. - */ @NotBlank String name; - /** - * 用户年龄. - */ @Min(1) @NotNull Integer age; - /** - * 创建时间. - */ Date createAt; - /** - * 性别. - */ @NotBlank @JsonProperty("Sex") String sex; diff --git a/apidoc-springmvc/src/test/java/com/kim/apidoc/example/spring/BaseController.java b/apidoc-springmvc/src/test/java/com/kim/apidoc/example/spring/BaseController.java new file mode 100644 index 0000000..d32ddfd --- /dev/null +++ b/apidoc-springmvc/src/test/java/com/kim/apidoc/example/spring/BaseController.java @@ -0,0 +1,11 @@ +package com.kim.apidoc.example.spring; + +import org.springframework.web.bind.annotation.RequestMapping; + +/** + * 示例controller继承的情况 + * 子类继承父类的路径 + */ +@RequestMapping("/restdoc") +public class BaseController { +} diff --git a/apidoc-springmvc/src/test/java/com/kim/apidoc/example/spring/advanced/AuthController.java b/apidoc-springmvc/src/test/java/com/kim/apidoc/example/spring/advanced/AuthController.java new file mode 100644 index 0000000..4c7e733 --- /dev/null +++ b/apidoc-springmvc/src/test/java/com/kim/apidoc/example/spring/advanced/AuthController.java @@ -0,0 +1,25 @@ +package com.kim.apidoc.example.spring.advanced; + +import com.kim.apidoc.example.common.ResultData; +import com.kim.apidoc.example.spring.BaseController; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.*; + +/** + * @index 3 + */ +@Controller +@RequestMapping("/auth") +public class AuthController extends BaseController{ + + /** + * + * @param token 上报的身份验证token,jwt + * @return + */ + @PostMapping + public ResultData auth(@RequestHeader() String token){ + return ResultData.ok(); + } + +} diff --git a/apidoc-springmvc/src/test/java/com/kim/apidoc/example/spring/advanced/EmptyController.java b/apidoc-springmvc/src/test/java/com/kim/apidoc/example/spring/advanced/EmptyController.java new file mode 100644 index 0000000..d99b49d --- /dev/null +++ b/apidoc-springmvc/src/test/java/com/kim/apidoc/example/spring/advanced/EmptyController.java @@ -0,0 +1,15 @@ +package com.kim.apidoc.example.spring.advanced; + +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +/** + * will be ignore + */ +@RestController +@RequestMapping("/empty") +public class EmptyController { + + + +} diff --git a/apidoc-springmvc/src/test/java/com/kim/apidoc/example/spring/advanced/IgnoreController.java b/apidoc-springmvc/src/test/java/com/kim/apidoc/example/spring/advanced/IgnoreController.java new file mode 100644 index 0000000..2ff3b75 --- /dev/null +++ b/apidoc-springmvc/src/test/java/com/kim/apidoc/example/spring/advanced/IgnoreController.java @@ -0,0 +1,20 @@ +package com.kim.apidoc.example.spring.advanced; + +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +/** + * will be ignore + * @ignore + */ +@RestController +@RequestMapping("/ignore") +public class IgnoreController { + + + @RequestMapping + public void ignoreThis(){ + } + + +} diff --git a/apidoc-springmvc/src/test/java/com/kim/apidoc/example/spring/advanced/KimUserController.java b/apidoc-springmvc/src/test/java/com/kim/apidoc/example/spring/advanced/KimUserController.java index 3a54ae5..dd1ab59 100644 --- a/apidoc-springmvc/src/test/java/com/kim/apidoc/example/spring/advanced/KimUserController.java +++ b/apidoc-springmvc/src/test/java/com/kim/apidoc/example/spring/advanced/KimUserController.java @@ -1,17 +1,15 @@ package com.kim.apidoc.example.spring.advanced; import com.kim.apidoc.example.annotation.KimController; -import com.kim.apidoc.example.common.Query; -import com.kim.apidoc.example.common.User; -import com.kim.apidoc.example.common.ResultData; import com.kim.apidoc.example.common.ResultData; +import com.kim.apidoc.example.common.User; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; /** - * The type Kim user controller. + * kim接口 * * @author duanledexianxianxian * @version 1.0.0 @@ -23,25 +21,24 @@ import org.springframework.web.bind.annotation.RequestMapping; @RequestMapping("/api/v1") public class KimUserController { - /** - * Detail user. + * 用户详情信息 + * 主动根据id获取用户的信息 * - * @param id the id - * @param query the query - * @return 用户对象 user + * @param id 用户编号 + * @return result data */ @GetMapping(value = "/{id}") - public User detail(@PathVariable String id, Query query) { + public ResultData detail(@PathVariable String id) { User user = new User(); - return user; + return ResultData.ok(user); } /** * Add integer. * - * @return integer integer + * @return the integer */ @PostMapping public Integer add() { diff --git a/apidoc-springmvc/src/test/java/com/kim/apidoc/example/spring/advanced/PageController.java b/apidoc-springmvc/src/test/java/com/kim/apidoc/example/spring/advanced/PageController.java new file mode 100644 index 0000000..e77340c --- /dev/null +++ b/apidoc-springmvc/src/test/java/com/kim/apidoc/example/spring/advanced/PageController.java @@ -0,0 +1,140 @@ +package com.kim.apidoc.example.spring.advanced; + +import com.apigcc.model.Info; +import com.apigcc.model.InfoQuery; +import com.kim.apidoc.example.common.*; +import com.kim.apidoc.example.spring.BaseController; +import com.kim.apidoc.example.spring.hello.Greeting; +import org.jruby.ir.Tuple; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.*; +import org.springframework.web.servlet.ModelAndView; + +import java.util.List; +import java.util.Map; + +/** + * @index 4 + */ +@Controller +@RequestMapping("/page") +public class PageController extends BaseController { + + /** + * 默认页面,由于不是restful的,restdoc将忽略该Endpoint + * + * @return + */ + @GetMapping + public ModelAndView index() { + return new ModelAndView(); + } + + /** + * Hello with ResponseBody + * ********* + * 由于带有@ResponseBody,restdoc将解析该Endpoint + *

+ * hhh + * \********* + * ********* + * hhhh + * ********* + *

+ * class ************** { + *

+ * } + * + * @return + */ + @GetMapping("/hello") + @ResponseBody + public Greeting hello() { + return new Greeting(1, "hello world"); + } + + + /** + * 未知的多泛型的tuple 演示 + * + * @return + */ + @GetMapping("/tuple") + @ResponseBody + public Tuple tuple() { + return null; + } + + /** + * 多个RequestMethod + * + * @return + */ + @RequestMapping(value = "/multiMethod", method = {RequestMethod.GET, RequestMethod.POST, RequestMethod.PUT}) + @ResponseBody + public ResultData multiMethod() { + return null; + } + + @PostMapping("/multi") + @ResponseBody + public ResultData> multi(@RequestBody ResultData>> resultData) { + return null; + } + + + /** + * 引用二方Jar + * 使用二方Jar的类时,代码解析器无法获取类上的注释,注解 + * 只能获取属性的名称和类型 + * @param infoQuery + * @return + */ + @PostMapping("/jar") + @ResponseBody + public Info jar(@RequestBody InfoQuery infoQuery){ + return null; + } + + + /** + * 一个复杂的类型 List> + * @return + */ + @GetMapping("/map") + @ResponseBody + public List> map(){ + return null; + } + + /** + * 一个更复杂的类型 List>>> + * @return + */ + @GetMapping("/map") + @ResponseBody + public List>>> maps(){ + return null; + } + + /** + * 一个问号类型 List>> + * @return + */ + @GetMapping("/map") + @ResponseBody + public List>> maps1(){ + return null; + } + + + /** + * 多级菜单 + * @return + */ + @GetMapping("/menus") + @ResponseBody + public List

menus(){ + return null; + } +} diff --git a/apidoc-springmvc/src/test/java/com/kim/apidoc/example/spring/advanced/UserController.java b/apidoc-springmvc/src/test/java/com/kim/apidoc/example/spring/advanced/UserController.java new file mode 100644 index 0000000..b8746a2 --- /dev/null +++ b/apidoc-springmvc/src/test/java/com/kim/apidoc/example/spring/advanced/UserController.java @@ -0,0 +1,139 @@ +package com.kim.apidoc.example.spring.advanced; + +import com.kim.apidoc.example.common.*; +import com.kim.apidoc.example.spring.BaseController; +import org.springframework.http.ResponseEntity; +import org.springframework.ui.Model; +import org.springframework.web.bind.annotation.*; + +import java.util.List; + +/** + * 用户模块(标题) + * 用户示例模块文字描述(详情) + * 支持多行文字 + * @index 2 + */ +@RestController +@RequestMapping("/users") +public class UserController extends BaseController { + + /** + * 用户详情信息 + * 主动根据id获取用户的信息 + * + * @param id 用户编号 + * @return + */ + @GetMapping(value = "/{id}") + public ResultData detail(@PathVariable String id) { + User user = new User(); + return ResultData.ok(user); + } + + /** + * 用户详情信息(根据email或电话号码) + * 多路径适配 + * + * @param email + * @param phone + * @return + */ + @GetMapping(value = {"/detail", "/info"}) + public ResultData detailOrInfo(String email, String phone) { + return ResultData.ok(new User()); + } + + /** + * 用户信息新增 + * + * @param user 用户信息 + * @return + */ + @PostMapping + public ResultData add(@RequestBody UserDTO user) { + return ResultData.ok(); + } + + /** + * 用户信息更新 + * + * @param user 用户信息 + * @return + */ + @PatchMapping + public ResultData update(@RequestBody UserDTO user) { + return ResultData.ok(); + } + + /** + * 用户列表信息查询 + * 默认展示GET方法查询 + * 返回集合类的结果 + * + * @param page 页码 + * @param size 每页条数 + * @return + */ + @RequestMapping("/list") + public ResultData> list(@RequestParam(defaultValue = "1") int page, @RequestParam(defaultValue = "20") int size) { + return ResultData.ok(); + } + + /** + * 用户列表信息搜索 + * POST搜索时,请求参数将放在请求体中 + * + * @param userQuery 查询参数 + * @return + */ + @PostMapping("/search") + public ResultData> search(UserQuery userQuery) { + return ResultData.ok(); + } + + /** + * 用户信息删除 + * ResponseEntity、Model以及未知类型将忽略 + * + * @param id + * @return + */ + @RequestMapping(value = "/{id}", method = RequestMethod.DELETE) + public ResponseEntity delete(@PathVariable String id, Model model) { + return ResponseEntity.ok(ResultData.ok()); + } + + /** + * 用户禁用 + * 某些项目使用自定义的ArgumentResolver,让spring自动注入一些信息 + * restdoc在解析时,可通过env.ignoreTypes("UserDtails")来忽略这些 + * + * @param userDetails 当前登录用户的信息 + * @return + */ + @RequestMapping(value = "/{id}/disable", method = RequestMethod.PUT) + public ResultData disable(UserDetails userDetails) { + return ResultData.ok(); + } + + /** + * 查询角色下的用户总数 + * @param role 枚举类型{@link Role} + * @return + */ + @GetMapping("/role") + public ResultData listFromRole(Role role){ + return ResultData.ok(); + } + + /** + * 批量上传用户信息 + * @param list + * @return com.apigcc.example.common.UserDTO + */ + @PostMapping("/batch") + public void batch(@RequestBody List list){ + } + +} diff --git a/apidoc-springmvc/src/test/java/com/kim/apidoc/example/spring/hello/Greeting.java b/apidoc-springmvc/src/test/java/com/kim/apidoc/example/spring/hello/Greeting.java new file mode 100644 index 0000000..e0412f9 --- /dev/null +++ b/apidoc-springmvc/src/test/java/com/kim/apidoc/example/spring/hello/Greeting.java @@ -0,0 +1,26 @@ +package com.kim.apidoc.example.spring.hello; + +public class Greeting { + + /** + * 编号 + */ + private final long id; + /** + * 内容 + */ + private final String content; + + public Greeting(long id, String content) { + this.id = id; + this.content = content; + } + + public long getId() { + return id; + } + + public String getContent() { + return content; + } +} diff --git a/apidoc-springmvc/src/test/java/com/kim/apidoc/example/spring/hello/GreetingController.java b/apidoc-springmvc/src/test/java/com/kim/apidoc/example/spring/hello/GreetingController.java new file mode 100644 index 0000000..9a74535 --- /dev/null +++ b/apidoc-springmvc/src/test/java/com/kim/apidoc/example/spring/hello/GreetingController.java @@ -0,0 +1,44 @@ +package com.kim.apidoc.example.spring.hello; + +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +import java.util.concurrent.atomic.AtomicLong; + +/** + * 欢迎使用Apiggs + * + * @author fengyuchenglun + * @version 1.0.0 + * @index 1 + */ +@RestController +public class GreetingController { + + /** + * The constant template. + */ + private static final String template = "Hello, %s!"; + /** + * The Counter. + */ + private final AtomicLong counter = new AtomicLong(); + + /** + * 示例接口 + * 自定义错误编码 + * + * @param name 名称 + * @return greeting greeting + * @errorCode ERROR_CODE_1 错误编码1 很长很长的描述 + * @errorCode ERROR_CODE_2 错误编码2 很长很长的描述 + * @errorCode ERROR_CODE_3 错误编码3 很长很长的描述很长很长的描述很长很长的描述很长很长的描述很长很长的描述很长很长的描述 + * @errorCode ERROR_CODE_4 错误编码4 很长很长的描述很长很长的描述很长很长的描述很长很长的描述很长很长的描述很长很长的描述很长很长的描述很长很长的描述很长很长的描述 + */ + @RequestMapping("/greeting") + public Greeting greeting(@RequestParam(value = "name", defaultValue = "apigcc") String name) { + return new Greeting(counter.incrementAndGet(), + String.format(template, name)); + } +} diff --git a/apidoc-springmvc/src/test/java/com/kim/apidoc/springmvc/SpringTest.java b/apidoc-springmvc/src/test/java/com/kim/apidoc/springmvc/SpringTest.java index 23b6e0d..f372c1d 100644 --- a/apidoc-springmvc/src/test/java/com/kim/apidoc/springmvc/SpringTest.java +++ b/apidoc-springmvc/src/test/java/com/kim/apidoc/springmvc/SpringTest.java @@ -1,8 +1,8 @@ package com.kim.apidoc.springmvc; -import com.kim.apidoc.core.ApiDoc; -import com.kim.apidoc.core.Context; -import com.kim.apidoc.core.common.diff.FileMatcher; +import kim.apidoc.core.ApiDoc; +import kim.apidoc.core.Context; +import kim.apidoc.core.common.diff.FileMatcher; import org.junit.Test; import java.io.IOException; diff --git a/build.gradle b/build.gradle index f3d4228..ece9c30 100644 --- a/build.gradle +++ b/build.gradle @@ -18,7 +18,7 @@ allprojects { dependencies { compile 'ch.qos.logback:logback-classic:1.2.3' - compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.10' + compileOnly 'org.projectlombok:lombok:1.18.4' annotationProcessor 'org.projectlombok:lombok:1.18.6' diff --git "a/markdown\346\216\245\345\217\243\346\250\241\347\211\210.md" "b/markdown\346\216\245\345\217\243\346\250\241\347\211\210.md" index f8b474d..a596775 100644 --- "a/markdown\346\216\245\345\217\243\346\250\241\347\211\210.md" +++ "b/markdown\346\216\245\345\217\243\346\250\241\347\211\210.md" @@ -2,10 +2,6 @@ - - -# 系统管理 - ## 1. 用户接口 与用户相关接口。 @@ -14,7 +10,7 @@ 添加用户 - **请求** +#### request ```HTTP POST /api/v1/users HTTP/1.1 @@ -26,44 +22,31 @@ POST /api/v1/users HTTP/1.1 } ``` -| 字段 | 类型 | 参数类型 | 是否必填 | 默认值 | 描述 | -| :------- | :----- | ---------- | :-------- | :------ | :---------- | -| loginId | String | Body | 必填 | | 用户编号 | -| userName | String | Body | 必填 | | 用户名 | -| password | String | Body | 必填 | | 密码 | +##### header - **响应** +| Field | Type | Condition | Default | Description | +| :------- | :----- | :-------- | :------ | :---------- | +| loginId | String | | | 用户编号 | +| userName | String | | | 用户名 | +| password | String | | | 密码 | -``` -{ - "loginId":"admin", - "userName":"123456", - "passwords":"123456" -} -``` +##### query -| 字段 | 类型 | 描述 | -| :------- | :----- | :---------- | -| loginId | String | 用户编号 | -| userName | String | 用户名 | -| password | String | 密码 | +| Field | Type | Condition | Default | Description | +| :------- | :----- | :-------- | :------ | :---------- | +| loginId | String | | | 用户编号 | +| userName | String | | | 用户名 | +| password | String | | | 密码 | -### 1.2 查询用户列表 +##### body -查询用户列表 +| Field | Type | Condition | Default | Description | +| :------- | :----- | :-------- | :------ | :---------- | +| loginId | String | | | 用户编号 | +| userName | String | | | 用户名 | +| password | String | | | 密码 | - **请求** - -```HTTP -GET /api/v1/users?userName=XXX&sex=XXX HTTP/1.1E -``` - -| 字段 | 类型 | 参数类型 | 是否必填 | 默认值 | 描述 | -| :------- | :----- | :-------- | :------ | :---------- | ----------- | -| userName | String | QUERY | | |用户名| -| sex | String | QUERY | | |性别| - - **响应** +#### response ``` { @@ -73,36 +56,9 @@ GET /api/v1/users?userName=XXX&sex=XXX HTTP/1.1E } ``` -| 字段 | 类型 | 描述 | +| Field | Type | Description | | :------- | :----- | :---------- | | loginId | String | 用户编号 | | userName | String | 用户名 | | password | String | 密码 | - -### 1.3 删除用户 - -删除用户 - - **请求** - -```HTTP -DELETE /api/v1/users/:userId HTTP/1.1E -``` - -| 字段 | 类型 | 参数类型 | 是否必填 | 默认值 | 描述 | -| :------- | :----- | :-------- | :------ | :---------- | ----------- | -| userId | String | PATH | | |用户编号| - - **响应** - -``` -{ - "data":"true" -} -``` - -| 字段 | 类型 | 描述 | -| :------- | :----- | :---------- | -| data | String | 是否成功 | - -- GitLab