From b2512692f4267521e6a10da2f17b0127dd0023c6 Mon Sep 17 00:00:00 2001 From: oppofind <836575280@qq.com> Date: Thu, 10 Oct 2019 14:03:04 +0800 Subject: [PATCH 1/3] fix AllInOne template for bug #I135PG --- src/main/resources/template/AllInOne.btl | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/resources/template/AllInOne.btl b/src/main/resources/template/AllInOne.btl index 5a80725..bbc7d65 100644 --- a/src/main/resources/template/AllInOne.btl +++ b/src/main/resources/template/AllInOne.btl @@ -43,6 +43,7 @@ for(param in doc.requestParams){ ${param.field}|${param.type}|${param.desc}|${param.required}|${param.version} <%}%> <%}%> + <%if(isNotEmpty(doc.requestUsage)){%> **Request-example:** ``` From 8b812efcf45ac7d121b23e73e76ac1483740f601 Mon Sep 17 00:00:00 2001 From: xingzi <1771761586@qq.com> Date: Fri, 11 Oct 2019 22:32:07 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=AF=B9@RequestHeader?= =?UTF-8?q?=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/power/doc/builder/SourceBuilder.java | 46 +++++++++++++++++-- 1 file changed, 42 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/power/doc/builder/SourceBuilder.java b/src/main/java/com/power/doc/builder/SourceBuilder.java index 6773a53..575de69 100644 --- a/src/main/java/com/power/doc/builder/SourceBuilder.java +++ b/src/main/java/com/power/doc/builder/SourceBuilder.java @@ -16,7 +16,10 @@ import com.thoughtworks.qdox.model.expression.AnnotationValue; import org.apache.commons.codec.digest.DigestUtils; import java.io.File; +import java.rmi.UnexpectedException; import java.util.*; +import java.util.stream.Collectors; +import java.util.stream.Stream; public class SourceBuilder { @@ -34,6 +37,8 @@ public class SourceBuilder { private static final String REQUEST_BODY = "RequestBody"; + private static final String REQUEST_HERDER="RequestHeader"; + private static final String REQUEST_PARAM = "RequestParam"; private static final String JSON_CONTENT_TYPE = "application/json; charset=utf-8"; @@ -173,6 +178,7 @@ public class SourceBuilder { List methodDocList = new ArrayList<>(methods.size()); int methodOrder = 0; for (JavaMethod method : methods) { + List apiReqHeaders = new ArrayList<>(); if (StringUtil.isEmpty(method.getComment()) && isStrict) { throw new RuntimeException("Unable to find comment for method " + method.getName() + " in " + cls.getCanonicalName()); } @@ -213,7 +219,31 @@ public class SourceBuilder { methodType = "DELETE"; methodCounter++; } + } + for(JavaParameter javaParameter : method.getParameters()){ + List javaAnnotations = javaParameter.getAnnotations(); + for(JavaAnnotation annotation : javaAnnotations){ + String annotationName = annotation.getType().getName(); + if (REQUEST_HERDER.equals(annotationName)) { + ApiReqHeader apiReqHeader = new ApiReqHeader(); + Map requestHeaderMap = annotation.getNamedParameterMap(); + if( requestHeaderMap.get("value")!=null){ + apiReqHeader.setName((String) requestHeaderMap.get("value")); + } + if( requestHeaderMap.get("defaultValue")!=null){ + apiReqHeader.setDesc((String) requestHeaderMap.get("defaultValue")); + } + if( requestHeaderMap.get("required")!=null){ + apiReqHeader.setRequired(!"false".equals(requestHeaderMap.get("required"))); + } + apiReqHeader.setType(javaParameter.getType().getValue()); + apiReqHeaders.add(apiReqHeader); + break; + } + } + } + apiMethodDoc.setRequestHeaders(apiReqHeaders); if (methodCounter > 0) { // if ("void".equals(method.getReturnType().getFullyQualifiedName())) { // throw new RuntimeException(method.getName() + " method in " + cls.getCanonicalName() + " can't be return type 'void'"); @@ -236,8 +266,12 @@ public class SourceBuilder { apiMethodDoc.setResponseParams(responseParams); //reduce create in template apiMethodDoc.setHeaders(createHeaders(this.headers, this.isAdoc)); - apiMethodDoc.setRequestHeaders(this.headers); + List allApiReqHeaders = Stream.of(this.headers,apiReqHeaders) + .flatMap(Collection::stream) + .collect(Collectors.toList()); + apiMethodDoc.setRequestHeaders(allApiReqHeaders); methodDocList.add(apiMethodDoc); + } } return methodDocList; @@ -882,11 +916,12 @@ public class SourceBuilder { } else { return buildJson(typeName, gicTypeName, this.fieldMap, false); } - } - + if (REQUEST_HERDER.equals(annotationName)){ + paraName =null; + } } - if (requestBodyCounter < 1) { + if (requestBodyCounter < 1 && paraName !=null) { paramsMap.put(paraName, DocUtil.getValByTypeAndFieldName(simpleTypeName, paraName, true)); } @@ -1001,6 +1036,9 @@ public class SourceBuilder { required = annotationValue.toString(); } String annotationName = annotation.getType().getName(); + if(REQUEST_HERDER.equals(annotationName)){ + continue; + } if (REQUEST_BODY.equals(annotationName)) { if (requestBodyCounter > 0) { throw new RuntimeException("You have use @RequestBody Passing multiple variables for method " From dc6a4ebcab7954fff036dda18afacf26cd195f07 Mon Sep 17 00:00:00 2001 From: oppofind <836575280@qq.com> Date: Sat, 12 Oct 2019 14:04:26 +0800 Subject: [PATCH 3/3] upgrade dependency of Common-Util --- RELEASE.md | 2 ++ pom.xml | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/RELEASE.md b/RELEASE.md index 21f650f..08394d9 100644 --- a/RELEASE.md +++ b/RELEASE.md @@ -70,5 +70,7 @@ - 更新日期:待定 - 更新内容: 1. 优化注释换行\n\r问题。 + 2. 修改bug #I135PG + 3. 添加requestHeader功能 \ No newline at end of file diff --git a/pom.xml b/pom.xml index cece3d6..7f837bf 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ 4.0.0 smart-doc jar - 1.7.0 + 1.7.1 smart-doc https://github.com/shalousun/smart-doc.git @@ -59,7 +59,7 @@ com.github.shalousun common-util - 1.8.6 + 1.8.7