Commit ec4188d8 authored by duanledexianxianxian's avatar duanledexianxianxian 😁

代码重构

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