This commit is contained in:
@@ -92,7 +92,7 @@ public class RestDocs extends HttpBaseServlet {
|
|||||||
if (Modifier.isStatic(field.getModifiers())) continue;
|
if (Modifier.isStatic(field.getModifiers())) continue;
|
||||||
|
|
||||||
Map<String, String> fieldmap = new LinkedHashMap<>();
|
Map<String, String> fieldmap = new LinkedHashMap<>();
|
||||||
fieldmap.put("type", field.getType().isArray() ? (field.getType().getComponentType().getName()+"[]") : field.getType().getName());
|
fieldmap.put("type", field.getType().isArray() ? (field.getType().getComponentType().getName() + "[]") : field.getType().getName());
|
||||||
|
|
||||||
Comment comment = field.getAnnotation(Comment.class);
|
Comment comment = field.getAnnotation(Comment.class);
|
||||||
if (comment != null) fieldmap.put("comment", comment.value());
|
if (comment != null) fieldmap.put("comment", comment.value());
|
||||||
@@ -107,6 +107,8 @@ public class RestDocs extends HttpBaseServlet {
|
|||||||
|
|
||||||
typesmap.put(ptype.getName(), typemap);
|
typesmap.put(ptype.getName(), typemap);
|
||||||
}
|
}
|
||||||
|
actionmap.put("result", action.result().getName());
|
||||||
|
actionmap.put("ret", action.ret());
|
||||||
actionsList.add(actionmap);
|
actionsList.add(actionmap);
|
||||||
}
|
}
|
||||||
actionsList.sort((o1, o2) -> ((String) o1.get("url")).compareTo((String) o2.get("url")));
|
actionsList.sort((o1, o2) -> ((String) o1.get("url")).compareTo((String) o2.get("url")));
|
||||||
|
|||||||
@@ -27,9 +27,9 @@
|
|||||||
for (var i = 0; i < jsoncontent.servers.length; i++) {
|
for (var i = 0; i < jsoncontent.servers.length; i++) {
|
||||||
for (var j = 0; j < jsoncontent.servers[i].servlets.length; j++) {
|
for (var j = 0; j < jsoncontent.servers[i].servlets.length; j++) {
|
||||||
var servlet = jsoncontent.servers[i].servlets[j];
|
var servlet = jsoncontent.servers[i].servlets[j];
|
||||||
if (html.length > 2) html.push(' <tr><th colspan="4" style="border-bottom:0;"> </th></tr>');
|
if (html.length > 2) html.push(' <tr><th colspan="5" style="border-bottom:0;"> </th></tr>');
|
||||||
html.push(' <tr><th colspan="4" style="border-top:' + ((html.length > 2) ? 0 : 1) + ';">' + (servlet.comment || '未知模块') + '</th></tr>');
|
html.push(' <tr><th colspan="5" style="border-top:' + ((html.length > 2) ? 0 : 1) + ';">' + (servlet.comment || '未知模块') + '</th></tr>');
|
||||||
html.push(' <tr><th>请求URL</th><th>描 述</th><th>鉴 权</th><th>参 数 <span style="font-size:12px;">(红色: Header; 蓝色: Cookie)</span></th></tr>');
|
html.push(' <tr><th>请求URL</th><th>描 述</th><th>鉴 权</th><th>参 数 <span style="font-size:12px;">(红色: Header; 蓝色: Cookie)</span></th><th>输 出</th></tr>');
|
||||||
for (var k = 0; k < servlet.actions.length; k++) {
|
for (var k = 0; k < servlet.actions.length; k++) {
|
||||||
var action = servlet.actions[k];
|
var action = servlet.actions[k];
|
||||||
html.push(' <tr>');
|
html.push(' <tr>');
|
||||||
@@ -55,14 +55,16 @@
|
|||||||
}
|
}
|
||||||
paramshtml.push('</table>');
|
paramshtml.push('</table>');
|
||||||
html.push('<td class="s" style="padding:0 5px;">' + paramshtml.join('') + '</td>');
|
html.push('<td class="s" style="padding:0 5px;">' + paramshtml.join('') + '</td>');
|
||||||
|
var rt = action.result.substring(action.result.lastIndexOf('.') + 1);
|
||||||
|
html.push('<td>' + (action.ret ? ("RetResult<" + rt + ">") : rt) + '</td>');
|
||||||
html.push('</tr>');
|
html.push('</tr>');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (var type in classmap) {
|
for (var type in classmap) {
|
||||||
html.push(' <tr><th colspan="4" style="border-bottom:0;"> </th></tr>');
|
html.push(' <tr><th colspan="5" style="border-bottom:0;"> </th></tr>');
|
||||||
html.push(' <tr id="' + type + '"><th colspan="4" style="border-top:0;">' + type + '</th></tr>');
|
html.push(' <tr id="' + type + '"><th colspan="5" style="border-top:0;">' + type + '</th></tr>');
|
||||||
html.push(' <tr><td colspan="4"><table class="typetable">');
|
html.push(' <tr><td colspan="5"><table class="typetable">');
|
||||||
for (var fieldname in classmap[type]) {
|
for (var fieldname in classmap[type]) {
|
||||||
var field = classmap[type][fieldname];
|
var field = classmap[type][fieldname];
|
||||||
var t = field.type.substring(field.type.lastIndexOf('.') + 1);
|
var t = field.type.substring(field.type.lastIndexOf('.') + 1);
|
||||||
|
|||||||
@@ -113,6 +113,10 @@ public abstract class HttpBaseServlet extends HttpServlet {
|
|||||||
String comment() default ""; //备注描述
|
String comment() default ""; //备注描述
|
||||||
|
|
||||||
WebParam[] params() default {};
|
WebParam[] params() default {};
|
||||||
|
|
||||||
|
Class result() default Object.class; //输出结果的数据类型
|
||||||
|
|
||||||
|
boolean ret() default true; //是否为RetResult包装
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -194,7 +194,6 @@ public final class Rest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (entrys.isEmpty()) return null; //没有可WebAction的方法
|
if (entrys.isEmpty()) return null; //没有可WebAction的方法
|
||||||
Map<String, Object> actionMap = new LinkedHashMap<>();
|
|
||||||
for (final MappingEntry entry : entrys) {
|
for (final MappingEntry entry : entrys) {
|
||||||
final Method method = entry.mappingMethod;
|
final Method method = entry.mappingMethod;
|
||||||
final Class returnType = method.getReturnType();
|
final Class returnType = method.getReturnType();
|
||||||
@@ -301,6 +300,7 @@ public final class Rest {
|
|||||||
paramlist.add(new Object[]{param, n, ptype, radix, comment, annpara, annsid, annaddr, annhead, anncookie});
|
paramlist.add(new Object[]{param, n, ptype, radix, comment, annpara, annsid, annaddr, annhead, anncookie});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Map<String, Object> actionMap = new LinkedHashMap<>();
|
||||||
{
|
{
|
||||||
//设置 WebAction
|
//设置 WebAction
|
||||||
boolean reqpath = false;
|
boolean reqpath = false;
|
||||||
@@ -339,11 +339,22 @@ public final class Rest {
|
|||||||
}
|
}
|
||||||
av3.visitEnd();
|
av3.visitEnd();
|
||||||
}
|
}
|
||||||
|
boolean ret = returnType == RetResult.class;
|
||||||
|
java.lang.reflect.Type rt = method.getGenericReturnType();
|
||||||
|
boolean subrt = (ret && rt instanceof ParameterizedType);
|
||||||
|
java.lang.reflect.Type[] subts = subrt ? ((ParameterizedType) rt).getActualTypeArguments() : null;
|
||||||
|
Class cz = subts == null ? returnType
|
||||||
|
: (subts[0] instanceof Class ? (Class) subts[0] : (subts[0] instanceof ParameterizedType ? (Class) ((ParameterizedType) subts[0]).getRawType() : Object.class));
|
||||||
|
av0.visit("result", Type.getType(Type.getDescriptor(subrt ? cz : returnType)));
|
||||||
|
av0.visit("ret", ret);
|
||||||
|
|
||||||
av0.visitEnd();
|
av0.visitEnd();
|
||||||
actionMap.put("url", url);
|
actionMap.put("url", url);
|
||||||
actionMap.put("actionid", entry.actionid);
|
actionMap.put("actionid", entry.actionid);
|
||||||
actionMap.put("comment", entry.comment);
|
actionMap.put("comment", entry.comment);
|
||||||
actionMap.put("methods", entry.methods);
|
actionMap.put("methods", entry.methods);
|
||||||
|
actionMap.put("result", subrt ? cz.getName() : returnType.getName());
|
||||||
|
actionMap.put("ret", ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
List<Map<String, Object>> paramMaps = new ArrayList<>();
|
List<Map<String, Object>> paramMaps = new ArrayList<>();
|
||||||
|
|||||||
Reference in New Issue
Block a user