Commit ec4188d8 authored by duanledexianxianxian's avatar duanledexianxianxian 😁

代码重构

parent ca53f41f
...@@ -3,6 +3,7 @@ package com.github.fengyuchenglun.apidoc.core.common.description; ...@@ -3,6 +3,7 @@ package com.github.fengyuchenglun.apidoc.core.common.description;
import com.github.fengyuchenglun.apidoc.core.common.ObjectMappers; import com.github.fengyuchenglun.apidoc.core.common.ObjectMappers;
import com.github.fengyuchenglun.apidoc.core.schema.Row; import com.github.fengyuchenglun.apidoc.core.schema.Row;
import com.fasterxml.jackson.databind.node.ArrayNode; import com.fasterxml.jackson.databind.node.ArrayNode;
import lombok.Data;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
...@@ -10,6 +11,7 @@ import java.util.Collection; ...@@ -10,6 +11,7 @@ import java.util.Collection;
/** /**
* 数组类型描述 * 数组类型描述
*/ */
@Data
public class ArrayTypeDescription extends TypeDescription { public class ArrayTypeDescription extends TypeDescription {
protected ArrayNode value; protected ArrayNode value;
......
...@@ -4,6 +4,7 @@ import com.github.fengyuchenglun.apidoc.core.common.ObjectMappers; ...@@ -4,6 +4,7 @@ import com.github.fengyuchenglun.apidoc.core.common.ObjectMappers;
import com.github.fengyuchenglun.apidoc.core.schema.Row; import com.github.fengyuchenglun.apidoc.core.schema.Row;
import com.fasterxml.jackson.databind.node.ObjectNode; import com.fasterxml.jackson.databind.node.ObjectNode;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import lombok.Data;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
...@@ -16,8 +17,7 @@ import java.util.List; ...@@ -16,8 +17,7 @@ import java.util.List;
* @author fengyuchenglun * @author fengyuchenglun
* @version 1.0.0 * @version 1.0.0
*/ */
@Setter @Data
@Getter
public class ObjectTypeDescription extends TypeDescription { public class ObjectTypeDescription extends TypeDescription {
/** /**
...@@ -29,6 +29,12 @@ public class ObjectTypeDescription extends TypeDescription { ...@@ -29,6 +29,12 @@ public class ObjectTypeDescription extends TypeDescription {
*/ */
private ObjectNode value = ObjectMappers.instance.createObjectNode(); private ObjectNode value = ObjectMappers.instance.createObjectNode();
@Override
public void setRequired(Boolean required) {
this.required = required;
this.members.get(0).setRequired(required);
}
/** /**
* Merge. * Merge.
* *
......
...@@ -2,10 +2,12 @@ package com.github.fengyuchenglun.apidoc.core.common.description; ...@@ -2,10 +2,12 @@ package com.github.fengyuchenglun.apidoc.core.common.description;
import com.github.javaparser.resolution.types.ResolvedPrimitiveType; import com.github.javaparser.resolution.types.ResolvedPrimitiveType;
import com.github.javaparser.resolution.types.ResolvedReferenceType; import com.github.javaparser.resolution.types.ResolvedReferenceType;
import lombok.Data;
/** /**
* 原始类型描述 * 原始类型描述
*/ */
@Data
public class PrimitiveTypeDescription extends TypeDescription { public class PrimitiveTypeDescription extends TypeDescription {
/** /**
......
package com.github.fengyuchenglun.apidoc.core.common.description; package com.github.fengyuchenglun.apidoc.core.common.description;
import lombok.Data;
/** /**
* 字符串类型 * 字符串类型
*/ */
@Data
public class StringTypeDescription extends TypeDescription { public class StringTypeDescription extends TypeDescription {
/** /**
......
...@@ -6,6 +6,7 @@ import com.github.fengyuchenglun.apidoc.core.schema.Row; ...@@ -6,6 +6,7 @@ import com.github.fengyuchenglun.apidoc.core.schema.Row;
import com.github.javaparser.ast.comments.Comment; import com.github.javaparser.ast.comments.Comment;
import com.github.javaparser.javadoc.Javadoc; import com.github.javaparser.javadoc.Javadoc;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import lombok.Data;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
...@@ -13,9 +14,9 @@ import java.util.Collection; ...@@ -13,9 +14,9 @@ import java.util.Collection;
/** /**
* The type Type description. * The type Type description.
* @author duanledexianxianxian
*/ */
@Setter @Data
@Getter
public abstract class TypeDescription { public abstract class TypeDescription {
/** /**
...@@ -46,10 +47,11 @@ public abstract class TypeDescription { ...@@ -46,10 +47,11 @@ public abstract class TypeDescription {
* 默认值. * 默认值.
*/ */
protected Object defaultValue; protected Object defaultValue;
/** /**
* 是否必填. * 是否必填.
*/ */
protected Boolean required; protected Boolean required=false;
/** /**
* Is available boolean. * Is available boolean.
...@@ -185,11 +187,11 @@ public abstract class TypeDescription { ...@@ -185,11 +187,11 @@ public abstract class TypeDescription {
def = ""; def = "";
} }
if (required != null) { // if (required != null) {
condition.append("required=").append(required); // condition.append("required=").append(required);
} // }
return Lists.newArrayList(new Row(key, type, false, condition.toString(), def, remark, requestParameterType)); return Lists.newArrayList(new Row(key, type, required, condition.toString(), def, remark, requestParameterType));
} }
......
package com.github.fengyuchenglun.apidoc.core.common.description; package com.github.fengyuchenglun.apidoc.core.common.description;
import com.github.fengyuchenglun.apidoc.core.schema.Row; import com.github.fengyuchenglun.apidoc.core.schema.Row;
import lombok.Data;
import java.util.Collection; import java.util.Collection;
/** /**
* 未知类型,应该忽略 * 未知类型,应该忽略
* @author duanledexianxianxian
*/ */
@Data
public class UnAvailableTypeDescription extends TypeDescription { public class UnAvailableTypeDescription extends TypeDescription {
public UnAvailableTypeDescription() { public UnAvailableTypeDescription() {
......
...@@ -43,6 +43,7 @@ public class MarkdownRender implements ProjectRender { ...@@ -43,6 +43,7 @@ public class MarkdownRender implements ProjectRender {
} }
private void build(Project project) throws Exception { private void build(Project project) throws Exception {
System.out.println(project);
String templatePath = ApiDoc.getInstance().getContext().getMarkdownTemplate(); String templatePath = ApiDoc.getInstance().getContext().getMarkdownTemplate();
String id = ApiDoc.getInstance().getContext().getId(); String id = ApiDoc.getInstance().getContext().getId();
Path buildPath = ApiDoc.getInstance().getContext().getBuildPath(); Path buildPath = ApiDoc.getInstance().getContext().getBuildPath();
......
...@@ -5,6 +5,8 @@ import com.github.javaparser.ast.comments.JavadocComment; ...@@ -5,6 +5,8 @@ import com.github.javaparser.ast.comments.JavadocComment;
import com.github.javaparser.ast.nodeTypes.NodeWithSimpleName; import com.github.javaparser.ast.nodeTypes.NodeWithSimpleName;
import com.github.fengyuchenglun.apidoc.core.common.helper.EnumHelper; import com.github.fengyuchenglun.apidoc.core.common.helper.EnumHelper;
import com.github.fengyuchenglun.apidoc.core.common.helper.FieldHelper; import com.github.fengyuchenglun.apidoc.core.common.helper.FieldHelper;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
...@@ -15,8 +17,8 @@ import java.util.List; ...@@ -15,8 +17,8 @@ import java.util.List;
/** /**
* 附录 * 附录
*/ */
@Setter @Data
@Getter @EqualsAndHashCode(callSuper=true)
public class Appendix extends Node { public class Appendix extends Node {
/** /**
......
package com.github.fengyuchenglun.apidoc.core.schema; package com.github.fengyuchenglun.apidoc.core.schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
...@@ -12,8 +14,8 @@ import java.util.TreeSet; ...@@ -12,8 +14,8 @@ import java.util.TreeSet;
* @author fengyuchenglun * @author fengyuchenglun
* @version 1.0.0 * @version 1.0.0
*/ */
@Setter @Data
@Getter @EqualsAndHashCode(callSuper=true)
public class Book extends Node { public class Book extends Node {
/** /**
......
package com.github.fengyuchenglun.apidoc.core.schema; package com.github.fengyuchenglun.apidoc.core.schema;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import lombok.Data;
import java.util.List; import java.util.List;
...@@ -9,6 +10,7 @@ import java.util.List; ...@@ -9,6 +10,7 @@ import java.util.List;
* *
* @param <T> the type parameter * @param <T> the type parameter
*/ */
@Data
public class Cell<T> { public class Cell<T> {
/** /**
......
package com.github.fengyuchenglun.apidoc.core.schema; package com.github.fengyuchenglun.apidoc.core.schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
...@@ -12,15 +14,14 @@ import java.util.TreeSet; ...@@ -12,15 +14,14 @@ import java.util.TreeSet;
* @author fengyuchenglun * @author fengyuchenglun
* @version 1.0.0 * @version 1.0.0
*/ */
@Setter @Data
@Getter @EqualsAndHashCode(callSuper = true)
public class Chapter extends Node { public class Chapter extends Node {
/** /**
* The Book name. * The Book name.
*/ */
String bookName; String bookName;
Project project;
/** /**
* The Sections. * The Sections.
......
package com.github.fengyuchenglun.apidoc.core.schema; package com.github.fengyuchenglun.apidoc.core.schema;
import lombok.Data;
import lombok.Getter; import lombok.Getter;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import lombok.Setter; import lombok.Setter;
...@@ -10,8 +11,7 @@ import lombok.Setter; ...@@ -10,8 +11,7 @@ import lombok.Setter;
* @author fengyuchenglun * @author fengyuchenglun
* @version 1.0.0 * @version 1.0.0
*/ */
@Setter @Data
@Getter
@NoArgsConstructor @NoArgsConstructor
public class Header { public class Header {
......
...@@ -5,6 +5,8 @@ import com.github.javaparser.ast.comments.Comment; ...@@ -5,6 +5,8 @@ import com.github.javaparser.ast.comments.Comment;
import com.github.javaparser.javadoc.Javadoc; import com.github.javaparser.javadoc.Javadoc;
import com.github.fengyuchenglun.apidoc.core.common.helper.CommentHelper; import com.github.fengyuchenglun.apidoc.core.common.helper.CommentHelper;
import com.github.fengyuchenglun.apidoc.core.common.helper.StringHelper; import com.github.fengyuchenglun.apidoc.core.common.helper.StringHelper;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
...@@ -19,8 +21,7 @@ import java.util.Optional; ...@@ -19,8 +21,7 @@ import java.util.Optional;
* @author fengyuchenglun * @author fengyuchenglun
* @version 1.0.0 * @version 1.0.0
*/ */
@Setter @Data
@Getter
public class Node implements Comparable<Node> { public class Node implements Comparable<Node> {
/** /**
* 节点类型 * 节点类型
......
package com.github.fengyuchenglun.apidoc.core.schema; package com.github.fengyuchenglun.apidoc.core.schema;
import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
...@@ -13,8 +15,8 @@ import java.util.*; ...@@ -13,8 +15,8 @@ import java.util.*;
* @author fengyuchenglun * @author fengyuchenglun
* @version 1.0.0 * @version 1.0.0
*/ */
@Setter @Data
@Getter @EqualsAndHashCode(callSuper = true)
public class Project extends Node { public class Project extends Node {
/** /**
...@@ -42,7 +44,6 @@ public class Project extends Node { ...@@ -42,7 +44,6 @@ public class Project extends Node {
* @param chapter the chapter * @param chapter the chapter
*/ */
public void addChapter(Chapter chapter) { public void addChapter(Chapter chapter) {
chapter.setProject(this);
if (Objects.isNull(chapter.getBookName())) { if (Objects.isNull(chapter.getBookName())) {
chapter.setBookName(Book.DEFAULT); chapter.setBookName(Book.DEFAULT);
} }
......
...@@ -11,8 +11,7 @@ import lombok.*; ...@@ -11,8 +11,7 @@ import lombok.*;
@EqualsAndHashCode @EqualsAndHashCode
@NoArgsConstructor @NoArgsConstructor
@AllArgsConstructor @AllArgsConstructor
@Setter @Data
@Getter
public class Row { public class Row {
/** /**
......
...@@ -5,6 +5,8 @@ import com.github.fengyuchenglun.apidoc.core.common.QueryStringBuilder; ...@@ -5,6 +5,8 @@ import com.github.fengyuchenglun.apidoc.core.common.QueryStringBuilder;
import com.github.fengyuchenglun.apidoc.core.common.helper.StringHelper; import com.github.fengyuchenglun.apidoc.core.common.helper.StringHelper;
import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ObjectNode; import com.fasterxml.jackson.databind.node.ObjectNode;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
...@@ -17,8 +19,8 @@ import java.util.*; ...@@ -17,8 +19,8 @@ import java.util.*;
* @author fengyuchenglun * @author fengyuchenglun
* @version 1.0.0 * @version 1.0.0
*/ */
@Setter @Data
@Getter @EqualsAndHashCode(callSuper=true)
public class Section extends Node { public class Section extends Node {
/** /**
......
package com.github.fengyuchenglun.apidoc.core.schema; package com.github.fengyuchenglun.apidoc.core.schema;
import lombok.Data;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
...@@ -14,8 +15,7 @@ import java.util.Objects; ...@@ -14,8 +15,7 @@ import java.util.Objects;
* @version 1.0.0 * @version 1.0.0
*/ */
@Slf4j @Slf4j
@Setter @Data
@Getter
public class Tag { public class Tag {
/** /**
......
...@@ -265,6 +265,8 @@ public class SpringParser implements ParserStrategy { ...@@ -265,6 +265,8 @@ public class SpringParser implements ParserStrategy {
Optional<AnnotationExpr> optional = parameter.getAnnotationByName(ParameterHelper.ANNOTATION_REQUEST_PARAM); Optional<AnnotationExpr> optional = parameter.getAnnotationByName(ParameterHelper.ANNOTATION_REQUEST_PARAM);
if (optional.isPresent()) { if (optional.isPresent()) {
// 如果有RequestParam注解,则参数必填
required = true;
Optional<Expression> valueOptional = AnnotationHelper.getAnyAttribute(optional.get(), "value", "name"); Optional<Expression> valueOptional = AnnotationHelper.getAnyAttribute(optional.get(), "value", "name");
if (valueOptional.isPresent()) { if (valueOptional.isPresent()) {
key = String.valueOf(ExpressionHelper.getValue(valueOptional.get())); key = String.valueOf(ExpressionHelper.getValue(valueOptional.get()));
......
...@@ -3,6 +3,7 @@ package com.github.fengyuchenglun.example.spring.advanced; ...@@ -3,6 +3,7 @@ package com.github.fengyuchenglun.example.spring.advanced;
import com.github.fengyuchenglun.example.annotation.KimController; import com.github.fengyuchenglun.example.annotation.KimController;
import com.github.fengyuchenglun.example.common.Query; import com.github.fengyuchenglun.example.common.Query;
import com.github.fengyuchenglun.example.common.User; import com.github.fengyuchenglun.example.common.User;
import com.github.fengyuchenglun.example.common.UserQuery;
import lombok.Data; import lombok.Data;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
...@@ -42,7 +43,7 @@ public class UserController { ...@@ -42,7 +43,7 @@ public class UserController {
* @return 用户对象 user * @return 用户对象 user
*/ */
@GetMapping(value = "/detail1") @GetMapping(value = "/detail1")
public User detail1( Query query) { public User detail1(Query query) {
User user = new User(); User user = new User();
return user; return user;
} }
...@@ -59,6 +60,65 @@ public class UserController { ...@@ -59,6 +60,65 @@ public class UserController {
return user; return user;
} }
/**
* 查看用户详情
*
* @param query 过滤条件
* @return 用户对象 user
*/
@GetMapping(value = "/detail4")
public User detail4(@RequestParam(required = false) Query query) {
User user = new User();
return user;
}
/**
* 查看用户详情
*
* @return 用户对象 user
*/
@GetMapping(value = "/detail5")
public User detail5() {
User user = new User();
return user;
}
/**
* 查看用户详情
*
* @param userName the user name
* @param age the age
* @param query the query
* @return 用户对象 user
*/
@GetMapping(value = "/detail6")
public User detail6(String userName, Integer age, UserQuery query) {
User user = new User();
return user;
}
/**
* 查看用户详情
*
* @return 用户对象 user
*/
@GetMapping(value = "/detail7")
public void detail7() {
}
/**
* 删除用户
*
* @param userId the user id
* @return boolean 是否成功
*/
@DeleteMapping(value = "/{userId}")
public Boolean deleteUser(@PathVariable("userId") Long userId) {
return true;
}
/** /**
* 用户表单对象. * 用户表单对象.
* *
...@@ -86,7 +146,7 @@ public class UserController { ...@@ -86,7 +146,7 @@ public class UserController {
* 添加用户 * 添加用户
* *
* @param form 用户表单对象 * @param form 用户表单对象
* @return integer integer * @return integer 返回记录
*/ */
@PostMapping @PostMapping
public Integer add(@RequestBody UserForm form) { public Integer add(@RequestBody UserForm form) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment