support #76, fix gitee #I2APZN
This commit is contained in:
parent
6ae2920480
commit
7a9cd812dd
|
@ -129,7 +129,7 @@ smart-doc官方目前已经开发完成[Maven插件](https://gitee.com/smart-doc
|
||||||
"codeField": "code",//错误码的code码字段名称
|
"codeField": "code",//错误码的code码字段名称
|
||||||
"descField": "message"//错误码的描述信息对应的字段名
|
"descField": "message"//错误码的描述信息对应的字段名
|
||||||
}],
|
}],
|
||||||
"revisionLogs": [{
|
"revisionLogs": [{ //文档变更记录
|
||||||
"version": "1.0", //文档版本号
|
"version": "1.0", //文档版本号
|
||||||
"status": "update", //变更操作状态,一般为:创建、更新等
|
"status": "update", //变更操作状态,一般为:创建、更新等
|
||||||
"author": "author", //文档变更作者
|
"author": "author", //文档变更作者
|
||||||
|
|
|
@ -35,6 +35,7 @@ import com.thoughtworks.qdox.model.JavaClass;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import static com.power.doc.constants.DocGlobalConstants.DEFAULT_SERVER_URL;
|
import static com.power.doc.constants.DocGlobalConstants.DEFAULT_SERVER_URL;
|
||||||
|
|
||||||
|
@ -43,6 +44,8 @@ import static com.power.doc.constants.DocGlobalConstants.DEFAULT_SERVER_URL;
|
||||||
*/
|
*/
|
||||||
public class ProjectDocConfigBuilder {
|
public class ProjectDocConfigBuilder {
|
||||||
|
|
||||||
|
private static Logger log = Logger.getLogger(ProjectDocConfigBuilder.class.getName());
|
||||||
|
|
||||||
private JavaProjectBuilder javaProjectBuilder;
|
private JavaProjectBuilder javaProjectBuilder;
|
||||||
|
|
||||||
private Map<String, JavaClass> classFilesMap = new ConcurrentHashMap<>();
|
private Map<String, JavaClass> classFilesMap = new ConcurrentHashMap<>();
|
||||||
|
@ -75,7 +78,11 @@ public class ProjectDocConfigBuilder {
|
||||||
this.setHighlightStyle();
|
this.setHighlightStyle();
|
||||||
javaProjectBuilder.setEncoding(Charset.DEFAULT_CHARSET);
|
javaProjectBuilder.setEncoding(Charset.DEFAULT_CHARSET);
|
||||||
this.javaProjectBuilder = javaProjectBuilder;
|
this.javaProjectBuilder = javaProjectBuilder;
|
||||||
|
try {
|
||||||
this.loadJavaSource(apiConfig.getSourceCodePaths(), this.javaProjectBuilder);
|
this.loadJavaSource(apiConfig.getSourceCodePaths(), this.javaProjectBuilder);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.warning(e.getMessage());
|
||||||
|
}
|
||||||
this.initClassFilesMap();
|
this.initClassFilesMap();
|
||||||
this.initCustomResponseFieldsMap(apiConfig);
|
this.initCustomResponseFieldsMap(apiConfig);
|
||||||
this.initReplaceClassMap(apiConfig);
|
this.initReplaceClassMap(apiConfig);
|
||||||
|
|
|
@ -299,6 +299,12 @@ public class JsonBuildHelper {
|
||||||
data0.append("[{\"mapKey\":{}}],");
|
data0.append("[{\"mapKey\":{}}],");
|
||||||
continue out;
|
continue out;
|
||||||
}
|
}
|
||||||
|
JavaClass arraySubClass = builder.getJavaProjectBuilder().getClassByName(gicName);
|
||||||
|
if (arraySubClass.isEnum()) {
|
||||||
|
Object value = JavaClassUtil.getEnumValue(arraySubClass, Boolean.FALSE);
|
||||||
|
data0.append("[").append(value).append("],");
|
||||||
|
continue out;
|
||||||
|
}
|
||||||
data0.append("[").append(buildJson(gicName, fieldGicName, isResp, nextLevel, registryClasses, builder)).append("]").append(",");
|
data0.append("[").append(buildJson(gicName, fieldGicName, isResp, nextLevel, registryClasses, builder)).append("]").append(",");
|
||||||
} else {
|
} else {
|
||||||
data0.append("[{\"$ref\":\"..\"}]").append(",");
|
data0.append("[{\"$ref\":\"..\"}]").append(",");
|
||||||
|
|
|
@ -235,25 +235,21 @@ public class ParamsBuildHelper {
|
||||||
ApiParam param = ApiParam.of().setField(pre + fieldName).setPid(pid);
|
ApiParam param = ApiParam.of().setField(pre + fieldName).setPid(pid);
|
||||||
JavaClass javaClass = projectBuilder.getJavaProjectBuilder().getClassByName(subTypeName);
|
JavaClass javaClass = projectBuilder.getJavaProjectBuilder().getClassByName(subTypeName);
|
||||||
if (javaClass.isEnum()) {
|
if (javaClass.isEnum()) {
|
||||||
String enumComments = javaClass.getComment();
|
comment = comment + handleEnumComment(javaClass, projectBuilder);
|
||||||
if (projectBuilder.getApiConfig().getInlineEnum()) {
|
|
||||||
ApiDataDictionary dataDictionary = projectBuilder.getApiConfig().getDataDictionary(javaClass.getSimpleName());
|
|
||||||
if (dataDictionary == null) {
|
|
||||||
comment = comment + JavaClassUtil.getEnumParams(javaClass);
|
|
||||||
} else {
|
|
||||||
comment = comment + "(enum:" + dictionaryListComment(dataDictionary) + ")";
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
enumComments = DocUtil.replaceNewLineToHtmlBr(enumComments);
|
|
||||||
comment = comment + "<br/>" + JavaClassUtil.getEnumParams(javaClass) + "<br/>";
|
|
||||||
if (enumComments != null) {
|
|
||||||
comment = comment + "(See: " + enumComments + ")";
|
|
||||||
}
|
|
||||||
comment = StringUtil.removeQuotes(comment);
|
|
||||||
|
|
||||||
}
|
|
||||||
param.setType(DocGlobalConstants.ENUM);
|
param.setType(DocGlobalConstants.ENUM);
|
||||||
}
|
}
|
||||||
|
if (JavaClassValidateUtil.isCollection(subTypeName)) {
|
||||||
|
String gNameTemp = fieldGicName;
|
||||||
|
if (globGicName.length > 0 && JAVA_LIST_FULLY.equals(gNameTemp)) {
|
||||||
|
gNameTemp = gNameTemp + "<T>";
|
||||||
|
}
|
||||||
|
String[] gNameArr = DocClassUtil.getSimpleGicName(gNameTemp);
|
||||||
|
if (gNameArr.length >= 0) {
|
||||||
|
String gName = DocClassUtil.getSimpleGicName(gNameTemp)[0];
|
||||||
|
JavaClass javaClass1 = projectBuilder.getJavaProjectBuilder().getClassByName(gName);
|
||||||
|
comment = comment + handleEnumComment(javaClass1, projectBuilder);
|
||||||
|
}
|
||||||
|
}
|
||||||
String appendComment = "";
|
String appendComment = "";
|
||||||
if (displayActualType) {
|
if (displayActualType) {
|
||||||
if (globGicName.length > 0) {
|
if (globGicName.length > 0) {
|
||||||
|
@ -424,7 +420,8 @@ public class ParamsBuildHelper {
|
||||||
public static String dictionaryListComment(ApiDataDictionary dictionary) {
|
public static String dictionaryListComment(ApiDataDictionary dictionary) {
|
||||||
List<EnumDictionary> enumDataDict = dictionary.getEnumDataDict();
|
List<EnumDictionary> enumDataDict = dictionary.getEnumDataDict();
|
||||||
return enumDataDict.stream().map(apiDataDictionary ->
|
return enumDataDict.stream().map(apiDataDictionary ->
|
||||||
apiDataDictionary.getValue() + ":" + apiDataDictionary.getDesc()
|
apiDataDictionary.getName() + "-(\"" + apiDataDictionary.getValue() + "\",\""
|
||||||
|
+ apiDataDictionary.getDesc() + "\")"
|
||||||
).collect(Collectors.joining(","));
|
).collect(Collectors.joining(","));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -448,4 +445,28 @@ public class ParamsBuildHelper {
|
||||||
param.setId(paramList.size() + param.getPid() + 1);
|
param.setId(paramList.size() + param.getPid() + 1);
|
||||||
paramList.add(param);
|
paramList.add(param);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static String handleEnumComment(JavaClass javaClass, ProjectDocConfigBuilder projectBuilder) {
|
||||||
|
String comment = "";
|
||||||
|
if (!javaClass.isEnum()) {
|
||||||
|
return comment;
|
||||||
|
}
|
||||||
|
String enumComments = javaClass.getComment();
|
||||||
|
if (projectBuilder.getApiConfig().getInlineEnum()) {
|
||||||
|
ApiDataDictionary dataDictionary = projectBuilder.getApiConfig().getDataDictionary(javaClass.getSimpleName());
|
||||||
|
if (dataDictionary == null) {
|
||||||
|
comment = comment + "<br/>" + JavaClassUtil.getEnumParams(javaClass);
|
||||||
|
} else {
|
||||||
|
comment = comment + "[enum:" + dictionaryListComment(dataDictionary) + "]";
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
enumComments = DocUtil.replaceNewLineToHtmlBr(enumComments);
|
||||||
|
comment = comment + "<br/>" + JavaClassUtil.getEnumParams(javaClass) + "<br/>";
|
||||||
|
if (enumComments != null) {
|
||||||
|
comment = comment + "(See: " + enumComments + ")";
|
||||||
|
}
|
||||||
|
comment = StringUtil.removeQuotes(comment);
|
||||||
|
}
|
||||||
|
return comment;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,7 +52,9 @@ import static com.power.doc.constants.DocTags.IGNORE;
|
||||||
* @author yu 2019/12/21.
|
* @author yu 2019/12/21.
|
||||||
*/
|
*/
|
||||||
public class SpringBootDocBuildTemplate implements IDocBuildTemplate<ApiDoc> {
|
public class SpringBootDocBuildTemplate implements IDocBuildTemplate<ApiDoc> {
|
||||||
|
|
||||||
private static Logger log = Logger.getLogger(SpringBootDocBuildTemplate.class.getName());
|
private static Logger log = Logger.getLogger(SpringBootDocBuildTemplate.class.getName());
|
||||||
|
|
||||||
private List<ApiReqHeader> headers;
|
private List<ApiReqHeader> headers;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -601,7 +603,9 @@ public class SpringBootDocBuildTemplate implements IDocBuildTemplate<ApiDoc> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
AnnotationValue annotationRequired = annotation.getProperty(DocAnnotationConstants.REQUIRED_PROP);
|
AnnotationValue annotationRequired = annotation.getProperty(DocAnnotationConstants.REQUIRED_PROP);
|
||||||
if (null == annotationRequired) {
|
if (Objects.nonNull(annotationRequired)) {
|
||||||
|
strRequired = annotationRequired.toString();
|
||||||
|
} else {
|
||||||
strRequired = "true";
|
strRequired = "true";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -184,6 +184,14 @@ public class DocClassUtil {
|
||||||
return "string";
|
return "string";
|
||||||
case "java.util.List":
|
case "java.util.List":
|
||||||
case "list":
|
case "list":
|
||||||
|
case "java.util.Set":
|
||||||
|
case "set":
|
||||||
|
case "java.util.LinkedList":
|
||||||
|
case "linkedlist":
|
||||||
|
case "java.util.ArrayList":
|
||||||
|
case "arraylist":
|
||||||
|
case "java.util.TreeSet":
|
||||||
|
case "treeset":
|
||||||
return "array";
|
return "array";
|
||||||
case "java.lang.Integer":
|
case "java.lang.Integer":
|
||||||
case "integer":
|
case "integer":
|
||||||
|
|
|
@ -246,14 +246,14 @@ function toCurl(request) {
|
||||||
throw "Request is not an object";
|
throw "Request is not an object";
|
||||||
}
|
}
|
||||||
// default is a GET request
|
// default is a GET request
|
||||||
const cmd = ['curl', '-X', request.type || 'GET'];
|
const cmd = ["curl", "-X", request.type || "GET"];
|
||||||
|
|
||||||
if (request.url.indexOf('https') == 0) {
|
if (request.url.indexOf('https') == 0) {
|
||||||
cmd.push('-k');
|
cmd.push("-k");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (request.data && request.data.length > 0) {
|
if (request.data && request.data.length > 0) {
|
||||||
cmd.push('-H');
|
cmd.push("-H");
|
||||||
cmd.push("'Content-Type: application/json; charset=utf-8'");
|
cmd.push("'Content-Type: application/json; charset=utf-8'");
|
||||||
}
|
}
|
||||||
// append request headers
|
// append request headers
|
||||||
|
@ -261,7 +261,7 @@ function toCurl(request) {
|
||||||
if (typeof request.headers == 'object') {
|
if (typeof request.headers == 'object') {
|
||||||
for (let key in request.headers) {
|
for (let key in request.headers) {
|
||||||
if (Object.prototype.hasOwnProperty.call(request.headers, key)) {
|
if (Object.prototype.hasOwnProperty.call(request.headers, key)) {
|
||||||
cmd.push('-H');
|
cmd.push("H");
|
||||||
headerValue = request.headers[key];
|
headerValue = request.headers[key];
|
||||||
if (headerValue.value == '') {
|
if (headerValue.value == '') {
|
||||||
cmd.push("'" + key + "'");
|
cmd.push("'" + key + "'");
|
||||||
|
@ -273,11 +273,19 @@ function toCurl(request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// display the response headers
|
// display the response headers
|
||||||
cmd.push('-i');
|
cmd.push("-i");
|
||||||
// append request url
|
// append request url
|
||||||
cmd.push(request.url);
|
let url = request.url;
|
||||||
|
if (!url.startsWith("http")) {
|
||||||
|
const protocol = window.document.location.protocol;
|
||||||
|
const domain = window.document.location.hostname;
|
||||||
|
const port = window.document.location.port;
|
||||||
|
url = protocol + "//" + domain + ":" + port + url;
|
||||||
|
}
|
||||||
|
cmd.push(url);
|
||||||
|
// append data
|
||||||
if (request.data && request.data.length > 0) {
|
if (request.data && request.data.length > 0) {
|
||||||
cmd.push('--data');
|
cmd.push("--data");
|
||||||
cmd.push("'" + request.data + "'");
|
cmd.push("'" + request.data + "'");
|
||||||
}
|
}
|
||||||
let curlCmd = "";
|
let curlCmd = "";
|
||||||
|
|
Loading…
Reference in New Issue