From 3a376b61cdb729eecb05469c43fb3601f421804a Mon Sep 17 00:00:00 2001 From: oppofind <836575280@qq.com> Date: Tue, 19 Nov 2019 10:49:35 +0800 Subject: [PATCH] fix blank in url --- RELEASE.md | 6 ++-- .../com/power/doc/builder/ApiDocBuilder.java | 1 - .../power/doc/builder/HtmlApiDocBuilder.java | 9 +++--- .../com/power/doc/builder/SourceBuilder.java | 32 ++++++++++--------- .../com/power/doc/utils/DocClassUtil.java | 2 ++ .../java/com/power/doc/utils/DocUtil.java | 5 +-- 6 files changed, 31 insertions(+), 24 deletions(-) diff --git a/RELEASE.md b/RELEASE.md index 148f4f6..9351f87 100644 --- a/RELEASE.md +++ b/RELEASE.md @@ -123,8 +123,10 @@ #### 版本号:1.7.7 - 更新日期:待定 - 更新内容: - 1. 修改timestamp类型字段创建json示例错误bug - + 1. 修改timestamp类型字段创建json示例错误bug。 + 2. fix #I1545A 单接口多路径bug。 + 3. 修改部分url生成部署空格问题。 + 4. 优化对java.util.concurrent.ConcurrentMap的解析。 \ No newline at end of file diff --git a/src/main/java/com/power/doc/builder/ApiDocBuilder.java b/src/main/java/com/power/doc/builder/ApiDocBuilder.java index bd0b6bb..73505ff 100644 --- a/src/main/java/com/power/doc/builder/ApiDocBuilder.java +++ b/src/main/java/com/power/doc/builder/ApiDocBuilder.java @@ -1,7 +1,6 @@ package com.power.doc.builder; import com.power.common.util.DateTimeUtil; -import com.power.common.util.StringUtil; import com.power.doc.model.ApiConfig; import com.power.doc.model.ApiDoc; diff --git a/src/main/java/com/power/doc/builder/HtmlApiDocBuilder.java b/src/main/java/com/power/doc/builder/HtmlApiDocBuilder.java index 20127b5..5c482dc 100644 --- a/src/main/java/com/power/doc/builder/HtmlApiDocBuilder.java +++ b/src/main/java/com/power/doc/builder/HtmlApiDocBuilder.java @@ -49,7 +49,7 @@ public class HtmlApiDocBuilder { copyCss(config.getOutPath()); buildApiDoc(apiDocList, config.getOutPath()); buildErrorCodeDoc(config.getErrorCodes(), config.getOutPath()); - buildDictionary(apiDocDictList,config.getOutPath()); + buildDictionary(apiDocDictList, config.getOutPath()); } @@ -79,8 +79,8 @@ public class HtmlApiDocBuilder { indexTemplate.binding(TemplateVariable.HOME_PAGE.getVariable(), homePage); indexTemplate.binding(TemplateVariable.API_DOC_LIST.getVariable(), apiDocList); indexTemplate.binding(TemplateVariable.VERSION.getVariable(), now); - indexTemplate.binding(TemplateVariable.ERROR_CODE_LIST.getVariable(),config.getErrorCodes()); - indexTemplate.binding(TemplateVariable.DICT_LIST.getVariable(),config.getDataDictionaries()); + indexTemplate.binding(TemplateVariable.ERROR_CODE_LIST.getVariable(), config.getErrorCodes()); + indexTemplate.binding(TemplateVariable.DICT_LIST.getVariable(), config.getDataDictionaries()); if (CollectionUtil.isEmpty(config.getErrorCodes())) { indexTemplate.binding(TemplateVariable.DICT_ORDER.getVariable(), apiDocList.size() + 1); } else { @@ -149,11 +149,12 @@ public class HtmlApiDocBuilder { /** * build dictionary + * * @param apiDocDictList dictionary list * @param outPath */ private static void buildDictionary(List apiDocDictList, String outPath) { - if(CollectionUtil.isNotEmpty(apiDocDictList)){ + if (CollectionUtil.isNotEmpty(apiDocDictList)) { Template template = BeetlTemplateUtil.getByName(DICT_LIST_MD_TPL); template.binding(TemplateVariable.DICT_LIST.getVariable(), apiDocDictList); String dictHtml = MarkDownUtil.toHtml(template.render()); diff --git a/src/main/java/com/power/doc/builder/SourceBuilder.java b/src/main/java/com/power/doc/builder/SourceBuilder.java index 36dc5d5..22abf19 100644 --- a/src/main/java/com/power/doc/builder/SourceBuilder.java +++ b/src/main/java/com/power/doc/builder/SourceBuilder.java @@ -249,7 +249,7 @@ public class SourceBuilder { } apiReqHeader.setDesc(desc.toString()); if (requestHeaderMap.get(DocAnnotationConstants.REQUIRED_PROP) != null) { - apiReqHeader.setRequired(!"false".equals(requestHeaderMap.get(DocAnnotationConstants.REQUIRED_PROP))); + apiReqHeader.setRequired(!Boolean.FALSE.toString().equals(requestHeaderMap.get(DocAnnotationConstants.REQUIRED_PROP))); } else { apiReqHeader.setRequired(true); } @@ -274,11 +274,10 @@ public class SourceBuilder { if (urls.length > 1) { url = getUrls(baseUrl, urls); } else { - url = this.appUrl + "/" + baseUrl + "/" + url; + url = UrlUtil.simplifyUrl(this.appUrl + "/" + baseUrl + "/" + url) ; } - apiMethodDoc.setType(methodType); - apiMethodDoc.setUrl(UrlUtil.simplifyUrl(url)); + apiMethodDoc.setUrl(url); List requestParams = requestParams(method, DocTags.PARAM, cls.getCanonicalName()); apiMethodDoc.setRequestParams(requestParams); String requestJson = buildReqJson(method, apiMethodDoc, isPostMethod); @@ -310,7 +309,9 @@ public class SourceBuilder { private String getUrls(String baseUrl, String[] urls) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < urls.length; i++) { - sb.append(this.appUrl + "/" + baseUrl + "/" + urls[i].replace("[", "").replace("]", "")); + String url = this.appUrl + "/" + baseUrl + "/" + StringUtil.trimBlank(urls[i]) + .replace("[", "").replace("]", ""); + sb.append(UrlUtil.simplifyUrl(url)); if (i < urls.length - 1) { sb.append(";\t"); } @@ -422,7 +423,7 @@ public class SourceBuilder { * * @param className class name * @param pre pre - * @param i counter + * @param i Recursive counter * @param isRequired required flag * @param responseFieldMap response map * @param isResp response flag @@ -434,16 +435,17 @@ public class SourceBuilder { if (StringUtil.isEmpty(className)) { throw new RuntimeException("Class name can't be null or empty."); } + // Check circular reference List paramList = new ArrayList<>(); if (registryClasses.containsKey(className) && i > registryClasses.size()) { return paramList; } + // Registry class registryClasses.put(className, className); String simpleName = DocClassUtil.getSimpleName(className); String[] globGicName = DocClassUtil.getSimpleGicName(className); - JavaClass cls = getJavaClass(simpleName); - //clsss.isEnum() - List fields = getFields(cls, 0); + JavaClass cls = this.getJavaClass(simpleName); + List fields = this.getFields(cls, 0); int n = 0; if (DocClassUtil.isPrimitive(simpleName)) { paramList.addAll(primitiveReturnRespComment(DocClassUtil.processTypeNameForParams(simpleName))); @@ -507,7 +509,7 @@ public class SourceBuilder { continue out; } else if (DocAnnotationConstants.SHORT_JSON_FIELD.equals(annotationName) && isResp) { if (null != annotation.getProperty(DocAnnotationConstants.SERIALIZE_PROP)) { - if ("false".equals(annotation.getProperty(DocAnnotationConstants.SERIALIZE_PROP).toString())) { + if (Boolean.FALSE.toString().equals(annotation.getProperty(DocAnnotationConstants.SERIALIZE_PROP).toString())) { continue out; } } else if (null != annotation.getProperty(DocAnnotationConstants.NAME_PROP)) { @@ -598,7 +600,7 @@ public class SourceBuilder { preBuilder.append("└─"); if (DocClassUtil.isMap(subTypeName)) { String gNameTemp = field.getType().getGenericCanonicalName(); - if (DocGlobalConstants.JAVA_MAP_FULLY.equals(gNameTemp)) { + if (DocClassUtil.isMap(gNameTemp)) { ApiParam param1 = ApiParam.of().setField(preBuilder.toString() + "any object") .setType("object").setDesc(DocGlobalConstants.ANY_OBJECT_MSG).setVersion(DocGlobalConstants.DEFAULT_VERSION); paramList.add(param1); @@ -717,8 +719,8 @@ public class SourceBuilder { * @param typeName type name * @param genericCanonicalName genericCanonicalName * @param responseFieldMap map of response fields data - * @param isResp response flag - * @param counter counter + * @param isResp Response flag + * @param counter Recursive counter * @return String */ private String buildJson(String typeName, String genericCanonicalName, Map responseFieldMap, @@ -822,7 +824,7 @@ public class SourceBuilder { continue out; } else if (DocAnnotationConstants.SHORT_JSON_FIELD.equals(annotationName) && isResp) { if (null != annotation.getProperty(DocAnnotationConstants.SERIALIZE_PROP)) { - if ("false".equals(annotation.getProperty(DocAnnotationConstants.SERIALIZE_PROP).toString())) { + if (Boolean.FALSE.toString().equals(annotation.getProperty(DocAnnotationConstants.SERIALIZE_PROP).toString())) { continue out; } } else if (null != annotation.getProperty(DocAnnotationConstants.NAME_PROP)) { @@ -894,7 +896,7 @@ public class SourceBuilder { } } } else if (DocClassUtil.isMap(subTypeName)) { - if (DocGlobalConstants.JAVA_MAP_FULLY.equals(subTypeName)) { + if (DocClassUtil.isMap(fieldGicName)) { data0.append("{").append("\"mapKey\":{}},"); continue out; } diff --git a/src/main/java/com/power/doc/utils/DocClassUtil.java b/src/main/java/com/power/doc/utils/DocClassUtil.java index df9e5eb..ca04c92 100644 --- a/src/main/java/com/power/doc/utils/DocClassUtil.java +++ b/src/main/java/com/power/doc/utils/DocClassUtil.java @@ -305,6 +305,8 @@ public class DocClassUtil { return true; case "java.util.concurrent.ConcurrentHashMap": return true; + case "java.util.concurrent.ConcurrentMap": + return true; case "java.util.Properties": return true; case "java.util.Hashtable": diff --git a/src/main/java/com/power/doc/utils/DocUtil.java b/src/main/java/com/power/doc/utils/DocUtil.java index c753223..8ea9ed5 100644 --- a/src/main/java/com/power/doc/utils/DocUtil.java +++ b/src/main/java/com/power/doc/utils/DocUtil.java @@ -5,6 +5,7 @@ import com.power.common.util.DateTimeUtil; import com.power.common.util.IDCardUtil; import com.power.common.util.RandomUtil; import com.power.common.util.StringUtil; +import com.power.doc.constants.DocAnnotationConstants; import com.power.doc.constants.DocGlobalConstants; import com.thoughtworks.qdox.model.DocletTag; import com.thoughtworks.qdox.model.JavaAnnotation; @@ -249,10 +250,10 @@ public class DocUtil { * @return String */ public static String handleMappingValue(JavaAnnotation annotation) { - if (null == annotation.getNamedParameter("value")) { + if (null == annotation.getNamedParameter(DocAnnotationConstants.VALUE_PROP)) { return "/"; } else { - return annotation.getNamedParameter("value").toString(); + return StringUtil.trimBlank(String.valueOf(annotation.getNamedParameter(DocAnnotationConstants.VALUE_PROP))); } }