support #76, fix gitee #I2APZN

This commit is contained in:
oppofind 2020-12-25 00:33:27 +08:00
parent 6ae2920480
commit 7a9cd812dd
7 changed files with 82 additions and 28 deletions

View File

@ -129,7 +129,7 @@ smart-doc官方目前已经开发完成[Maven插件](https://gitee.com/smart-doc
"codeField": "code",//错误码的code码字段名称
"descField": "message"//错误码的描述信息对应的字段名
}],
"revisionLogs": [{
"revisionLogs": [{ //文档变更记录
"version": "1.0", //文档版本号
"status": "update", //变更操作状态,一般为:创建、更新等
"author": "author", //文档变更作者

View File

@ -35,6 +35,7 @@ import com.thoughtworks.qdox.model.JavaClass;
import java.io.File;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.logging.Logger;
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 {
private static Logger log = Logger.getLogger(ProjectDocConfigBuilder.class.getName());
private JavaProjectBuilder javaProjectBuilder;
private Map<String, JavaClass> classFilesMap = new ConcurrentHashMap<>();
@ -75,7 +78,11 @@ public class ProjectDocConfigBuilder {
this.setHighlightStyle();
javaProjectBuilder.setEncoding(Charset.DEFAULT_CHARSET);
this.javaProjectBuilder = javaProjectBuilder;
try {
this.loadJavaSource(apiConfig.getSourceCodePaths(), this.javaProjectBuilder);
} catch (Exception e) {
log.warning(e.getMessage());
}
this.initClassFilesMap();
this.initCustomResponseFieldsMap(apiConfig);
this.initReplaceClassMap(apiConfig);

View File

@ -299,6 +299,12 @@ public class JsonBuildHelper {
data0.append("[{\"mapKey\":{}}],");
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(",");
} else {
data0.append("[{\"$ref\":\"..\"}]").append(",");

View File

@ -235,25 +235,21 @@ public class ParamsBuildHelper {
ApiParam param = ApiParam.of().setField(pre + fieldName).setPid(pid);
JavaClass javaClass = projectBuilder.getJavaProjectBuilder().getClassByName(subTypeName);
if (javaClass.isEnum()) {
String enumComments = javaClass.getComment();
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);
}
comment = comment + handleEnumComment(javaClass, projectBuilder);
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 = "";
if (displayActualType) {
if (globGicName.length > 0) {
@ -424,7 +420,8 @@ public class ParamsBuildHelper {
public static String dictionaryListComment(ApiDataDictionary dictionary) {
List<EnumDictionary> enumDataDict = dictionary.getEnumDataDict();
return enumDataDict.stream().map(apiDataDictionary ->
apiDataDictionary.getValue() + ":" + apiDataDictionary.getDesc()
apiDataDictionary.getName() + "-(\"" + apiDataDictionary.getValue() + "\",\""
+ apiDataDictionary.getDesc() + "\")"
).collect(Collectors.joining(","));
}
@ -448,4 +445,28 @@ public class ParamsBuildHelper {
param.setId(paramList.size() + param.getPid() + 1);
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;
}
}

View File

@ -52,7 +52,9 @@ import static com.power.doc.constants.DocTags.IGNORE;
* @author yu 2019/12/21.
*/
public class SpringBootDocBuildTemplate implements IDocBuildTemplate<ApiDoc> {
private static Logger log = Logger.getLogger(SpringBootDocBuildTemplate.class.getName());
private List<ApiReqHeader> headers;
/**
@ -601,7 +603,9 @@ public class SpringBootDocBuildTemplate implements IDocBuildTemplate<ApiDoc> {
}
}
AnnotationValue annotationRequired = annotation.getProperty(DocAnnotationConstants.REQUIRED_PROP);
if (null == annotationRequired) {
if (Objects.nonNull(annotationRequired)) {
strRequired = annotationRequired.toString();
} else {
strRequired = "true";
}
}

View File

@ -184,6 +184,14 @@ public class DocClassUtil {
return "string";
case "java.util.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";
case "java.lang.Integer":
case "integer":

View File

@ -246,14 +246,14 @@ function toCurl(request) {
throw "Request is not an object";
}
// 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) {
cmd.push('-k');
cmd.push("-k");
}
if (request.data && request.data.length > 0) {
cmd.push('-H');
cmd.push("-H");
cmd.push("'Content-Type: application/json; charset=utf-8'");
}
// append request headers
@ -261,7 +261,7 @@ function toCurl(request) {
if (typeof request.headers == 'object') {
for (let key in request.headers) {
if (Object.prototype.hasOwnProperty.call(request.headers, key)) {
cmd.push('-H');
cmd.push("H");
headerValue = request.headers[key];
if (headerValue.value == '') {
cmd.push("'" + key + "'");
@ -273,11 +273,19 @@ function toCurl(request) {
}
// display the response headers
cmd.push('-i');
cmd.push("-i");
// 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) {
cmd.push('--data');
cmd.push("--data");
cmd.push("'" + request.data + "'");
}
let curlCmd = "";