This commit is contained in:
@@ -62,62 +62,71 @@ public class ApiDocs extends HttpBaseServlet {
|
|||||||
|
|
||||||
List<Map> actionsList = new ArrayList<>();
|
List<Map> actionsList = new ArrayList<>();
|
||||||
servletmap.put("actions", actionsList);
|
servletmap.put("actions", actionsList);
|
||||||
for (Method method : servlet.getClass().getMethods()) {
|
final Class selfClz = servlet.getClass();
|
||||||
if (method.getParameterCount() != 2) continue;
|
Class clz = servlet.getClass();
|
||||||
WebAction action = method.getAnnotation(WebAction.class);
|
HashSet<String> actionurls = new HashSet<>();
|
||||||
if (action == null) continue;
|
do {
|
||||||
final Map<String, Object> actionmap = new LinkedHashMap<>();
|
if (Modifier.isAbstract(clz.getModifiers())) break;
|
||||||
actionmap.put("url", prefix + action.url());
|
for (Method method : clz.getMethods()) {
|
||||||
actionmap.put("auth", method.getAnnotation(AuthIgnore.class) == null);
|
if (method.getParameterCount() != 2) continue;
|
||||||
actionmap.put("actionid", action.actionid());
|
WebAction action = method.getAnnotation(WebAction.class);
|
||||||
actionmap.put("comment", action.comment());
|
if (action == null) continue;
|
||||||
List<Map> paramsList = new ArrayList<>();
|
if (!action.inherited() && selfClz != clz) continue; //忽略不被继承的方法
|
||||||
actionmap.put("params", paramsList);
|
final Map<String, Object> actionmap = new LinkedHashMap<>();
|
||||||
for (WebParam param : method.getAnnotationsByType(WebParam.class)) {
|
if (actionurls.contains(action.url())) continue;
|
||||||
final Map<String, Object> parammap = new LinkedHashMap<>();
|
actionmap.put("url", prefix + action.url());
|
||||||
final boolean isarray = param.type().isArray();
|
actionurls.add(action.url());
|
||||||
final Class ptype = isarray ? param.type().getComponentType() : param.type();
|
actionmap.put("auth", method.getAnnotation(AuthIgnore.class) == null);
|
||||||
parammap.put("name", param.name());
|
actionmap.put("actionid", action.actionid());
|
||||||
parammap.put("radix", param.radix());
|
actionmap.put("comment", action.comment());
|
||||||
parammap.put("type", ptype.getName() + (isarray ? "[]" : ""));
|
List<Map> paramsList = new ArrayList<>();
|
||||||
parammap.put("src", param.src());
|
actionmap.put("params", paramsList);
|
||||||
parammap.put("comment", param.comment());
|
for (WebParam param : method.getAnnotationsByType(WebParam.class)) {
|
||||||
paramsList.add(parammap);
|
final Map<String, Object> parammap = new LinkedHashMap<>();
|
||||||
if (ptype.isPrimitive() || ptype == String.class) continue;
|
final boolean isarray = param.type().isArray();
|
||||||
if (typesmap.containsKey(ptype.getName())) continue;
|
final Class ptype = isarray ? param.type().getComponentType() : param.type();
|
||||||
|
parammap.put("name", param.name());
|
||||||
|
parammap.put("radix", param.radix());
|
||||||
|
parammap.put("type", ptype.getName() + (isarray ? "[]" : ""));
|
||||||
|
parammap.put("src", param.src());
|
||||||
|
parammap.put("comment", param.comment());
|
||||||
|
paramsList.add(parammap);
|
||||||
|
if (ptype.isPrimitive() || ptype == String.class) continue;
|
||||||
|
if (typesmap.containsKey(ptype.getName())) continue;
|
||||||
|
|
||||||
final Map<String, Map<String, String>> typemap = new LinkedHashMap<>();
|
final Map<String, Map<String, String>> typemap = new LinkedHashMap<>();
|
||||||
Class loop = ptype;
|
Class loop = ptype;
|
||||||
do {
|
do {
|
||||||
if (loop == null || loop.isInterface()) break;
|
if (loop == null || loop.isInterface()) break;
|
||||||
for (Field field : loop.getDeclaredFields()) {
|
for (Field field : loop.getDeclaredFields()) {
|
||||||
if (Modifier.isFinal(field.getModifiers())) continue;
|
if (Modifier.isFinal(field.getModifiers())) continue;
|
||||||
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.getGenericType().getTypeName());
|
fieldmap.put("type", field.getType().isArray() ? (field.getType().getComponentType().getName() + "[]") : field.getGenericType().getTypeName());
|
||||||
|
|
||||||
Comment comment = field.getAnnotation(Comment.class);
|
Comment comment = field.getAnnotation(Comment.class);
|
||||||
if (comment != null) {
|
if (comment != null) {
|
||||||
fieldmap.put("comment", comment.value());
|
fieldmap.put("comment", comment.value());
|
||||||
} else {
|
} else {
|
||||||
Column col = field.getAnnotation(Column.class);
|
Column col = field.getAnnotation(Column.class);
|
||||||
if (col != null) fieldmap.put("comment", col.comment());
|
if (col != null) fieldmap.put("comment", col.comment());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (servlet.getClass().getAnnotation(Rest.RestDynamic.class) != null) {
|
||||||
|
if (field.getAnnotation(RestAddress.class) != null) continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
typemap.put(field.getName(), fieldmap);
|
||||||
}
|
}
|
||||||
|
} while ((loop = loop.getSuperclass()) != Object.class);
|
||||||
|
|
||||||
if (servlet.getClass().getAnnotation(Rest.RestDynamic.class) != null) {
|
typesmap.put(ptype.getName(), typemap);
|
||||||
if (field.getAnnotation(RestAddress.class) != null) continue;
|
}
|
||||||
}
|
actionmap.put("result", action.result());
|
||||||
|
actionsList.add(actionmap);
|
||||||
typemap.put(field.getName(), fieldmap);
|
|
||||||
}
|
|
||||||
} while ((loop = loop.getSuperclass()) != Object.class);
|
|
||||||
|
|
||||||
typesmap.put(ptype.getName(), typemap);
|
|
||||||
}
|
}
|
||||||
actionmap.put("result", action.result());
|
} while ((clz = clz.getSuperclass()) != HttpServlet.class);
|
||||||
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")));
|
||||||
servletsList.add(servletmap);
|
servletsList.add(servletmap);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -123,6 +123,7 @@ public abstract class HttpBaseServlet extends HttpServlet {
|
|||||||
|
|
||||||
String result() default "Object"; //输出结果的数据类型
|
String result() default "Object"; //输出结果的数据类型
|
||||||
|
|
||||||
|
boolean inherited() default true; //是否能被继承, 当 HttpBaseServlet 被继承后该方法是否能被子类继承
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -220,6 +221,7 @@ public abstract class HttpBaseServlet extends HttpServlet {
|
|||||||
final int serviceid = module == null ? 0 : module.moduleid();
|
final int serviceid = module == null ? 0 : module.moduleid();
|
||||||
final HashMap<String, Entry> map = new HashMap<>();
|
final HashMap<String, Entry> map = new HashMap<>();
|
||||||
HashMap<String, Class> nameset = new HashMap<>();
|
HashMap<String, Class> nameset = new HashMap<>();
|
||||||
|
final Class selfClz = this.getClass();
|
||||||
Class clz = this.getClass();
|
Class clz = this.getClass();
|
||||||
do {
|
do {
|
||||||
if (Modifier.isAbstract(clz.getModifiers())) break;
|
if (Modifier.isAbstract(clz.getModifiers())) break;
|
||||||
@@ -238,6 +240,7 @@ public abstract class HttpBaseServlet extends HttpServlet {
|
|||||||
|
|
||||||
final WebAction action = method.getAnnotation(WebAction.class);
|
final WebAction action = method.getAnnotation(WebAction.class);
|
||||||
if (action == null) continue;
|
if (action == null) continue;
|
||||||
|
if (!action.inherited() && selfClz != clz) continue; //忽略不被继承的方法
|
||||||
final int actionid = action.actionid();
|
final int actionid = action.actionid();
|
||||||
final String name = action.url().trim();
|
final String name = action.url().trim();
|
||||||
if (nameset.containsKey(name)) {
|
if (nameset.containsKey(name)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user