diff --git a/apidoc-core/build.gradle b/apidoc-core/build.gradle index dffa1eef891299413ad279489879625eece4cf6f..2a1eec758c4a575880e12bf087c805da7b9c3017 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 a28605a47ca83d8c9b1e24fc2c1b5b4c743061a5..0000000000000000000000000000000000000000 --- 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 0727e22e15469b20bc6a4de103d0035c783a7996..0000000000000000000000000000000000000000 --- 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 558b268b2db799c7a03287845f60c08af1375f47..0000000000000000000000000000000000000000 --- 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 c098eded5f86aa5f76b7ea1232467f0ee181f3ff..0000000000000000000000000000000000000000 --- 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 f3a00bb8b785f2a430e9046968435eb798830605..0000000000000000000000000000000000000000 --- 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 49435274b6fc222d17fde2a218e07bbc0a5196b1..0000000000000000000000000000000000000000 --- 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 b2148ff3a4a454e895b646bdfd26ffc8c11f98ce..0000000000000000000000000000000000000000 --- 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 91739e0fcbbfb55532591bb491d644fdeed69fb6..0000000000000000000000000000000000000000 --- 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 dc17e8a10859ed9bff5ce170e92855bdbb57ce56..0000000000000000000000000000000000000000 --- 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 6984ddd728c27663a4b7f0ff0beb6e8af2542674..fc1219920cb473e267e625fe463999383d92e664 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 bb58954d4a3088eb21f9b5d8553b48c6c4af5266..01d1ed0b71557a6c943a8386d388ada8c7b9c4a9 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 ea8bcb297fd2a3d6116b167136249e2a2d9208bb..a98d17de84a4be9fd5600e27239c2709cd0fb539 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 d8fa44b2cccefdcbe6f3c031fd058860cabd2342..685cb2675022c4e7f905fe18d95d602f30f5f980 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 1bfb72783e2d26fbb16bc0ae172f1cd22d6b51a2..9cfafa525618afbc46a178dbb54cf65c181bd2d8 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 c053981509d2bf8603e3d1446bef3a88879d9726..909071c54cd8ff0ddcd34f1fa524a4fac634667a 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 4b05db07b9a97fbe8adda9d8b908a5b9487fc3e9..8359d867265950a3290151edfd732b5cbdb9e8d2 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 8aba8aae0dc16984bad0f6bb2acfcb4a929f389a..f614fd1185f6b412944c0bab26d850874db0e47a 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 84e53a53108836a0cd597e2881ac6936154fd801..0eb349e1dca943836e0cc8460444ea3cc098f17a 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 021bd952847c1fe2894038c9aa66535e25184d1c..f8d589bab3b63419f39f7c3148151496255b2252 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 0000000000000000000000000000000000000000..57b7cc9899e73d93f58a6d14af27b30c687ae784 --- /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 a2941211598b7b3ae657564818a9e3f4880cd851..d40e90eced44253601cbe9b9c5beb59cc5c1e87f 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 14031b8d23e658b0e63341f6ba94b2ecbb2c5246..52b5806f9164b69e5c8d4e0fb63ba6e340287f5a 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 0f6115f5c8e50e2e648fbaad44c3525f78513d19..447274b5a02fde6847ccbf9cbb6a3e6cf20c39ed 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 311bf40b66a4f66c43aa8609389969fb97465090..0d0da4bc588c2cf6a406a6e4d8a3aecbc66e1b90 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 a5393650a378e9ff884507fb52d36d8f4d4ef278..4304fec5608b1dba3dfaf9a342867891d74f833c 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 3ea0d10bc02960da5803104b0f806dc2baecdd9e..cc0a05fbc6d2b478e8d81ee06a3a3fa274f07636 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 86e8f7ea5441c0a7f08f1bc3c97adb3930e679f5..86234f2e97f7dac8cdf774ce67bfd1bf15fda942 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 dbb34bf41c31ec73aaa8ac2ea14a18ddbde66857..5cd759171ea9c48c14fc3e56e17c8566190f31ac 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 a20830915d594f531d4b7111bee381363f102f8c..13adf03728573a7fd19dd6c94302b2645b9007a5 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 0000000000000000000000000000000000000000..fcb8c5358e0c6d42a61597104c933e2c270e8537 --- /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 59247b8302795e5f55c636dfc44d67dd63906dcf..7a780362ff5cf30f317b550d67e7b2cbdc2d03c5 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 447b79da1ecbb2db6f366946cdf1adb0a4feceb7..63c748a33bb75c190790fe1ae80f2e46afa53edc 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 8aab28beac65d8e1b613747f0a509f60ff10a4e7..661243d053b931c4dcbd3faea249f2af17cf5c46 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 8ef8fcdd10b8977d351096238518d2784b3ac56f..20daa4003c59902da6d0dea9aed2b68a5bfebacd 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 14f9f4e7d1f54a4f79eb292436ab526338b8f908..08e98fecde7b66c21e357d3ae92dcacc7c1ff69b 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 64fef127a6f9e7d749f6c5a753a326a4ecc70caf..38efcaf93321e99709eab27e241f7b3436b3fb65 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 42ad047dab77db349e184d65ca97a84e4cbc9e10..722d0b0f9ac59f713536f2e5171f5892b359e76c 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 44f849bc465598f3b20ca57863189e527e2edd35..0d42101ec92bc8a62035b85982a3a98122f6f9fc 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 629ef8f45992864752c9923df370435aab897771..0dd0a03d7790b7f8f65410b6d94218feb5c0c4bc 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 c114e5ea3c7c186284e7805d7b91f7f4a4883228..18e4ca4fbecb72ba53f424a8617c71fb1e3e9b1d 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 9642f9aef5fae1bcd22c20b764ebbefbd0cf61a9..5d95e67a0d69a81907f4ff42a6b9035e78555bf8 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 b7ca387286535527ab11937c0321c7b5297ab7e7..301f70e651886ae45864ff413165f1fbb3f98735 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 8fdb93f53ea61e7dc011180d474b6bfeaaad601e..22f00147c86f26352ff50fd526f04ca2fca4cea3 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 1c80669a90cc8e4f24a898b7d1e70610d9cb6b52..2b012d59b5bdbd60e5d145870773ea9d87cb4511 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 b3a32fe1654965a7601709bc91fd3b54ce2c82ea..47487e575bb2b7370a7a29333a7129290a7c853d 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 3972bd9604353f36456fb89d58ac55765044e78f..7d56b3c4e50f4ee16dacce10222fa037ec5a74c0 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 be112fb94449485d9fd5538e1d6d8a2361479b8e..8620ef9c34ec38bceea73d8ad56b51954cea2390 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 32ea847f0d21fb5d7dc9c329118507682fde4362..5fceb856b60eff85f9a7d5a00013b31c90d23be0 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 9cd90f5fe38947f39fd5e0aa262f83470561d364..4a25b191da786339d5db137acb69e5102567a05a 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 26f8aaa040f1327d3a7bb4e4514d68e78c75d4cd..5f3baf7637e6e3fc0be678e9f464df9f87470658 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 1d6be5db89f241dfe7fde49aaf918f44f3d69b51..549e7a9a315a0cf688bf45fe2f190338a4160e0b 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 e54cbcb5291835771db69233ba75c6839207d430..6ddf403cfbce920e6b114eb4c1b93316c91efd7a 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 b8ef7390653b6e49f90af5581ba40d8184fa563b..3854cda0f508b355ffbdea2c1b0ee7a69a6a35ec 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 3cb84e055a4bdeb23977dc4ea06726ba1e194924..5fc565dcd4fd4cf0844ecaea9c862acb5363396c 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 f7e3331b1e43b5b01940667535f8603bd886aad0..699a3a0c786aa7f0e462cc8c812dac0634509ce3 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 0000000000000000000000000000000000000000..8567ecca65aea120de997937edbd0c24d1717781 --- /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 491dc2ea260268b21a18114333e5def5b329477d..c1e7b249dd5f9788d6a3e8753ea61f0e19f7ae7b 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 0000000000000000000000000000000000000000..739d24a8a39856f65f8ac726d8d0dbdbd2e8b4b1 --- /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 325add5b80981953b01835b6f06739aa7cd8b802..1afe2df0c8db978a78c2346995f6749390a92e79 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 c2c36614085fd56a5dbd5abb4e388194a0f8f5a6..2e126666f448a2f0cfcefd7808ca01ddc57e0977 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 76f2296902ca52a688a0c1028faae3faf3b98753..db9e2c6913183603098cac52dce0facd2ad721f5 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 f08cc10600e58f4f2d8af1ad7d0288d17b2588be..89e6356f3597bd0b232099b47547fff74fbde7d3 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 9c9f20ddbee5bf1f7379c80ee79e8005f5fb88fa..b163b84fe80dc4328ff0ff3688de639ba6d411ef 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 306f27cef3860c58b87896b9c9462ac8a63f72a3..613803396bc2df374d1787127ba942afe7007d32 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 8118dab205e1efde3dd6aaf45722c0aa9f11c878..9cba7e118263a9de9d0a1417e3a89d911423f077 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 8a9bf3786a868f0bbc024a066ed1e89c43363143..b9302f976c61c1a719a2c02db1727a96915cd44a 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 fde1fe2c8f605609fb9c3f660f05cbc5845d8c0f..cdd456b013db60a102efb75f320aeb4361e10807 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 295444449d4c7551ff50ff2ec92d28c6f1362bf1..b2942c49a44c5c2331aedabbdee2c8ce4976e711 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 da8ffb333119857b14b42e431ad4fd04019af5e5..5fe5e565976882135f6e991c8276f4d052e1b7fb 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 92efd8e9f2b3a9b9e5baed20f28088949fd62cb8..7a12503427889e4028263ea83c0bf06dc18472e0 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 3d9a3c742bd353c36781925b29603a3993d3f83c..469a6916c05020e8beab1310f34af58045e800c1 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 485847832bad4e4c406dd5ef8dbdeffff2d3dc73..fc8a6b1ce656d9bca5b9514734e964fcb8f54070 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 dfd2da2e0ae5f304c6d67c2a417270df8bc69ea7..99b9eddefef6863228e85f30ff96e0e5d46b19b8 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 99b7e64c8e2f0173ec990913d32c5fb7c00da6e0..59e699d6d45876278d64af6036e6ced381ab494b 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 cd99d6402470ea8337f30a1bd713e0f41b1759c2..962f0f21f08a16ef3c46f4518382d9f31d86ee8e 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 31c09d71a307bcb80dae904c61f1edd38e05d336..4cf18f6372119525e7e0d75f4400620dda24fb37 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 63d628cef324fdfa5c1e82a7e67a870b57780914..0abf6c1f287c9a6cb2305efc13b9ebdf9c5a3347 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 ae219b6a62add410d48a7649943635bb83b8d8fd..6cbf3fb7f5a8250974b0e262a28ff41ca0c383b5 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 9d3a51b30779eac3b17dfedc7fd4e7c391d0e4ac..b3ea98bfe17cd1c12215e187b74a334923d1b9f2 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 00da4e253dad1e3b9fdb5554faffbcad1c894889..7dcff547dde9e8431be1b9de49a9a9f1041d2e29 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 899ed6247901b02313239669503977b703a2698f..753ae7c5ddd74cc1baefe8b2441447d861102043 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 d258fc7b659c6241573ea8e3255424e07b673203..0000000000000000000000000000000000000000 --- 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 e1624c3f3b7b21f60385522f5172e17db99a595a..ba0aa40a336ab2eef65e8658e28f674ecf5ab71b 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 53b65a9de081a34f2b38ca9aec499fe483f03a93..e178cdb453b991b30c9308314bcf2cbf8447ae2b 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 e80c81ad5d44b1c4943e4a31ca064c33cf4361fa..091a26fd2eb4a7574bf0e4a5466bc6d5d3c1fb7b 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 62780943ca1dec72f5e89d4e0ac6458c84f1573f..7132860bc645ff94806be480a004bbf392464e07 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 f9046ea1193519308284904f351ecc97b422e795..7684aa0f6485515c3fe9a23f20c090b866351b87 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 bfeb26b10bf4c42c08a633fbcddaff1f376fe6b8..b3f033fa79b0136a4449723be07baa4db53cc304 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 22b450ed7abac2b3191d8987e1a1c2da2044aa2a..25bdd5c8a3218029718d54da1674563459af1dbc 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 9724a8f4f4903982853cd260b60922bea6c29059..97b50a38ec6e42846ce9f103ad083b060c3c85bc 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 0000000000000000000000000000000000000000..d32ddfdf7f69ef93da5c9fd2a713e7ee245e91c6 --- /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 0000000000000000000000000000000000000000..4c7e733368df8f5e0117c1799925470f9a840cd0 --- /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 0000000000000000000000000000000000000000..d99b49dcc5ce1ff8694643ff3369331baebe5ae0 --- /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 0000000000000000000000000000000000000000..2ff3b75fab20c78a7976bbba23239f5ec19bb569 --- /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 3a54ae5683d027d0106ef1d8d7ee6eb024e17190..dd1ab5971295eabdcae0ddd05d07cfb3b3dedf67 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 0000000000000000000000000000000000000000..e77340c7bacaecac3e6cb3a0ef6d1b4c5ba8d6de --- /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 0000000000000000000000000000000000000000..b8746a27663efb93b6fbe2e2f6ab409022d31ca0 --- /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 0000000000000000000000000000000000000000..e0412f913f9d6b2784937ba737a394c84965d466 --- /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 0000000000000000000000000000000000000000..9a74535349e7d3231530afd9693c2dd30e7b06f8 --- /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 23b6e0d983d6a4de9e38c0b0e3ec12366c68f807..f372c1d32b2d5cca2c2c115190ce45eb8e7aed5a 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 f3d4228adc1783de05ddfed1140970269efc84e3..ece9c30264c61d53aa76070bb6bc229caf2b0568 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 f8b474d17fab58e2395cae700a688ac6fb8f7b23..a596775fc9361d929f551a187e95e6766de47c49 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 | 是否成功 | -