This commit is contained in:
@@ -126,6 +126,7 @@ public class ApiDocs extends HttpBaseServlet {
|
|||||||
parammap.put("type", ptype.getName() + (isarray ? "[]" : ""));
|
parammap.put("type", ptype.getName() + (isarray ? "[]" : ""));
|
||||||
parammap.put("src", param.src());
|
parammap.put("src", param.src());
|
||||||
parammap.put("comment", param.comment());
|
parammap.put("comment", param.comment());
|
||||||
|
parammap.put("required", param.required());
|
||||||
paramsList.add(parammap);
|
paramsList.add(parammap);
|
||||||
if (ptype.isPrimitive() || ptype == String.class) continue;
|
if (ptype.isPrimitive() || ptype == String.class) continue;
|
||||||
if (typesmap.containsKey(ptype.getName())) continue;
|
if (typesmap.containsKey(ptype.getName())) continue;
|
||||||
@@ -188,7 +189,7 @@ public class ApiDocs extends HttpBaseServlet {
|
|||||||
in = new FileInputStream(doctemplate);
|
in = new FileInputStream(doctemplate);
|
||||||
}
|
}
|
||||||
if (in == null) in = ApiDocs.class.getResourceAsStream("apidoc-template.html");
|
if (in == null) in = ApiDocs.class.getResourceAsStream("apidoc-template.html");
|
||||||
String content = Utility.read(in).replace("${content}", json);
|
String content = Utility.read(in).replace("'${content}'", json);
|
||||||
in.close();
|
in.close();
|
||||||
FileOutputStream outhtml = new FileOutputStream(new File(app.getHome(), "apidoc.html"));
|
FileOutputStream outhtml = new FileOutputStream(new File(app.getHome(), "apidoc.html"));
|
||||||
outhtml.write(content.getBytes("UTF-8"));
|
outhtml.write(content.getBytes("UTF-8"));
|
||||||
|
|||||||
@@ -29,7 +29,7 @@
|
|||||||
var servlet = jsoncontent.servers[i].servlets[j];
|
var servlet = jsoncontent.servers[i].servlets[j];
|
||||||
if (html.length > 2) html.push(' <tr><th colspan="5" 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="5" 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><th>输 出</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>');
|
||||||
@@ -47,9 +47,10 @@
|
|||||||
if (param.name == '&') {
|
if (param.name == '&') {
|
||||||
paramshtml.push('<tr><td style="font-size:12px;">内置 </td><td> ' + t + '</td><td> 当前用户</td></tr>');
|
paramshtml.push('<tr><td style="font-size:12px;">内置 </td><td> ' + t + '</td><td> 当前用户</td></tr>');
|
||||||
} else {
|
} else {
|
||||||
var c = ' style="font-weight:bold;"';
|
var w = param.required ? "font-weight:bold;" : "";
|
||||||
if (param.src == "HEADER") c = ' style="color:red;font-weight:bold;"';
|
var c = ' style="' + w + '"';
|
||||||
if (param.src == "COOKIE") c = ' style="color:blue;font-weight:bold;"';
|
if (param.src == "HEADER") c = ' style="color:red;' + w + '"';
|
||||||
|
if (param.src == "COOKIE") c = ' style="color:blue;' + w + '"';
|
||||||
paramshtml.push('<tr><td ' + c + '> ' + param.name + ' </td><td> ' + t + '</td><td> ' + param.comment + '</td></tr>');
|
paramshtml.push('<tr><td ' + c + '> ' + param.name + ' </td><td> ' + t + '</td><td> ' + param.comment + '</td></tr>');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -90,7 +91,7 @@
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
var jsoncontent = ${content};
|
var jsoncontent = '${content}'; //这里必须要用单引号引起来
|
||||||
document.write(createhtml(jsoncontent));
|
document.write(createhtml(jsoncontent));
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
|
|||||||
@@ -89,6 +89,8 @@ public abstract class HttpBaseServlet extends HttpServlet {
|
|||||||
ParamSourceType src() default ParamSourceType.PARAMETER; //参数来源类型
|
ParamSourceType src() default ParamSourceType.PARAMETER; //参数来源类型
|
||||||
|
|
||||||
int radix() default 10; //转换数字byte/short/int/long时所用的进制数, 默认10进制
|
int radix() default 10; //转换数字byte/short/int/long时所用的进制数, 默认10进制
|
||||||
|
|
||||||
|
boolean required() default true; //参数是否必传
|
||||||
}
|
}
|
||||||
|
|
||||||
@Documented
|
@Documented
|
||||||
|
|||||||
@@ -262,6 +262,7 @@ public final class Rest {
|
|||||||
final Class ptype = param.getType();
|
final Class ptype = param.getType();
|
||||||
String n = null;
|
String n = null;
|
||||||
String comment = "";
|
String comment = "";
|
||||||
|
boolean required = true;
|
||||||
int radix = 10;
|
int radix = 10;
|
||||||
|
|
||||||
RestHeader annhead = param.getAnnotation(RestHeader.class);
|
RestHeader annhead = param.getAnnotation(RestHeader.class);
|
||||||
@@ -297,6 +298,7 @@ public final class Rest {
|
|||||||
RestParam annpara = param.getAnnotation(RestParam.class);
|
RestParam annpara = param.getAnnotation(RestParam.class);
|
||||||
if (annpara != null) radix = annpara.radix();
|
if (annpara != null) radix = annpara.radix();
|
||||||
if (annpara != null) comment = annpara.comment();
|
if (annpara != null) comment = annpara.comment();
|
||||||
|
if (annpara != null) required = annpara.required();
|
||||||
if (n == null) n = (annpara == null || annpara.name().isEmpty()) ? null : annpara.name();
|
if (n == null) n = (annpara == null || annpara.name().isEmpty()) ? null : annpara.name();
|
||||||
if (n == null && ptype == userType) n = "&"; //用户类型特殊处理
|
if (n == null && ptype == userType) n = "&"; //用户类型特殊处理
|
||||||
if (n == null) {
|
if (n == null) {
|
||||||
@@ -312,7 +314,7 @@ public final class Rest {
|
|||||||
&& (entry.name.startsWith("find") || entry.name.startsWith("delete")) && params.length == 1) {
|
&& (entry.name.startsWith("find") || entry.name.startsWith("delete")) && params.length == 1) {
|
||||||
if (ptype.isPrimitive() || ptype == String.class) n = "#";
|
if (ptype.isPrimitive() || ptype == String.class) n = "#";
|
||||||
}
|
}
|
||||||
paramlist.add(new Object[]{param, n, ptype, radix, comment, annpara, annsid, annaddr, annhead, anncookie});
|
paramlist.add(new Object[]{param, n, ptype, radix, comment, required, annpara, annsid, annaddr, annhead, anncookie});
|
||||||
}
|
}
|
||||||
|
|
||||||
Map<String, Object> actionMap = new LinkedHashMap<>();
|
Map<String, Object> actionMap = new LinkedHashMap<>();
|
||||||
@@ -354,9 +356,9 @@ public final class Rest {
|
|||||||
av0 = mv.visitAnnotation(webparamsDesc, true);
|
av0 = mv.visitAnnotation(webparamsDesc, true);
|
||||||
AnnotationVisitor av1 = av0.visitArray("value");
|
AnnotationVisitor av1 = av0.visitArray("value");
|
||||||
//设置 WebParam
|
//设置 WebParam
|
||||||
for (Object[] ps : paramlist) { //{param, n, ptype, radix, comment, annpara, annsid, annaddr, annhead, anncookie}
|
for (Object[] ps : paramlist) { //{param, n, ptype, radix, comment, required, annpara, annsid, annaddr, annhead, anncookie}
|
||||||
final boolean ishead = ((RestHeader) ps[8]) != null; //是否取getHeader 而不是 getParameter
|
final boolean ishead = ((RestHeader) ps[9]) != null; //是否取getHeader 而不是 getParameter
|
||||||
final boolean iscookie = ((RestCookie) ps[9]) != null; //是否取getCookie
|
final boolean iscookie = ((RestCookie) ps[10]) != null; //是否取getCookie
|
||||||
|
|
||||||
AnnotationVisitor av2 = av1.visitAnnotation(null, webparamDesc);
|
AnnotationVisitor av2 = av1.visitAnnotation(null, webparamDesc);
|
||||||
av2.visit("name", (String) ps[1]);
|
av2.visit("name", (String) ps[1]);
|
||||||
@@ -365,6 +367,7 @@ public final class Rest {
|
|||||||
av2.visitEnum("src", sourcetypeDesc, ishead ? HttpBaseServlet.ParamSourceType.HEADER.name()
|
av2.visitEnum("src", sourcetypeDesc, ishead ? HttpBaseServlet.ParamSourceType.HEADER.name()
|
||||||
: (iscookie ? HttpBaseServlet.ParamSourceType.COOKIE.name() : HttpBaseServlet.ParamSourceType.PARAMETER.name()));
|
: (iscookie ? HttpBaseServlet.ParamSourceType.COOKIE.name() : HttpBaseServlet.ParamSourceType.PARAMETER.name()));
|
||||||
av2.visit("comment", (String) ps[4]);
|
av2.visit("comment", (String) ps[4]);
|
||||||
|
av2.visit("required", (Boolean) ps[5]);
|
||||||
av2.visitEnd();
|
av2.visitEnd();
|
||||||
}
|
}
|
||||||
av1.visitEnd();
|
av1.visitEnd();
|
||||||
@@ -377,11 +380,12 @@ public final class Rest {
|
|||||||
Class ptype = (Class) ps[2];
|
Class ptype = (Class) ps[2];
|
||||||
int radix = (Integer) ps[3];
|
int radix = (Integer) ps[3];
|
||||||
String comment = (String) ps[4];
|
String comment = (String) ps[4];
|
||||||
RestParam annpara = (RestParam) ps[5];
|
boolean required = (Boolean) ps[5];
|
||||||
RestSessionid annsid = (RestSessionid) ps[6];
|
RestParam annpara = (RestParam) ps[6];
|
||||||
RestAddress annaddr = (RestAddress) ps[7];
|
RestSessionid annsid = (RestSessionid) ps[7];
|
||||||
RestHeader annhead = (RestHeader) ps[8];
|
RestAddress annaddr = (RestAddress) ps[8];
|
||||||
RestCookie anncookie = (RestCookie) ps[9];
|
RestHeader annhead = (RestHeader) ps[9];
|
||||||
|
RestCookie anncookie = (RestCookie) ps[10];
|
||||||
|
|
||||||
final boolean ishead = annhead != null; //是否取getHeader 而不是 getParameter
|
final boolean ishead = annhead != null; //是否取getHeader 而不是 getParameter
|
||||||
final boolean iscookie = anncookie != null; //是否取getCookie
|
final boolean iscookie = anncookie != null; //是否取getCookie
|
||||||
|
|||||||
@@ -28,5 +28,7 @@ public @interface RestParam {
|
|||||||
|
|
||||||
int radix() default 10; //转换数字byte/short/int/long时所用的进制数, 默认10进制
|
int radix() default 10; //转换数字byte/short/int/long时所用的进制数, 默认10进制
|
||||||
|
|
||||||
|
boolean required() default true; //参数是否必传
|
||||||
|
|
||||||
String comment() default ""; //备注描述
|
String comment() default ""; //备注描述
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user