Commit 01c179c7 authored by duanledexianxianxian's avatar duanledexianxianxian 😁

Refactoring code.

parent 27ab485b
......@@ -104,4 +104,15 @@ public class ObjectTypeDescription extends TypeDescription {
}
return rows;
}
@Override
public Collection<Row> rows(String requestParameterType) {
Collection<Row> rows = super.rows(null);
for (TypeDescription member : members) {
if (member.isAvailable()) {
rows.addAll(member.rows(requestParameterType));
}
}
return rows;
}
}
......@@ -199,7 +199,7 @@ public abstract class TypeDescription {
* @return the collection
*/
public Collection<Row> rows() {
return rows(null);
return this.rows(null);
}
public void accept(Comment comment) {
......
package com.kim.apidoc.core.parser;
import com.github.javaparser.ast.comments.JavadocComment;
import com.kim.apidoc.core.schema.Chapter;
import com.kim.apidoc.core.schema.Node;
import com.kim.apidoc.core.schema.Project;
......@@ -30,13 +31,14 @@ public class VisitorParser extends VoidVisitorAdapter<Node> {
/**
* 类或者接口声明
*
* @param classOrInterfaceDeclaration
* @param arg
*/
@Override
public void visit(final ClassOrInterfaceDeclaration classOrInterfaceDeclaration, final Node arg) {
if (arg instanceof Project && parserStrategy.accept(classOrInterfaceDeclaration)) {
if (arg instanceof Project) {
Project project = (Project) arg;
// 章节
Chapter chapter = new Chapter();
......@@ -44,17 +46,25 @@ public class VisitorParser extends VoidVisitorAdapter<Node> {
chapter.setName(classOrInterfaceDeclaration.getNameAsString());
classOrInterfaceDeclaration.getComment().ifPresent(chapter::accept);
OptionalHelper.any(chapter.getTag("book"),chapter.getTag("group"))
OptionalHelper.any(chapter.getTag("book"), chapter.getTag("group"))
.ifPresent(tag -> chapter.setBookName(tag.getContent()));
parserStrategy.visit(classOrInterfaceDeclaration, chapter);
if (parserStrategy.accept(classOrInterfaceDeclaration)) {
parserStrategy.visit(classOrInterfaceDeclaration, chapter);
}
project.addChapter(chapter);
super.visit(classOrInterfaceDeclaration, chapter);
}
}
@Override
public void visit(JavadocComment n, Node arg) {
super.visit(n, arg);
}
/**
* 方法声明
*
* @param methodDeclaration
* @param arg
*/
......
......@@ -60,7 +60,7 @@ ${section.getParameterString()}
| Field | Type | Request Type | Required | Condition | Default | Description |
| :------- | :----- | :----- |:-------- |:-------- | :------ | :---------- |
<#list section.requestRows as rowKey,rowValue>
| ${rowValue.key!''} | ${rowValue.type!''} | ${rowValue.requestParameterType!''} |${rowValue.required?string('true','false')} | ${rowValue.condition!''} | ${rowValue.def!''} | ${rowValue.remark!''} |
| ${rowValue.key!''} | ${rowValue.type!''} | **${rowValue.requestParameterType!''}** |${rowValue.required?string('true','false')} | ${rowValue.condition!''} | ${rowValue.def!''} | ${rowValue.remark!''} |
</#list>
</#if>
<#-- 响应-->
......
......@@ -3,6 +3,14 @@ package com.kim.apidoc.example.common;
import lombok.Getter;
import lombok.Setter;
/**
* The type Result data.
*
* @param <T> the type parameter
* @author fengyuchenglun
* @version 1.0.0
* @resultData
*/
@Setter
@Getter
public class ResultData<T> {
......@@ -11,13 +19,33 @@ public class ResultData<T> {
* 返回码
*/
int code;
//返回信息
/**
* The Msg.
*/
//返回信息
String msg;
/**
* The Data.
*/
T data;
/**
* Ok result data.
*
* @param <T> the type parameter
* @return the result data
*/
public static <T> ResultData<T> ok(){
return ok(null);
}
/**
* Ok result data.
*
* @param <T> the type parameter
* @param data the data
* @return the result data
*/
public static <T> ResultData<T> ok(T data){
ResultData<T> resultData = new ResultData<>();
resultData.code = 0;
......
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.ResultData;
import com.kim.apidoc.example.common.User;
import com.kim.apidoc.example.common.UserQuery;
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;
......@@ -25,11 +26,12 @@ public class KimUserController {
* 用户详情信息
* 主动根据id获取用户的信息
*
* @param userQuery the user query
* @param id the id
* @param query the query
* @return result data
*/
@GetMapping(value = "/{id}")
public ResultData<User> detail(UserQuery userQuery) {
public ResultData<User> detail(@PathVariable String id, Query query) {
User user = new User();
return ResultData.ok(user);
}
......
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