h = new HashMap<>();
+ h.put("required", res.isRequired() ? "1" : "0");
+ h.put("value", res.getValue());
+ h.put("name", res.getName());
+ h.put("desc", res.getDesc());
+ headers.add(j, h);
+ });
+
+ method.put("req_headers", headers);
+
+ Template apiTemplate = BeetlTemplateUtil.getByName(YAPI_RESULT_TPL);
+
+ apiTemplate.binding(TemplateVariable.RESPONSELIST.getVariable(), generateJson(apiMethodDoc.getResponseParams()));
+ String json = apiTemplate.render();
+ method.put("res_body", json);
+
+ if (StringUtil.isNotEmpty(apiMethodDoc.getResponseUsage())) {
+ method.put("desc", "\n" + apiMethodDoc.getResponseUsage() + "\n
\n");
+ }
+
+ methods.add(idx, method);
+ });
+ module.put("list", methods);
+
+ requestItem.add(module);
+ });
+
+ String filePath = config.getOutPath();
+ filePath = filePath + DocGlobalConstants.YAPI_JSON;
+ Gson gson = new GsonBuilder().setPrettyPrinting().create();
+ String data = gson.toJson(requestItem);
+ FileUtil.nioWriteFile(data, filePath);
+ }
+
+ private static String generateJson(List responseParams) {
+ StringBuffer re = new StringBuffer("\"type\":\"object\",\n\"properties\":{\n");
+ HashSet required = new HashSet<>();
+ responseParams.stream().forEach(apiParam -> {
+ re.append(getTypeAndPropertiesJson(apiParam));
+ if (apiParam.isRequired()) {
+ required.add(apiParam.getField());
+ }
+ });
+ Gson gs = new Gson();
+ re.append("\"required\":\"" + gs.toJson(required.toArray()) + "\"");
+ re.append("\t}");
+ return re.toString();
+ }
+
+ /**
+ * 将字段类型转换为yapi的字段类型
+ *
+ * @param type java type
+ * @return String
+ */
+ public static String changeType(String type) {
+ switch (type) {
+ case "boolean":
+ return "boolean";
+ case "int32":
+ return "integer";
+ case "int64":
+ return "number";
+ default:
+ return type;
+ }
+ }
+
+ /**
+ * 单个参数拼接字符串
+ *
+ * @param param ApiParam
+ * @return String
+ */
+ public static String getTypeAndPropertiesJson(ApiParam param) {
+ StringBuffer resultJson = new StringBuffer();
+
+ resultJson.append("\"" + param.getField() + "\":{");
+ resultJson.append("\"type\":\"" + changeType(param.getType()) + "\", ");
+
+ if (param.getChildren() != null && param.getChildren().size() > 0) {
+ if (param.getType().equals("object")) {
+ resultJson.append(" \"properties\":{");
+ param.getChildren().forEach(child -> {
+ resultJson.append(getTypeAndPropertiesJson(child));
+ });
+ } else if (param.getType().equals("array")) {
+ resultJson.append(" \"items\":{");
+ resultJson.append("\"type\":\"object\",\n\"properties\":{\n");
+ param.getChildren().forEach(child -> {
+ resultJson.append(getTypeAndPropertiesJson(child));
+ });
+ resultJson.append("\t},");
+ }
+ resultJson.append("},");
+ }
+ resultJson.append("},");
+ return resultJson.toString();
+ }
+}
diff --git a/src/main/java/com/power/doc/constants/DocGlobalConstants.java b/src/main/java/com/power/doc/constants/DocGlobalConstants.java
index c2202cc..fddda89 100644
--- a/src/main/java/com/power/doc/constants/DocGlobalConstants.java
+++ b/src/main/java/com/power/doc/constants/DocGlobalConstants.java
@@ -1,149 +1,151 @@
-package com.power.doc.constants;
-
-/**
- * @author yu 2018/12/15.
- */
-public interface DocGlobalConstants {
-
- String FILE_SEPARATOR = System.getProperty("file.separator");
-
- String HTML_DOC_OUT_PATH = "src/main/resources/static/doc";
-
- String ADOC_OUT_PATH = "src/docs/asciidoc";
-
- String PROJECT_CODE_PATH = "src" + FILE_SEPARATOR + "main" + FILE_SEPARATOR + "java";
-
- String ABSOLUTE_CODE_PATH = System.getProperty("user.dir") + FILE_SEPARATOR + PROJECT_CODE_PATH;
-
- String DOC_LANGUAGE = "smart-doc_language";
-
- String API_DOC_MD_TPL = "ApiDoc.btl";
-
- String API_DOC_ADOC_TPL = "ApiDoc.adoc";
-
- String ALL_IN_ONE_MD_TPL = "AllInOne.btl";
-
- String ALL_IN_ONE_ADOC_TPL = "AllInOne.adoc";
-
- String ALL_IN_ONE_HTML_TPL = "AllInOne.html";
-
- String HTML_API_DOC_TPL = "HtmlApiDoc.btl";
-
- String ERROR_CODE_LIST_MD_TPL = "ErrorCodeList.btl";
-
- String ERROR_CODE_LIST_ADOC_TPL = "ErrorCodeList.adoc";
-
- String ERROR_CODE_LIST_MD = "ErrorCodeList.md";
-
- String ERROR_CODE_LIST_ADOC = "ErrorCodeList.adoc";
-
- String DICT_LIST_MD = "Dictionary.md";
-
- String DICT_LIST_MD_TPL = "Dictionary.btl";
-
- String DICT_LIST_ADOC = "Dictionary.adoc";
-
- String DICT_LIST_ADOC_TPL = "Dictionary.btl";
-
- String INDEX_TPL = "Index.btl";
-
- String INDEX_CSS_TPL = "index.css";
-
- String MARKDOWN_CSS_TPL = "markdown.css";
-
- String ALL_IN_ONE_CSS = "AllInOne.css";
-
- String RPC_API_DOC_ADOC_TPL = "dubbo/Dubbo.adoc";
-
- String RPC_ALL_IN_ONE_ADOC_TPL = "dubbo/DubboAllInOne.adoc";
-
- String RPC_ALL_IN_ONE_HTML_TPL = "dubbo/DubboAllInOne.html";
-
- String RPC_DEPENDENCY_MD_TPL = "dubbo/DubboApiDependency.md";
-
- String RPC_API_DOC_MD_TPL = "dubbo/Dubbo.md";
-
- String RPC_ALL_IN_ONE_MD_TPL = "dubbo/DubboAllInOne.md";
-
- String RPC_INDEX_TPL = "dubbo/DubboIndex.btl";
-
- String POSTMAN_JSON = "/postman.json";
-
- String OPEN_API_JSON = "/openApi3.0.json";
-
- String CONTROLLER_FULLY = "org.springframework.stereotype.Controller";
-
- String REST_CONTROLLER_FULLY = "org.springframework.web.bind.annotation.RestController";
-
- String GET_MAPPING_FULLY = "org.springframework.web.bind.annotation.GetMapping";
-
- String POST_MAPPING_FULLY = "org.springframework.web.bind.annotation.PostMapping";
-
- String PUT_MAPPING_FULLY = "org.springframework.web.bind.annotation.PutMapping";
-
- String PATCH_MAPPING_FULLY = "org.springframework.web.bind.annotation.PatchMapping";
-
- String DELETE_MAPPING_FULLY = "org.springframework.web.bind.annotation.DeleteMapping";
-
- String REQUEST_MAPPING_FULLY = "org.springframework.web.bind.annotation.RequestMapping";
-
- String REQUEST_BODY_FULLY = "org.springframework.web.bind.annotation.RequestBody";
-
- String MODE_AND_VIEW_FULLY = "org.springframework.web.servlet.ModelAndView";
-
- String MULTIPART_FILE_FULLY = "org.springframework.web.multipart.MultipartFile";
-
- String JAVA_OBJECT_FULLY = "java.lang.Object";
-
- String JAVA_STRING_FULLY = "java.lang.String";
-
- String JAVA_MAP_FULLY = "java.util.Map";
-
- String JAVA_LIST_FULLY = "java.util.List";
-
- String DEFAULT_VERSION = "-";
-
- String ERROR_CODE_LIST_CN_TITLE = "错误码列表";
-
- String ERROR_CODE_LIST_EN_TITLE = "Error Code List";
-
- String DICT_CN_TITLE = "数据字典";
-
- String DICT_EN_TITLE = "Data Dictionaries";
-
- String FIELD_SPACE = " ";
-
- String ANY_OBJECT_MSG = "any object.";
-
- String NO_COMMENTS_FOUND = "No comments found.";
-
- String SPRING_WEB_ANNOTATION_PACKAGE = "org.springframework.web.bind.annotation";
-
- String FILE_CONTENT_TYPE = "multipart/form-data";
-
- String MULTIPART_TYPE = "multipart/form-data";
-
- String APPLICATION_JSON = "application/json";
-
- String JSON_CONTENT_TYPE = "application/json; charset=utf-8";
-
- String POSTMAN_MODE_FORMDATA = "formdata";
-
- String POSTMAN_MODE_RAW = "raw";
-
- String SHORT_MULTIPART_FILE_FULLY = "MultipartFile";
-
- String DEFAULT_SERVER_URL = "http://{server}";
-
- String SHORT_REQUEST_BODY = "RequestBody";
-
- String CURL_REQUEST_TYPE = "curl -X %s -i %s";
-
- String CURL_REQUEST_TYPE_DATA = "curl -X %s -i %s --data '%s'";
-
- String CURL_POST_PUT_JSON = "curl -X %s -H 'Content-Type: application/json; charset=utf-8' -i %s --data '%s'";
-
- String EMPTY = "";
-
- String ENUM = "enum";
-}
+package com.power.doc.constants;
+
+/**
+ * @author yu 2018/12/15.
+ */
+public interface DocGlobalConstants {
+
+ String FILE_SEPARATOR = System.getProperty("file.separator");
+
+ String HTML_DOC_OUT_PATH = "src/main/resources/static/doc";
+
+ String ADOC_OUT_PATH = "src/docs/asciidoc";
+
+ String PROJECT_CODE_PATH = "src" + FILE_SEPARATOR + "main" + FILE_SEPARATOR + "java";
+
+ String ABSOLUTE_CODE_PATH = System.getProperty("user.dir") + FILE_SEPARATOR + PROJECT_CODE_PATH;
+
+ String DOC_LANGUAGE = "smart-doc_language";
+
+ String API_DOC_MD_TPL = "ApiDoc.btl";
+
+ String API_DOC_ADOC_TPL = "ApiDoc.adoc";
+
+ String ALL_IN_ONE_MD_TPL = "AllInOne.btl";
+
+ String ALL_IN_ONE_ADOC_TPL = "AllInOne.adoc";
+
+ String ALL_IN_ONE_HTML_TPL = "AllInOne.html";
+
+ String HTML_API_DOC_TPL = "HtmlApiDoc.btl";
+
+ String ERROR_CODE_LIST_MD_TPL = "ErrorCodeList.btl";
+
+ String ERROR_CODE_LIST_ADOC_TPL = "ErrorCodeList.adoc";
+
+ String ERROR_CODE_LIST_MD = "ErrorCodeList.md";
+
+ String ERROR_CODE_LIST_ADOC = "ErrorCodeList.adoc";
+
+ String DICT_LIST_MD = "Dictionary.md";
+
+ String DICT_LIST_MD_TPL = "Dictionary.btl";
+
+ String DICT_LIST_ADOC = "Dictionary.adoc";
+
+ String DICT_LIST_ADOC_TPL = "Dictionary.btl";
+
+ String INDEX_TPL = "Index.btl";
+
+ String INDEX_CSS_TPL = "index.css";
+
+ String MARKDOWN_CSS_TPL = "markdown.css";
+
+ String ALL_IN_ONE_CSS = "AllInOne.css";
+
+ String RPC_API_DOC_ADOC_TPL = "dubbo/Dubbo.adoc";
+
+ String RPC_ALL_IN_ONE_ADOC_TPL = "dubbo/DubboAllInOne.adoc";
+
+ String RPC_ALL_IN_ONE_HTML_TPL = "dubbo/DubboAllInOne.html";
+
+ String RPC_DEPENDENCY_MD_TPL = "dubbo/DubboApiDependency.md";
+
+ String RPC_API_DOC_MD_TPL = "dubbo/Dubbo.md";
+
+ String RPC_ALL_IN_ONE_MD_TPL = "dubbo/DubboAllInOne.md";
+
+ String RPC_INDEX_TPL = "dubbo/DubboIndex.btl";
+
+ String POSTMAN_JSON = "/postman.json";
+
+ String OPEN_API_JSON = "/openApi3.0.json";
+
+ String CONTROLLER_FULLY = "org.springframework.stereotype.Controller";
+
+ String REST_CONTROLLER_FULLY = "org.springframework.web.bind.annotation.RestController";
+
+ String GET_MAPPING_FULLY = "org.springframework.web.bind.annotation.GetMapping";
+
+ String POST_MAPPING_FULLY = "org.springframework.web.bind.annotation.PostMapping";
+
+ String PUT_MAPPING_FULLY = "org.springframework.web.bind.annotation.PutMapping";
+
+ String PATCH_MAPPING_FULLY = "org.springframework.web.bind.annotation.PatchMapping";
+
+ String DELETE_MAPPING_FULLY = "org.springframework.web.bind.annotation.DeleteMapping";
+
+ String REQUEST_MAPPING_FULLY = "org.springframework.web.bind.annotation.RequestMapping";
+
+ String REQUEST_BODY_FULLY = "org.springframework.web.bind.annotation.RequestBody";
+
+ String MODE_AND_VIEW_FULLY = "org.springframework.web.servlet.ModelAndView";
+
+ String MULTIPART_FILE_FULLY = "org.springframework.web.multipart.MultipartFile";
+
+ String JAVA_OBJECT_FULLY = "java.lang.Object";
+
+ String JAVA_STRING_FULLY = "java.lang.String";
+
+ String JAVA_MAP_FULLY = "java.util.Map";
+
+ String JAVA_LIST_FULLY = "java.util.List";
+
+ String DEFAULT_VERSION = "-";
+
+ String ERROR_CODE_LIST_CN_TITLE = "错误码列表";
+
+ String ERROR_CODE_LIST_EN_TITLE = "Error Code List";
+
+ String DICT_CN_TITLE = "数据字典";
+
+ String DICT_EN_TITLE = "Data Dictionaries";
+
+ String FIELD_SPACE = " ";
+
+ String ANY_OBJECT_MSG = "any object.";
+
+ String NO_COMMENTS_FOUND = "No comments found.";
+
+ String SPRING_WEB_ANNOTATION_PACKAGE = "org.springframework.web.bind.annotation";
+
+ String FILE_CONTENT_TYPE = "multipart/form-data";
+
+ String MULTIPART_TYPE = "multipart/form-data";
+
+ String APPLICATION_JSON = "application/json";
+
+ String JSON_CONTENT_TYPE = "application/json; charset=utf-8";
+
+ String POSTMAN_MODE_FORMDATA = "formdata";
+
+ String POSTMAN_MODE_RAW = "raw";
+
+ String SHORT_MULTIPART_FILE_FULLY = "MultipartFile";
+
+ String DEFAULT_SERVER_URL = "http://{server}";
+
+ String SHORT_REQUEST_BODY = "RequestBody";
+
+ String CURL_REQUEST_TYPE = "curl -X %s %s -i %s";
+
+ String CURL_REQUEST_TYPE_DATA = "curl -X %s %s -i %s --data '%s'";
+
+ String CURL_POST_PUT_JSON = "curl -X %s -H 'Content-Type: application/json; charset=utf-8' %s -i %s --data '%s'";
+
+ String EMPTY = "";
+
+ String ENUM = "enum";
+ String YAPI_RESULT_TPL = "yapiJson.btl";
+ String YAPI_JSON="/yapi.json";
+}
diff --git a/src/main/java/com/power/doc/constants/TemplateVariable.java b/src/main/java/com/power/doc/constants/TemplateVariable.java
index 8f60654..0065989 100644
--- a/src/main/java/com/power/doc/constants/TemplateVariable.java
+++ b/src/main/java/com/power/doc/constants/TemplateVariable.java
@@ -48,7 +48,8 @@ public enum TemplateVariable {
URI("uri"),
RPC_CONSUMER_CONFIG("consumerConfigExample"),
REQUEST_EXAMPLE("isRequestExample"),
- RESPONSE_EXAMPLE("isResponseExample");
+ RESPONSE_EXAMPLE("isResponseExample"),
+ RESPONSELIST("respList");
private String variable;
diff --git a/src/main/java/com/power/doc/helper/ParamsBuildHelper.java b/src/main/java/com/power/doc/helper/ParamsBuildHelper.java
index 279b9e7..a56df99 100644
--- a/src/main/java/com/power/doc/helper/ParamsBuildHelper.java
+++ b/src/main/java/com/power/doc/helper/ParamsBuildHelper.java
@@ -1,429 +1,429 @@
-/*
- * smart-doc https://github.com/shalousun/smart-doc
- *
- * Copyright (C) 2018-2020 smart-doc
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package com.power.doc.helper;
-
-import com.power.common.model.EnumDictionary;
-import com.power.common.util.CollectionUtil;
-import com.power.common.util.StringUtil;
-import com.power.doc.builder.ProjectDocConfigBuilder;
-import com.power.doc.constants.DocAnnotationConstants;
-import com.power.doc.constants.DocGlobalConstants;
-import com.power.doc.constants.DocTags;
-import com.power.doc.constants.ValidatorAnnotations;
-import com.power.doc.model.*;
-import com.power.doc.utils.*;
-import com.thoughtworks.qdox.model.*;
-
-import java.util.*;
-import java.util.stream.Collectors;
-
-import static com.power.doc.constants.DocGlobalConstants.NO_COMMENTS_FOUND;
-
-/**
- * @author yu 2019/12/21.
- */
-public class ParamsBuildHelper {
-
- public static List buildParams(String className, String pre, int level, String isRequired,
- Map responseFieldMap, boolean isResp,
- Map registryClasses, ProjectDocConfigBuilder projectBuilder,
- List groupClasses, int pid) {
- //存储泛型所对应的实体类
- Map genericMap = new HashMap<>(10);
-
- if (StringUtil.isEmpty(className)) {
- throw new RuntimeException("Class name can't be null or empty.");
- }
- ApiConfig apiConfig = projectBuilder.getApiConfig();
- int nextLevel = level + 1;
- // Check circular reference
- List paramList = new ArrayList<>();
- if (level > apiConfig.getRecursionLimit()) {
- return paramList;
- }
- if (registryClasses.containsKey(className) && level > registryClasses.size()) {
- return paramList;
- }
- boolean skipTransientField = apiConfig.isSkipTransientField();
- boolean isShowJavaType = projectBuilder.getApiConfig().getShowJavaType();
- boolean requestFieldToUnderline = projectBuilder.getApiConfig().isRequestFieldToUnderline();
- boolean responseFieldToUnderline = projectBuilder.getApiConfig().isResponseFieldToUnderline();
- // Registry class
- registryClasses.put(className, className);
- String simpleName = DocClassUtil.getSimpleName(className);
- String[] globGicName = DocClassUtil.getSimpleGicName(className);
- JavaClass cls = projectBuilder.getClassByName(simpleName);
- //如果存在泛型 则将泛型与类名的对应关系存起来
- if (cls != null && null != cls.getTypeParameters()) {
- List> variables = cls.getTypeParameters();
- for (int i = 0; i < cls.getTypeParameters().size() && i fields = JavaClassUtil.getFields(cls, 0, new HashSet<>());
- if (JavaClassValidateUtil.isPrimitive(simpleName)) {
- String processedType = isShowJavaType ? simpleName : DocClassUtil.processTypeNameForParams(simpleName.toLowerCase());
- paramList.addAll(primitiveReturnRespComment(processedType));
- } else if (JavaClassValidateUtil.isCollection(simpleName) || JavaClassValidateUtil.isArray(simpleName)) {
- if (!JavaClassValidateUtil.isCollection(globGicName[0])) {
- String gicName = globGicName[0];
- if (JavaClassValidateUtil.isArray(gicName)) {
- gicName = gicName.substring(0, gicName.indexOf("["));
- }
- paramList.addAll(buildParams(gicName, pre, nextLevel, isRequired, responseFieldMap, isResp,
- registryClasses, projectBuilder, groupClasses, pid));
- }
- } else if (JavaClassValidateUtil.isMap(simpleName)) {
- if (globGicName.length == 2) {
- paramList.addAll(buildParams(globGicName[1], pre, nextLevel, isRequired, responseFieldMap, isResp,
- registryClasses, projectBuilder, groupClasses, pid));
- }
- } else if (DocGlobalConstants.JAVA_OBJECT_FULLY.equals(className)) {
- ApiParam param = ApiParam.of().setField(pre + "any object").setType("object").setPid(pid);
- if (StringUtil.isEmpty(isRequired)) {
- param.setDesc(DocGlobalConstants.ANY_OBJECT_MSG).setVersion(DocGlobalConstants.DEFAULT_VERSION);
- } else {
- param.setDesc(DocGlobalConstants.ANY_OBJECT_MSG).setRequired(false).setVersion(DocGlobalConstants.DEFAULT_VERSION);
- }
- paramList.add(param);
- }
-// if (className.contains(DocGlobalConstants.MULTIPART_FILE_FULLY)) {
-// ApiParam param = ApiParam.of().setField("").setType("file")
-// .setPid(pid)
-// .setDesc("comment").setRequired(true).setVersion(DocGlobalConstants.DEFAULT_VERSION);
-// paramList.add(param);
-// }
- else {
- boolean isGenerics = JavaFieldUtil.checkGenerics(fields);
- out:
- for (DocJavaField docField : fields) {
- JavaField field = docField.getJavaField();
- String fieldName = field.getName();
- String subTypeName = field.getType().getFullyQualifiedName();
- if (field.isStatic() || "this$0".equals(fieldName) ||
- JavaClassValidateUtil.isIgnoreFieldTypes(subTypeName)) {
- continue;
- }
- if (field.isTransient() && skipTransientField) {
- continue;
- }
- if ((responseFieldToUnderline && isResp) || (requestFieldToUnderline && !isResp)) {
- fieldName = StringUtil.camelToUnderline(fieldName);
- }
- String typeSimpleName = field.getType().getSimpleName();
- String fieldGicName = field.getType().getGenericCanonicalName();
- List javaAnnotations = docField.getAnnotations();
-
- Map tagsMap = DocUtil.getFieldTagsValue(field, docField);
- String since = DocGlobalConstants.DEFAULT_VERSION;//since tag value
- if (!isResp) {
- pre:
- if (tagsMap.containsKey(DocTags.IGNORE)) {
- continue out;
- } else if (tagsMap.containsKey(DocTags.SINCE)) {
- since = tagsMap.get(DocTags.SINCE);
- }
- } else {
- if (tagsMap.containsKey(DocTags.SINCE)) {
- since = tagsMap.get(DocTags.SINCE);
- }
- }
-
- boolean strRequired = false;
- int annotationCounter = 0;
-
- an:
- for (JavaAnnotation annotation : javaAnnotations) {
- String simpleAnnotationName = annotation.getType().getValue();
- if (DocAnnotationConstants.SHORT_JSON_IGNORE.equals(simpleAnnotationName)) {
- continue out;
- } else if (DocAnnotationConstants.SHORT_JSON_FIELD.equals(simpleAnnotationName)) {
- if (null != annotation.getProperty(DocAnnotationConstants.SERIALIZE_PROP)) {
- if (Boolean.FALSE.toString().equals(annotation.getProperty(DocAnnotationConstants.SERIALIZE_PROP).toString())) {
- continue out;
- }
- } else if (null != annotation.getProperty(DocAnnotationConstants.NAME_PROP)) {
- fieldName = StringUtil.removeQuotes(annotation.getProperty(DocAnnotationConstants.NAME_PROP).toString());
- }
- } else if (DocAnnotationConstants.SHORT_JSON_PROPERTY.equals(simpleAnnotationName)) {
- if (null != annotation.getProperty(DocAnnotationConstants.VALUE_PROP)) {
- fieldName = StringUtil.removeQuotes(annotation.getProperty(DocAnnotationConstants.VALUE_PROP).toString());
- }
- } else if (ValidatorAnnotations.NULL.equals(simpleAnnotationName) && !isResp) {
- List groupClassList = JavaClassUtil.getParamGroupJavaClass(annotation);
- for (String javaClass : groupClassList) {
- if (groupClasses.contains(javaClass)) {
- strRequired = false;
- break an;
- }
- }
- } else if (JavaClassValidateUtil.isJSR303Required(simpleAnnotationName) && !isResp) {
- annotationCounter++;
- boolean hasGroup = false;
- List groupClassList = JavaClassUtil.getParamGroupJavaClass(annotation);
- for (String javaClass : groupClassList) {
- if (groupClasses.contains(javaClass)) {
- hasGroup = true;
- }
- }
- if (hasGroup) {
- strRequired = true;
- } else if (CollectionUtil.isEmpty(groupClasses)) {
- strRequired = true;
- }
- break an;
- }
- }
- if (annotationCounter < 1) {
- doc:
- if (tagsMap.containsKey(DocTags.REQUIRED)) {
- strRequired = true;
- break doc;
- }
- }
- //cover comment
- CustomRespField customResponseField = responseFieldMap.get(field.getName());
- String comment;
- if (null != customResponseField && StringUtil.isNotEmpty(customResponseField.getDesc())) {
- comment = customResponseField.getDesc();
- } else {
- comment = docField.getComment();
- }
- if (StringUtil.isNotEmpty(comment)) {
- comment = DocUtil.replaceNewLineToHtmlBr(comment);
- }
- if (JavaClassValidateUtil.isPrimitive(subTypeName)) {
- ApiParam param = ApiParam.of().setField(pre + fieldName);
- param.setPid(pid);
- String processedType = isShowJavaType ? typeSimpleName : DocClassUtil.processTypeNameForParams(typeSimpleName.toLowerCase());
- param.setType(processedType);
- if (StringUtil.isNotEmpty(comment)) {
- commonHandleParam(paramList, param, isRequired, comment, since, strRequired);
- } else {
- commonHandleParam(paramList, param, isRequired, NO_COMMENTS_FOUND, since, strRequired);
- }
- } else {
- ApiParam param = ApiParam.of().setField(pre + fieldName);
- JavaClass javaClass = projectBuilder.getJavaProjectBuilder().getClassByName(subTypeName);
- String enumComments = javaClass.getComment();
- if (javaClass.isEnum()) {
- 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 + "
" + JavaClassUtil.getEnumParams(javaClass) + "
";
- if (enumComments != null) {
- comment = comment + "(See: " + enumComments + ")";
- }
- comment = StringUtil.removeQuotes(comment);
-
- }
- param.setType(DocGlobalConstants.ENUM);
- }
- //如果是文件
- if(typeSimpleName.contains(DocGlobalConstants.MULTIPART_FILE_FULLY)){
- param.setType("file");
- }
- //如果已经设置返回类型 不需要再次设置
- if (param.getType() == null) {
- String processedType;
- if (typeSimpleName.length() == 1) {
- processedType = DocClassUtil.processTypeNameForParams(typeSimpleName.toLowerCase());
- } else {
- processedType = isShowJavaType ? typeSimpleName : DocClassUtil.processTypeNameForParams(typeSimpleName.toLowerCase());
- }
- param.setType(processedType);
- }
- if (!isResp && javaClass.isEnum()) {
- List methods = javaClass.getMethods();
- int index = 0;
-
- enumOut:
- for (JavaMethod method : methods) {
- List javaAnnotationList = method.getAnnotations();
- for (JavaAnnotation annotation : javaAnnotationList) {
- if (annotation.getType().getValue().contains("JsonValue")) {
- break enumOut;
- }
- }
- if (CollectionUtil.isEmpty(javaAnnotations) && index < 1) {
- break enumOut;
- }
- index++;
- }
- param.setType(DocGlobalConstants.ENUM);
- }
-
- if (StringUtil.isNotEmpty(comment)) {
- commonHandleParam(paramList, param, isRequired, comment, since, strRequired);
- } else {
- commonHandleParam(paramList, param, isRequired, NO_COMMENTS_FOUND, since, strRequired);
- }
- StringBuilder preBuilder = new StringBuilder();
- for (int j = 0; j < level; j++) {
- preBuilder.append(DocGlobalConstants.FIELD_SPACE);
- }
- preBuilder.append("└─");
- int fieldPid = paramList.size();
- if (JavaClassValidateUtil.isMap(subTypeName)) {
- String gNameTemp = field.getType().getGenericCanonicalName();
- if (JavaClassValidateUtil.isMap(gNameTemp)) {
- ApiParam param1 = ApiParam.of().setField(preBuilder.toString() + "any object")
- .setId(paramList.size()+1).setPid(fieldPid)
- .setType("object").setDesc(DocGlobalConstants.ANY_OBJECT_MSG).setVersion(DocGlobalConstants.DEFAULT_VERSION);
- paramList.add(param1);
- continue;
- }
- String valType = DocClassUtil.getMapKeyValueType(gNameTemp)[1];
- if (!JavaClassValidateUtil.isPrimitive(valType)) {
- if (valType.length() == 1) {
- String gicName = genericMap.get(valType);
- if (!JavaClassValidateUtil.isPrimitive(gicName) && !simpleName.equals(gicName)) {
- paramList.addAll(buildParams(gicName, preBuilder.toString(), nextLevel, isRequired,
- responseFieldMap, isResp, registryClasses, projectBuilder, groupClasses, fieldPid));
- }
- } else {
- paramList.addAll(buildParams(valType, preBuilder.toString(), nextLevel, isRequired,
- responseFieldMap, isResp, registryClasses, projectBuilder, groupClasses, fieldPid));
- }
- }
- } else if (JavaClassValidateUtil.isCollection(subTypeName)) {
- String gNameTemp = field.getType().getGenericCanonicalName();
- if (globGicName.length > 0 && "java.util.List".equals(gNameTemp)) {
- gNameTemp = gNameTemp + "";
- }
- String[] gNameArr = DocClassUtil.getSimpleGicName(gNameTemp);
- if (gNameArr.length == 0) {
- continue out;
- }
- String gName = DocClassUtil.getSimpleGicName(gNameTemp)[0];
- if (!JavaClassValidateUtil.isPrimitive(gName)) {
- if (!simpleName.equals(gName) && !gName.equals(simpleName)) {
- if (gName.length() == 1) {
- int len = globGicName.length;
- if (len > 0) {
- String gicName = genericMap.get(gName) != null ? genericMap.get(gName) : globGicName[0];
- if (!JavaClassValidateUtil.isPrimitive(gicName) && !simpleName.equals(gicName)) {
- paramList.addAll(buildParams(gicName, preBuilder.toString(), nextLevel, isRequired,
- responseFieldMap, isResp, registryClasses, projectBuilder, groupClasses, fieldPid));
- }
- }
- } else {
- paramList.addAll(buildParams(gName, preBuilder.toString(), nextLevel, isRequired,
- responseFieldMap, isResp, registryClasses, projectBuilder, groupClasses, fieldPid));
- }
- }
- }
- } else
- if (subTypeName.length() == 1 || DocGlobalConstants.JAVA_OBJECT_FULLY.equals(subTypeName)) {
- if (isGenerics && DocGlobalConstants.JAVA_OBJECT_FULLY.equals(subTypeName)) {
- ApiParam param1 = ApiParam.of().setField(preBuilder.toString() + "any object")
- .setId(paramList.size())
- .setType("object").setDesc(DocGlobalConstants.ANY_OBJECT_MSG).setVersion(DocGlobalConstants.DEFAULT_VERSION);
- paramList.add(param1);
- } else if (!simpleName.equals(className)) {
- if (globGicName.length > 0) {
- String gicName = genericMap.get(subTypeName) != null ? genericMap.get(subTypeName) : globGicName[0];
- String simple = DocClassUtil.getSimpleName(gicName);
- if (JavaClassValidateUtil.isPrimitive(simple)) {
- //do nothing
- } else if (gicName.contains("<")) {
- if (JavaClassValidateUtil.isCollection(simple)) {
- String gName = DocClassUtil.getSimpleGicName(gicName)[0];
- if (!JavaClassValidateUtil.isPrimitive(gName)) {
- paramList.addAll(buildParams(gName, preBuilder.toString(), nextLevel, isRequired,
- responseFieldMap, isResp, registryClasses, projectBuilder, groupClasses, fieldPid));
- }
- } else if (JavaClassValidateUtil.isMap(simple)) {
- String valType = DocClassUtil.getMapKeyValueType(gicName)[1];
- if (!JavaClassValidateUtil.isPrimitive(valType)) {
- paramList.addAll(buildParams(valType, preBuilder.toString(), nextLevel, isRequired,
- responseFieldMap, isResp, registryClasses, projectBuilder, groupClasses, fieldPid));
- }
- } else {
- paramList.addAll(buildParams(gicName, preBuilder.toString(), nextLevel, isRequired,
- responseFieldMap, isResp, registryClasses, projectBuilder, groupClasses, fieldPid));
- }
- } else {
- paramList.addAll(buildParams(gicName, preBuilder.toString(), nextLevel, isRequired,
- responseFieldMap, isResp, registryClasses, projectBuilder, groupClasses, fieldPid));
- }
- } else {
- paramList.addAll(buildParams(subTypeName, preBuilder.toString(), nextLevel, isRequired,
- responseFieldMap, isResp, registryClasses, projectBuilder, groupClasses, fieldPid));
- }
- }
- } else if (JavaClassValidateUtil.isArray(subTypeName)) {
- fieldGicName = fieldGicName.substring(0, fieldGicName.indexOf("["));
- if (className.equals(fieldGicName)) {
- //do nothing
- } else if (!JavaClassValidateUtil.isPrimitive(fieldGicName)) {
- paramList.addAll(buildParams(fieldGicName, preBuilder.toString(), nextLevel, isRequired,
- responseFieldMap, isResp, registryClasses, projectBuilder, groupClasses, fieldPid));
- }
- } else if (simpleName.equals(subTypeName)) {
- //do nothing
- } else {
- if (!javaClass.isEnum()) {
- paramList.addAll(buildParams(fieldGicName, preBuilder.toString(), nextLevel, isRequired,
- responseFieldMap, isResp, registryClasses, projectBuilder, groupClasses, fieldPid));
- }
- }
- }
- }
- }
- return paramList;
- }
-
- public static String dictionaryListComment(ApiDataDictionary dictionary) {
- List enumDataDict = dictionary.getEnumDataDict();
- return enumDataDict.stream().map(apiDataDictionary ->
- apiDataDictionary.getValue() + ":" + apiDataDictionary.getDesc()
- ).collect(Collectors.joining(","));
- }
-
- public static List primitiveReturnRespComment(String typeName) {
- StringBuilder comments = new StringBuilder();
- comments.append("The api directly returns the ").append(typeName).append(" type value.");
- ApiParam apiParam = ApiParam.of().setField("No field")
- .setType(typeName).setDesc(comments.toString()).setVersion(DocGlobalConstants.DEFAULT_VERSION);
- List paramList = new ArrayList<>();
- paramList.add(apiParam);
- return paramList;
- }
-
- private static void commonHandleParam(List paramList, ApiParam param, String isRequired, String comment, String since, boolean strRequired) {
- if (StringUtil.isEmpty(isRequired)) {
- param.setDesc(comment).setVersion(since);
- } else {
- param.setDesc(comment).setVersion(since).setRequired(strRequired);
- }
- param.setId(paramList.size() + param.getPid() + 1);
- paramList.add(param);
- }
-}
+/*
+ * smart-doc https://github.com/shalousun/smart-doc
+ *
+ * Copyright (C) 2018-2020 smart-doc
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package com.power.doc.helper;
+
+import com.power.common.model.EnumDictionary;
+import com.power.common.util.CollectionUtil;
+import com.power.common.util.StringUtil;
+import com.power.doc.builder.ProjectDocConfigBuilder;
+import com.power.doc.constants.DocAnnotationConstants;
+import com.power.doc.constants.DocGlobalConstants;
+import com.power.doc.constants.DocTags;
+import com.power.doc.constants.ValidatorAnnotations;
+import com.power.doc.model.*;
+import com.power.doc.utils.*;
+import com.thoughtworks.qdox.model.*;
+
+import java.util.*;
+import java.util.stream.Collectors;
+
+import static com.power.doc.constants.DocGlobalConstants.NO_COMMENTS_FOUND;
+
+/**
+ * @author yu 2019/12/21.
+ */
+public class ParamsBuildHelper {
+
+ public static List buildParams(String className, String pre, int level, String isRequired,
+ Map responseFieldMap, boolean isResp,
+ Map registryClasses, ProjectDocConfigBuilder projectBuilder,
+ List groupClasses, int pid) {
+ //存储泛型所对应的实体类
+ Map genericMap = new HashMap<>(10);
+
+ if (StringUtil.isEmpty(className)) {
+ throw new RuntimeException("Class name can't be null or empty.");
+ }
+ ApiConfig apiConfig = projectBuilder.getApiConfig();
+ int nextLevel = level + 1;
+ // Check circular reference
+ List paramList = new ArrayList<>();
+ if (level > apiConfig.getRecursionLimit()) {
+ return paramList;
+ }
+ if (registryClasses.containsKey(className) && level > registryClasses.size()) {
+ return paramList;
+ }
+ boolean skipTransientField = apiConfig.isSkipTransientField();
+ boolean isShowJavaType = projectBuilder.getApiConfig().getShowJavaType();
+ boolean requestFieldToUnderline = projectBuilder.getApiConfig().isRequestFieldToUnderline();
+ boolean responseFieldToUnderline = projectBuilder.getApiConfig().isResponseFieldToUnderline();
+ // Registry class
+ registryClasses.put(className, className);
+ String simpleName = DocClassUtil.getSimpleName(className);
+ String[] globGicName = DocClassUtil.getSimpleGicName(className);
+ JavaClass cls = projectBuilder.getClassByName(simpleName);
+ //如果存在泛型 则将泛型与类名的对应关系存起来
+ if (cls != null && null != cls.getTypeParameters()) {
+ List> variables = cls.getTypeParameters();
+ for (int i = 0; i < cls.getTypeParameters().size() && i fields = JavaClassUtil.getFields(cls, 0, new HashSet<>());
+ if (JavaClassValidateUtil.isPrimitive(simpleName)) {
+ String processedType = isShowJavaType ? simpleName : DocClassUtil.processTypeNameForParams(simpleName.toLowerCase());
+ paramList.addAll(primitiveReturnRespComment(processedType));
+ } else if (JavaClassValidateUtil.isCollection(simpleName) || JavaClassValidateUtil.isArray(simpleName)) {
+ if (!JavaClassValidateUtil.isCollection(globGicName[0])) {
+ String gicName = globGicName[0];
+ if (JavaClassValidateUtil.isArray(gicName)) {
+ gicName = gicName.substring(0, gicName.indexOf("["));
+ }
+ paramList.addAll(buildParams(gicName, pre, nextLevel, isRequired, responseFieldMap, isResp,
+ registryClasses, projectBuilder, groupClasses, pid));
+ }
+ } else if (JavaClassValidateUtil.isMap(simpleName)) {
+ if (globGicName.length == 2) {
+ paramList.addAll(buildParams(globGicName[1], pre, nextLevel, isRequired, responseFieldMap, isResp,
+ registryClasses, projectBuilder, groupClasses, pid));
+ }
+ } else if (DocGlobalConstants.JAVA_OBJECT_FULLY.equals(className)) {
+ ApiParam param = ApiParam.of().setField(pre + "any object").setType("object").setPid(pid);
+ if (StringUtil.isEmpty(isRequired)) {
+ param.setDesc(DocGlobalConstants.ANY_OBJECT_MSG).setVersion(DocGlobalConstants.DEFAULT_VERSION);
+ } else {
+ param.setDesc(DocGlobalConstants.ANY_OBJECT_MSG).setRequired(false).setVersion(DocGlobalConstants.DEFAULT_VERSION);
+ }
+ paramList.add(param);
+ }
+// if (className.contains(DocGlobalConstants.MULTIPART_FILE_FULLY)) {
+// ApiParam param = ApiParam.of().setField("").setType("file")
+// .setPid(pid)
+// .setDesc("comment").setRequired(true).setVersion(DocGlobalConstants.DEFAULT_VERSION);
+// paramList.add(param);
+// }
+ else {
+ boolean isGenerics = JavaFieldUtil.checkGenerics(fields);
+ out:
+ for (DocJavaField docField : fields) {
+ JavaField field = docField.getJavaField();
+ String fieldName = field.getName();
+ String subTypeName = field.getType().getFullyQualifiedName();
+ if (field.isStatic() || "this$0".equals(fieldName) ||
+ JavaClassValidateUtil.isIgnoreFieldTypes(subTypeName)) {
+ continue;
+ }
+ if (field.isTransient() && skipTransientField) {
+ continue;
+ }
+ if ((responseFieldToUnderline && isResp) || (requestFieldToUnderline && !isResp)) {
+ fieldName = StringUtil.camelToUnderline(fieldName);
+ }
+ String typeSimpleName = field.getType().getSimpleName();
+ String fieldGicName = field.getType().getGenericCanonicalName();
+ List javaAnnotations = docField.getAnnotations();
+
+ Map tagsMap = DocUtil.getFieldTagsValue(field, docField);
+ String since = DocGlobalConstants.DEFAULT_VERSION;//since tag value
+ if (!isResp) {
+ pre:
+ if (tagsMap.containsKey(DocTags.IGNORE)) {
+ continue out;
+ } else if (tagsMap.containsKey(DocTags.SINCE)) {
+ since = tagsMap.get(DocTags.SINCE);
+ }
+ } else {
+ if (tagsMap.containsKey(DocTags.SINCE)) {
+ since = tagsMap.get(DocTags.SINCE);
+ }
+ }
+
+ boolean strRequired = false;
+ int annotationCounter = 0;
+
+ an:
+ for (JavaAnnotation annotation : javaAnnotations) {
+ String simpleAnnotationName = annotation.getType().getValue();
+ if (DocAnnotationConstants.SHORT_JSON_IGNORE.equals(simpleAnnotationName)) {
+ continue out;
+ } else if (DocAnnotationConstants.SHORT_JSON_FIELD.equals(simpleAnnotationName)) {
+ if (null != annotation.getProperty(DocAnnotationConstants.SERIALIZE_PROP)) {
+ if (Boolean.FALSE.toString().equals(annotation.getProperty(DocAnnotationConstants.SERIALIZE_PROP).toString())) {
+ continue out;
+ }
+ } else if (null != annotation.getProperty(DocAnnotationConstants.NAME_PROP)) {
+ fieldName = StringUtil.removeQuotes(annotation.getProperty(DocAnnotationConstants.NAME_PROP).toString());
+ }
+ } else if (DocAnnotationConstants.SHORT_JSON_PROPERTY.equals(simpleAnnotationName)) {
+ if (null != annotation.getProperty(DocAnnotationConstants.VALUE_PROP)) {
+ fieldName = StringUtil.removeQuotes(annotation.getProperty(DocAnnotationConstants.VALUE_PROP).toString());
+ }
+ } else if (ValidatorAnnotations.NULL.equals(simpleAnnotationName) && !isResp) {
+ List groupClassList = JavaClassUtil.getParamGroupJavaClass(annotation);
+ for (String javaClass : groupClassList) {
+ if (groupClasses.contains(javaClass)) {
+ strRequired = false;
+ break an;
+ }
+ }
+ } else if (JavaClassValidateUtil.isJSR303Required(simpleAnnotationName) && !isResp) {
+ annotationCounter++;
+ boolean hasGroup = false;
+ List groupClassList = JavaClassUtil.getParamGroupJavaClass(annotation);
+ for (String javaClass : groupClassList) {
+ if (groupClasses.contains(javaClass)) {
+ hasGroup = true;
+ }
+ }
+ if (hasGroup) {
+ strRequired = true;
+ } else if (CollectionUtil.isEmpty(groupClasses)) {
+ strRequired = true;
+ }
+ break an;
+ }
+ }
+ if (annotationCounter < 1) {
+ doc:
+ if (tagsMap.containsKey(DocTags.REQUIRED)) {
+ strRequired = true;
+ break doc;
+ }
+ }
+ //cover comment
+ CustomRespField customResponseField = responseFieldMap.get(field.getName());
+ String comment;
+ if (null != customResponseField && StringUtil.isNotEmpty(customResponseField.getDesc())) {
+ comment = customResponseField.getDesc();
+ } else {
+ comment = docField.getComment();
+ }
+ if (StringUtil.isNotEmpty(comment)) {
+ comment = DocUtil.replaceNewLineToHtmlBr(comment);
+ }
+ if (JavaClassValidateUtil.isPrimitive(subTypeName)) {
+ ApiParam param = ApiParam.of().setField(pre + fieldName);
+ param.setPid(pid);
+ String processedType = isShowJavaType ? typeSimpleName : DocClassUtil.processTypeNameForParams(typeSimpleName.toLowerCase());
+ param.setType(processedType);
+ if (StringUtil.isNotEmpty(comment)) {
+ commonHandleParam(paramList, param, isRequired, comment, since, strRequired);
+ } else {
+ commonHandleParam(paramList, param, isRequired, NO_COMMENTS_FOUND, since, strRequired);
+ }
+ } else {
+ ApiParam param = ApiParam.of().setField(pre + fieldName).setPid(pid);
+ JavaClass javaClass = projectBuilder.getJavaProjectBuilder().getClassByName(subTypeName);
+ String enumComments = javaClass.getComment();
+ if (javaClass.isEnum()) {
+ 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 + "
" + JavaClassUtil.getEnumParams(javaClass) + "
";
+ if (enumComments != null) {
+ comment = comment + "(See: " + enumComments + ")";
+ }
+ comment = StringUtil.removeQuotes(comment);
+
+ }
+ param.setType(DocGlobalConstants.ENUM);
+ }
+ //如果是文件
+ if(typeSimpleName.contains(DocGlobalConstants.MULTIPART_FILE_FULLY)){
+ param.setType("file");
+ }
+ //如果已经设置返回类型 不需要再次设置
+ if (param.getType() == null) {
+ String processedType;
+ if (typeSimpleName.length() == 1) {
+ processedType = DocClassUtil.processTypeNameForParams(typeSimpleName.toLowerCase());
+ } else {
+ processedType = isShowJavaType ? typeSimpleName : DocClassUtil.processTypeNameForParams(typeSimpleName.toLowerCase());
+ }
+ param.setType(processedType);
+ }
+ if (!isResp && javaClass.isEnum()) {
+ List methods = javaClass.getMethods();
+ int index = 0;
+
+ enumOut:
+ for (JavaMethod method : methods) {
+ List javaAnnotationList = method.getAnnotations();
+ for (JavaAnnotation annotation : javaAnnotationList) {
+ if (annotation.getType().getValue().contains("JsonValue")) {
+ break enumOut;
+ }
+ }
+ if (CollectionUtil.isEmpty(javaAnnotations) && index < 1) {
+ break enumOut;
+ }
+ index++;
+ }
+ param.setType(DocGlobalConstants.ENUM);
+ }
+
+ if (StringUtil.isNotEmpty(comment)) {
+ commonHandleParam(paramList, param, isRequired, comment, since, strRequired);
+ } else {
+ commonHandleParam(paramList, param, isRequired, NO_COMMENTS_FOUND, since, strRequired);
+ }
+ StringBuilder preBuilder = new StringBuilder();
+ for (int j = 0; j < level; j++) {
+ preBuilder.append(DocGlobalConstants.FIELD_SPACE);
+ }
+ preBuilder.append("└─");
+ int fieldPid = paramList.size()+pid;
+ if (JavaClassValidateUtil.isMap(subTypeName)) {
+ String gNameTemp = field.getType().getGenericCanonicalName();
+ if (JavaClassValidateUtil.isMap(gNameTemp)) {
+ ApiParam param1 = ApiParam.of().setField(preBuilder.toString() + "any object")
+ .setId(paramList.size()+1).setPid(fieldPid)
+ .setType("object").setDesc(DocGlobalConstants.ANY_OBJECT_MSG).setVersion(DocGlobalConstants.DEFAULT_VERSION);
+ paramList.add(param1);
+ continue;
+ }
+ String valType = DocClassUtil.getMapKeyValueType(gNameTemp)[1];
+ if (!JavaClassValidateUtil.isPrimitive(valType)) {
+ if (valType.length() == 1) {
+ String gicName = genericMap.get(valType);
+ if (!JavaClassValidateUtil.isPrimitive(gicName) && !simpleName.equals(gicName)) {
+ paramList.addAll(buildParams(gicName, preBuilder.toString(), nextLevel, isRequired,
+ responseFieldMap, isResp, registryClasses, projectBuilder, groupClasses, fieldPid));
+ }
+ } else {
+ paramList.addAll(buildParams(valType, preBuilder.toString(), nextLevel, isRequired,
+ responseFieldMap, isResp, registryClasses, projectBuilder, groupClasses, fieldPid));
+ }
+ }
+ } else if (JavaClassValidateUtil.isCollection(subTypeName)) {
+ String gNameTemp = field.getType().getGenericCanonicalName();
+ if (globGicName.length > 0 && "java.util.List".equals(gNameTemp)) {
+ gNameTemp = gNameTemp + "";
+ }
+ String[] gNameArr = DocClassUtil.getSimpleGicName(gNameTemp);
+ if (gNameArr.length == 0) {
+ continue out;
+ }
+ String gName = DocClassUtil.getSimpleGicName(gNameTemp)[0];
+ if (!JavaClassValidateUtil.isPrimitive(gName)) {
+ if (!simpleName.equals(gName) && !gName.equals(simpleName)) {
+ if (gName.length() == 1) {
+ int len = globGicName.length;
+ if (len > 0) {
+ String gicName = genericMap.get(gName) != null ? genericMap.get(gName) : globGicName[0];
+ if (!JavaClassValidateUtil.isPrimitive(gicName) && !simpleName.equals(gicName)) {
+ paramList.addAll(buildParams(gicName, preBuilder.toString(), nextLevel, isRequired,
+ responseFieldMap, isResp, registryClasses, projectBuilder, groupClasses, fieldPid));
+ }
+ }
+ } else {
+ paramList.addAll(buildParams(gName, preBuilder.toString(), nextLevel, isRequired,
+ responseFieldMap, isResp, registryClasses, projectBuilder, groupClasses, fieldPid));
+ }
+ }
+ }
+ } else
+ if (subTypeName.length() == 1 || DocGlobalConstants.JAVA_OBJECT_FULLY.equals(subTypeName)) {
+ if (isGenerics && DocGlobalConstants.JAVA_OBJECT_FULLY.equals(subTypeName)) {
+ ApiParam param1 = ApiParam.of().setField(preBuilder.toString() + "any object")
+ .setId(paramList.size())
+ .setType("object").setDesc(DocGlobalConstants.ANY_OBJECT_MSG).setVersion(DocGlobalConstants.DEFAULT_VERSION);
+ paramList.add(param1);
+ } else if (!simpleName.equals(className)) {
+ if (globGicName.length > 0) {
+ String gicName = genericMap.get(subTypeName) != null ? genericMap.get(subTypeName) : globGicName[0];
+ String simple = DocClassUtil.getSimpleName(gicName);
+ if (JavaClassValidateUtil.isPrimitive(simple)) {
+ //do nothing
+ } else if (gicName.contains("<")) {
+ if (JavaClassValidateUtil.isCollection(simple)) {
+ String gName = DocClassUtil.getSimpleGicName(gicName)[0];
+ if (!JavaClassValidateUtil.isPrimitive(gName)) {
+ paramList.addAll(buildParams(gName, preBuilder.toString(), nextLevel, isRequired,
+ responseFieldMap, isResp, registryClasses, projectBuilder, groupClasses, fieldPid));
+ }
+ } else if (JavaClassValidateUtil.isMap(simple)) {
+ String valType = DocClassUtil.getMapKeyValueType(gicName)[1];
+ if (!JavaClassValidateUtil.isPrimitive(valType)) {
+ paramList.addAll(buildParams(valType, preBuilder.toString(), nextLevel, isRequired,
+ responseFieldMap, isResp, registryClasses, projectBuilder, groupClasses, fieldPid));
+ }
+ } else {
+ paramList.addAll(buildParams(gicName, preBuilder.toString(), nextLevel, isRequired,
+ responseFieldMap, isResp, registryClasses, projectBuilder, groupClasses, fieldPid));
+ }
+ } else {
+ paramList.addAll(buildParams(gicName, preBuilder.toString(), nextLevel, isRequired,
+ responseFieldMap, isResp, registryClasses, projectBuilder, groupClasses, fieldPid));
+ }
+ } else {
+ paramList.addAll(buildParams(subTypeName, preBuilder.toString(), nextLevel, isRequired,
+ responseFieldMap, isResp, registryClasses, projectBuilder, groupClasses, fieldPid));
+ }
+ }
+ } else if (JavaClassValidateUtil.isArray(subTypeName)) {
+ fieldGicName = fieldGicName.substring(0, fieldGicName.indexOf("["));
+ if (className.equals(fieldGicName)) {
+ //do nothing
+ } else if (!JavaClassValidateUtil.isPrimitive(fieldGicName)) {
+ paramList.addAll(buildParams(fieldGicName, preBuilder.toString(), nextLevel, isRequired,
+ responseFieldMap, isResp, registryClasses, projectBuilder, groupClasses, fieldPid));
+ }
+ } else if (simpleName.equals(subTypeName)) {
+ //do nothing
+ } else {
+ if (!javaClass.isEnum()) {
+ paramList.addAll(buildParams(fieldGicName, preBuilder.toString(), nextLevel, isRequired,
+ responseFieldMap, isResp, registryClasses, projectBuilder, groupClasses, fieldPid));
+ }
+ }
+ }
+ }
+ }
+ return paramList;
+ }
+
+ public static String dictionaryListComment(ApiDataDictionary dictionary) {
+ List enumDataDict = dictionary.getEnumDataDict();
+ return enumDataDict.stream().map(apiDataDictionary ->
+ apiDataDictionary.getValue() + ":" + apiDataDictionary.getDesc()
+ ).collect(Collectors.joining(","));
+ }
+
+ public static List primitiveReturnRespComment(String typeName) {
+ StringBuilder comments = new StringBuilder();
+ comments.append("The api directly returns the ").append(typeName).append(" type value.");
+ ApiParam apiParam = ApiParam.of().setField("No field")
+ .setType(typeName).setDesc(comments.toString()).setVersion(DocGlobalConstants.DEFAULT_VERSION);
+ List paramList = new ArrayList<>();
+ paramList.add(apiParam);
+ return paramList;
+ }
+
+ private static void commonHandleParam(List paramList, ApiParam param, String isRequired, String comment, String since, boolean strRequired) {
+ if (StringUtil.isEmpty(isRequired)) {
+ param.setDesc(comment).setVersion(since);
+ } else {
+ param.setDesc(comment).setVersion(since).setRequired(strRequired);
+ }
+ param.setId(paramList.size() + param.getPid() + 1);
+ paramList.add(param);
+ }
+}
diff --git a/src/main/java/com/power/doc/model/ApiParam.java b/src/main/java/com/power/doc/model/ApiParam.java
index 0137d45..7844f46 100644
--- a/src/main/java/com/power/doc/model/ApiParam.java
+++ b/src/main/java/com/power/doc/model/ApiParam.java
@@ -1,157 +1,162 @@
-/*
- * smart-doc
- *
- * Copyright (C) 2018-2020 smart-doc
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package com.power.doc.model;
-
-import java.util.List;
-
-/**
- * @author yu 2019/9/27.
- */
-public class ApiParam {
-
- /**
- * field id
- */
- private int id = 1;
-
- /**
- * field
- */
- private String field;
-
- /**
- * field type
- */
- private String type;
-
- /**
- * description
- */
- private String desc;
-
- /**
- * require flag
- */
- private boolean required;
-
- /**
- * version
- */
- private String version;
-
- /**
- * field pid
- */
- private int pid;
- /**
- * PathVariableParams flag
- */
- private boolean isPathParams;
-
- private List children;
-
- public static ApiParam of(){
- return new ApiParam();
- }
-
- public String getField() {
- return field;
- }
-
- public ApiParam setField(String field) {
- this.field = field;
- return this;
- }
-
- public String getType() {
- return type;
- }
-
- public ApiParam setType(String type) {
- this.type = type;
- return this;
- }
-
- public String getDesc() {
- return desc;
- }
-
- public ApiParam setDesc(String desc) {
- this.desc = desc;
- return this;
- }
-
- public boolean isRequired() {
- return required;
- }
-
- public ApiParam setRequired(boolean required) {
- this.required = required;
- return this;
- }
-
- public String getVersion() {
- return version;
- }
-
- public ApiParam setVersion(String version) {
- this.version = version;
- return this;
- }
-
- public int getId() {
- return id;
- }
-
- public ApiParam setId(int id) {
- this.id = id;
- return this;
- }
-
- public int getPid() {
- return pid;
- }
-
- public ApiParam setPid(int pid) {
- this.pid = pid;
- return this;
- }
-
- public List getChildren() {
- return children;
- }
-
- public boolean isPathParams() {
- return isPathParams;
- }
-
- public ApiParam setPathParams(boolean pathParams) {
- isPathParams = pathParams;
- return this;
- }
-
- public ApiParam setChildren(List children) {
- this.children = children;
- return this;
- }
-}
+/*
+ * smart-doc
+ *
+ * Copyright (C) 2018-2020 smart-doc
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package com.power.doc.model;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @author yu 2019/9/27.
+ */
+public class ApiParam {
+
+ /**
+ * field id
+ */
+ private int id = 1;
+
+ /**
+ * field
+ */
+ private String field;
+
+ /**
+ * field type
+ */
+ private String type;
+
+ /**
+ * description
+ */
+ private String desc;
+
+ /**
+ * require flag
+ */
+ private boolean required;
+
+ /**
+ * version
+ */
+ private String version;
+
+ /**
+ * field pid
+ */
+ private int pid;
+
+ /**
+ * PathVariableParams flag
+ */
+ private boolean isPathParams;
+
+ /**
+ * children params
+ */
+ private List children;
+
+ public static ApiParam of(){
+ return new ApiParam();
+ }
+
+ public String getField() {
+ return field;
+ }
+
+ public ApiParam setField(String field) {
+ this.field = field;
+ return this;
+ }
+
+ public String getType() {
+ return type;
+ }
+
+ public ApiParam setType(String type) {
+ this.type = type;
+ return this;
+ }
+
+ public String getDesc() {
+ return desc;
+ }
+
+ public ApiParam setDesc(String desc) {
+ this.desc = desc;
+ return this;
+ }
+
+ public boolean isRequired() {
+ return required;
+ }
+
+ public ApiParam setRequired(boolean required) {
+ this.required = required;
+ return this;
+ }
+
+ public String getVersion() {
+ return version;
+ }
+
+ public ApiParam setVersion(String version) {
+ this.version = version;
+ return this;
+ }
+
+ public int getId() {
+ return id;
+ }
+
+ public ApiParam setId(int id) {
+ this.id = id;
+ return this;
+ }
+
+ public int getPid() {
+ return pid;
+ }
+
+ public ApiParam setPid(int pid) {
+ this.pid = pid;
+ return this;
+ }
+
+ public List getChildren() {
+ return children;
+ }
+
+ public boolean isPathParams() {
+ return isPathParams;
+ }
+
+ public ApiParam setPathParams(boolean pathParams) {
+ isPathParams = pathParams;
+ return this;
+ }
+
+ public ApiParam setChildren(List children) {
+ this.children = children;
+ return this;
+ }
+}
diff --git a/src/main/java/com/power/doc/template/SpringBootDocBuildTemplate.java b/src/main/java/com/power/doc/template/SpringBootDocBuildTemplate.java
index d3d91c2..284b3cd 100644
--- a/src/main/java/com/power/doc/template/SpringBootDocBuildTemplate.java
+++ b/src/main/java/com/power/doc/template/SpringBootDocBuildTemplate.java
@@ -22,7 +22,10 @@
*/
package com.power.doc.template;
-import com.power.common.util.*;
+import com.power.common.util.JsonFormatUtil;
+import com.power.common.util.RandomUtil;
+import com.power.common.util.StringUtil;
+import com.power.common.util.UrlUtil;
import com.power.doc.builder.ProjectDocConfigBuilder;
import com.power.doc.constants.*;
import com.power.doc.handler.SpringMVCRequestHeaderHandler;
@@ -44,7 +47,6 @@ import java.util.stream.Stream;
import static com.power.doc.constants.DocGlobalConstants.FILE_CONTENT_TYPE;
import static com.power.doc.constants.DocGlobalConstants.JSON_CONTENT_TYPE;
import static com.power.doc.constants.DocTags.IGNORE;
-import static com.power.doc.constants.DocTags.PARAM;
/**
* @author yu 2019/12/21.
@@ -90,8 +92,8 @@ public class SpringBootDocBuildTemplate implements IDocBuildTemplate {
}
@Override
- public boolean ignoreReturnObject(String typeName,List ignoreParams) {
- if (JavaClassValidateUtil.isMvcIgnoreParams(typeName,ignoreParams)) {
+ public boolean ignoreReturnObject(String typeName, List ignoreParams) {
+ if (JavaClassValidateUtil.isMvcIgnoreParams(typeName, ignoreParams)) {
return DocGlobalConstants.MODE_AND_VIEW_FULLY.equals(typeName);
}
return false;
@@ -165,6 +167,17 @@ public class SpringBootDocBuildTemplate implements IDocBuildTemplate {
requestParams = ApiParamTreeUtil.apiParamToTree(requestParams);
}
apiMethodDoc.setRequestParams(requestParams);
+ List allApiReqHeaders;
+ if (this.headers != null) {
+ allApiReqHeaders = Stream.of(this.headers, apiReqHeaders)
+ .flatMap(Collection::stream).distinct().collect(Collectors.toList());
+ } else {
+ allApiReqHeaders = apiReqHeaders;
+ }
+ //reduce create in template
+ apiMethodDoc.setHeaders(this.createDocRenderHeaders(allApiReqHeaders, apiConfig.isAdoc()));
+ apiMethodDoc.setRequestHeaders(allApiReqHeaders);
+
// build request json
ApiRequestExample requestExample = buildReqJson(method, apiMethodDoc, requestMapping.getMethodType(),
projectBuilder);
@@ -180,16 +193,6 @@ public class SpringBootDocBuildTemplate implements IDocBuildTemplate {
responseParams = ApiParamTreeUtil.apiParamToTree(responseParams);
}
apiMethodDoc.setResponseParams(responseParams);
- List allApiReqHeaders;
- if (this.headers != null) {
- allApiReqHeaders = Stream.of(this.headers, apiReqHeaders)
- .flatMap(Collection::stream).distinct().collect(Collectors.toList());
- } else {
- allApiReqHeaders = apiReqHeaders;
- }
- //reduce create in template
- apiMethodDoc.setHeaders(this.createDocRenderHeaders(allApiReqHeaders, apiConfig.isAdoc()));
- apiMethodDoc.setRequestHeaders(allApiReqHeaders);
methodDocList.add(apiMethodDoc);
}
}
@@ -199,9 +202,18 @@ public class SpringBootDocBuildTemplate implements IDocBuildTemplate {
private ApiRequestExample buildReqJson(JavaMethod method, ApiMethodDoc apiMethodDoc, String methodType,
ProjectDocConfigBuilder configBuilder) {
List parameterList = method.getParameters();
- if (parameterList.size() < 1) {
- return ApiRequestExample.builder().setUrl(apiMethodDoc.getUrl());
+ List reqHeaderList = apiMethodDoc.getRequestHeaders();
+ StringBuilder header = new StringBuilder(reqHeaderList.size());
+ for (ApiReqHeader reqHeader : reqHeaderList) {
+ header.append(" -H ").append("'").append(reqHeader.getName())
+ .append(":").append(reqHeader.getValue()).append("'");
}
+ if (parameterList.size() < 1) {
+ String format = String.format(DocGlobalConstants.CURL_REQUEST_TYPE, methodType,
+ header.toString(), apiMethodDoc.getUrl());
+ return ApiRequestExample.builder().setUrl(apiMethodDoc.getUrl()).setExampleBody(format);
+ }
+
Map constantsMap = configBuilder.getConstantsMap();
boolean requestFieldToUnderline = configBuilder.getApiConfig().isRequestFieldToUnderline();
Map replacementMap = configBuilder.getReplaceClassMap();
@@ -210,7 +222,6 @@ public class SpringBootDocBuildTemplate implements IDocBuildTemplate {
List springMvcRequestAnnotations = SpringMvcRequestAnnotationsEnum.listSpringMvcRequestAnnotations();
List formDataList = new ArrayList<>();
ApiRequestExample requestExample = ApiRequestExample.builder();
- Set jsonParamSet = this.jsonParamSet(parameterList);
out:
for (JavaParameter parameter : parameterList) {
JavaType javaType = parameter.getType();
@@ -218,12 +229,9 @@ public class SpringBootDocBuildTemplate implements IDocBuildTemplate {
String typeName = javaType.getFullyQualifiedName();
String gicTypeName = javaType.getGenericCanonicalName();
String rewriteClassName = null;
- if (jsonParamSet.size() > 0 && !jsonParamSet.contains(paramName)) {
- continue;
- }
String commentClass = paramsComments.get(paramName);
//ignore request params
- if(Objects.nonNull(commentClass) && commentClass.contains(IGNORE)){
+ if (Objects.nonNull(commentClass) && commentClass.contains(IGNORE)) {
continue;
}
if (Objects.nonNull(commentClass) && !DocGlobalConstants.NO_COMMENTS_FOUND.equals(commentClass)) {
@@ -237,7 +245,7 @@ public class SpringBootDocBuildTemplate implements IDocBuildTemplate {
gicTypeName = rewriteClassName;
typeName = DocClassUtil.getSimpleName(rewriteClassName);
}
- if (JavaClassValidateUtil.isMvcIgnoreParams(typeName,configBuilder.getApiConfig().getIgnoreRequestParams())) {
+ if (JavaClassValidateUtil.isMvcIgnoreParams(typeName, configBuilder.getApiConfig().getIgnoreRequestParams())) {
continue;
}
String simpleTypeName = javaType.getValue().toLowerCase();
@@ -380,18 +388,19 @@ public class SpringBootDocBuildTemplate implements IDocBuildTemplate {
body = StringUtil.removeQuotes(body);
url = apiMethodDoc.getServerUrl() + "/" + path;
url = UrlUtil.simplifyUrl(url);
+ String format = String.format(DocGlobalConstants.CURL_REQUEST_TYPE, methodType, header.toString(), url);
if (requestExample.isJson()) {
if (StringUtil.isNotEmpty(requestExample.getJsonBody())) {
- exampleBody = String.format(DocGlobalConstants.CURL_POST_PUT_JSON, methodType, url,
+ exampleBody = String.format(DocGlobalConstants.CURL_POST_PUT_JSON, methodType,header.toString(), url,
requestExample.getJsonBody());
} else {
- exampleBody = String.format(DocGlobalConstants.CURL_REQUEST_TYPE, methodType, url);
+ exampleBody = format;
}
} else {
if (StringUtil.isNotEmpty(body)) {
- exampleBody = String.format(DocGlobalConstants.CURL_REQUEST_TYPE_DATA, methodType, url, body);
+ exampleBody = String.format(DocGlobalConstants.CURL_REQUEST_TYPE_DATA, methodType,header.toString(), url, body);
} else {
- exampleBody = String.format(DocGlobalConstants.CURL_REQUEST_TYPE, methodType, url);
+ exampleBody = format;
}
}
requestExample.setExampleBody(exampleBody).setUrl(url);
@@ -403,7 +412,7 @@ public class SpringBootDocBuildTemplate implements IDocBuildTemplate {
url = StringUtil.removeQuotes(url);
url = apiMethodDoc.getServerUrl() + "/" + url;
url = UrlUtil.simplifyUrl(url);
- exampleBody = String.format(DocGlobalConstants.CURL_REQUEST_TYPE, methodType, url);
+ exampleBody = String.format(DocGlobalConstants.CURL_REQUEST_TYPE, methodType,header.toString(), url);
requestExample.setExampleBody(exampleBody)
.setJsonBody(DocGlobalConstants.EMPTY)
.setUrl(url);
@@ -424,15 +433,11 @@ public class SpringBootDocBuildTemplate implements IDocBuildTemplate {
}
Map constantsMap = builder.getConstantsMap();
boolean requestFieldToUnderline = builder.getApiConfig().isRequestFieldToUnderline();
- Set jsonParamSet = this.jsonParamSet(parameterList);
List paramList = new ArrayList<>();
int requestBodyCounter = 0;
out:
for (JavaParameter parameter : parameterList) {
String paramName = parameter.getName();
- if (jsonParamSet.size() > 0 && !jsonParamSet.contains(paramName)) {
- continue;
- }
String typeName = parameter.getType().getGenericCanonicalName();
String simpleName = parameter.getType().getValue().toLowerCase();
String fullTypeName = parameter.getType().getFullyQualifiedName();
@@ -449,7 +454,7 @@ public class SpringBootDocBuildTemplate implements IDocBuildTemplate {
typeName = rewriteClassName;
fullTypeName = DocClassUtil.getSimpleName(rewriteClassName);
}
- if (JavaClassValidateUtil.isMvcIgnoreParams(typeName,builder.getApiConfig().getIgnoreRequestParams())) {
+ if (JavaClassValidateUtil.isMvcIgnoreParams(typeName, builder.getApiConfig().getIgnoreRequestParams())) {
continue out;
}
fullTypeName = DocClassUtil.rewriteRequestParam(fullTypeName);
@@ -482,7 +487,7 @@ public class SpringBootDocBuildTemplate implements IDocBuildTemplate {
}
if (SpringMvcAnnotations.REQUEST_PARAM.equals(annotationName) ||
DocAnnotationConstants.SHORT_PATH_VARIABLE.equals(annotationName)) {
- if(DocAnnotationConstants.SHORT_PATH_VARIABLE.equals(annotationName)){
+ if (DocAnnotationConstants.SHORT_PATH_VARIABLE.equals(annotationName)) {
isPathVariable = true;
}
paramName = getParamName(paramName, annotation);
@@ -508,8 +513,8 @@ public class SpringBootDocBuildTemplate implements IDocBuildTemplate {
}
}
Boolean required = Boolean.parseBoolean(strRequired);
- if(isPathVariable){
- comment = comment +" (This is path param)";
+ if (isPathVariable) {
+ comment = comment + " (This is path param)";
}
if (JavaClassValidateUtil.isCollection(fullTypeName) || JavaClassValidateUtil.isArray(fullTypeName)) {
String[] gicNameArr = DocClassUtil.getSimpleGicName(typeName);
@@ -600,19 +605,4 @@ public class SpringBootDocBuildTemplate implements IDocBuildTemplate {
}
return false;
}
-
- public Set jsonParamSet(List parameterList) {
- Set jsonParamSet = new HashSet<>();
- for (JavaParameter parameter : parameterList) {
- String paramName = parameter.getName();
- List annotations = parameter.getAnnotations();
- for (JavaAnnotation annotation : annotations) {
- String annotationName = annotation.getType().getValue();
- if (SpringMvcAnnotations.REQUEST_BODY.equals(annotationName)) {
- jsonParamSet.add(paramName);
- }
- }
- }
- return jsonParamSet;
- }
}
diff --git a/src/main/java/com/power/doc/utils/ApiParamTreeUtil.java b/src/main/java/com/power/doc/utils/ApiParamTreeUtil.java
index 89736c0..a0f250b 100644
--- a/src/main/java/com/power/doc/utils/ApiParamTreeUtil.java
+++ b/src/main/java/com/power/doc/utils/ApiParamTreeUtil.java
@@ -46,6 +46,9 @@ public class ApiParamTreeUtil {
childList.add(param);
}
}
+ for (ApiParam param : childList) {
+ param.setChildren(getChild(param.getId(), apiParamList));
+ }
if (childList.size() == 0) {
return null;
}
diff --git a/src/main/java/com/power/doc/utils/DocClassUtil.java b/src/main/java/com/power/doc/utils/DocClassUtil.java
index f95d3bf..6bda8fd 100644
--- a/src/main/java/com/power/doc/utils/DocClassUtil.java
+++ b/src/main/java/com/power/doc/utils/DocClassUtil.java
@@ -1,254 +1,254 @@
-/*
- * smart-doc
- *
- * Copyright (C) 2018-2020 smart-doc
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package com.power.doc.utils;
-
-import com.power.common.util.StringUtil;
-import com.power.doc.filter.ReturnTypeProcessor;
-import com.power.doc.model.ApiReturn;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Stack;
-
-/**
- * Description:
- * Doc class handle util
- *
- * @author yu 2018//14.
- */
-public class DocClassUtil {
-
-
- /**
- * get class names by generic class name
- *
- * @param returnType generic class name
- * @return array of string
- */
- public static String[] getSimpleGicName(String returnType) {
- if (returnType.contains("<")) {
- String pre = returnType.substring(0, returnType.indexOf("<"));
- if (JavaClassValidateUtil.isMap(pre)) {
- return getMapKeyValueType(returnType);
- }
- String type = returnType.substring(returnType.indexOf("<") + 1, returnType.lastIndexOf(">"));
- if (JavaClassValidateUtil.isCollection(pre)) {
- return type.split(" ");
- }
- String[] arr = type.split(",");
- return classNameFix(arr);
- } else {
- return returnType.split(" ");
- }
- }
-
- /**
- * Get a simple type name from a generic class name
- *
- * @param gicName Generic class name
- * @return String
- */
- public static String getSimpleName(String gicName) {
- if (gicName.contains("<")) {
- return gicName.substring(0, gicName.indexOf("<"));
- } else {
- return gicName;
- }
- }
-
- /**
- * Automatic repair of generic split class names
- *
- * @param arr arr of class name
- * @return array of String
- */
- private static String[] classNameFix(String[] arr) {
- List classes = new ArrayList<>();
- List indexList = new ArrayList<>();
- int globIndex = 0;
- int length = arr.length;
- for (int i = 0; i < length; i++) {
- if (classes.size() > 0) {
- int index = classes.size() - 1;
- if (!isClassName(classes.get(index))) {
- globIndex = globIndex + 1;
- if (globIndex < length) {
- indexList.add(globIndex);
- String className = classes.get(index) + "," + arr[globIndex];
- classes.set(index, className);
- }
- } else {
- globIndex = globIndex + 1;
- if (globIndex < length) {
- if (isClassName(arr[globIndex])) {
- indexList.add(globIndex);
- classes.add(arr[globIndex]);
- } else {
- if (!indexList.contains(globIndex) && !indexList.contains(globIndex + 1)) {
- indexList.add(globIndex);
- classes.add(arr[globIndex] + "," + arr[globIndex + 1]);
- globIndex = globIndex + 1;
- indexList.add(globIndex);
- }
- }
- }
- }
- } else {
- if (isClassName(arr[i])) {
- indexList.add(i);
- classes.add(arr[i]);
- } else {
- if (!indexList.contains(i) && !indexList.contains(i + 1)) {
- globIndex = i + 1;
- classes.add(arr[i] + "," + arr[globIndex]);
- indexList.add(i);
- indexList.add(i + 1);
- }
- }
- }
- }
- return classes.toArray(new String[classes.size()]);
- }
-
- /**
- * get map key and value type name populate into array.
- *
- * @param gName generic class name
- * @return array of string
- */
- public static String[] getMapKeyValueType(String gName) {
- if (gName.contains("<")) {
- String[] arr = new String[2];
- String key = gName.substring(gName.indexOf("<") + 1, gName.indexOf(","));
- String value = gName.substring(gName.indexOf(",") + 1, gName.lastIndexOf(">"));
- arr[0] = key;
- arr[1] = value;
- return arr;
- } else {
- return new String[0];
- }
-
- }
-
- /**
- * Convert the parameter types exported to the api document
- *
- * @param javaTypeName java simple typeName
- * @return String
- */
- public static String processTypeNameForParams(String javaTypeName) {
- if (StringUtil.isEmpty(javaTypeName)) {
- return "object";
- }
- if (javaTypeName.length() == 1) {
- return "object";
- }
- if (javaTypeName.contains("[]")) {
- return "array";
- }
- switch (javaTypeName) {
- case "java.lang.String":
- case "string":
- case "char":
- case "java.util.Byte":
- case "byte":
- case "date":
- case "localdatetime":
- case "localdate":
- case "localtime":
- case "timestamp":
- return "string";
- case "java.util.List":
- case "list":
- return "array";
- case "java.lang.Integer":
- case "integer":
- case "int":
- return "int32";
- case "short":
- case "java.lang.Short":
- return "int16";
- case "double":
- return "double";
- case "java.lang.Long":
- case "long":
- return "int64";
- case "java.lang.Float":
- case "float":
- return "float";
- case "bigdecimal":
- case "biginteger":
- return "number";
- case "java.lang.Boolean":
- case "boolean":
- return "boolean";
- case "map":
- return "map";
- case "multipartfile":
- return "file";
- default:
- return "object";
- }
-
- }
-
- /**
- * process return type
- *
- * @param fullyName fully name
- * @return ApiReturn
- */
- public static ApiReturn processReturnType(String fullyName) {
- ReturnTypeProcessor processor = new ReturnTypeProcessor();
- processor.setTypeName(fullyName);
- return processor.process();
- }
-
- /**
- * rewrite request param
- *
- * @param typeName param type name
- * @return String
- */
- public static String rewriteRequestParam(String typeName) {
- switch (typeName) {
- case "org.springframework.data.domain.Pageable":
- return "org.springframework.data.domain.PageRequest";
- default:
- return typeName;
- }
- }
-
- private static boolean isClassName(String className) {
- className = className.replaceAll("[^<>]", "");
- Stack stack = new Stack<>();
- for (char c : className.toCharArray()) {
- if (c == '<') {
- stack.push('>');
- } else if (stack.isEmpty() || c != stack.pop()) {
- return false;
- }
- }
- return stack.isEmpty();
- }
-}
+/*
+ * smart-doc
+ *
+ * Copyright (C) 2018-2020 smart-doc
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package com.power.doc.utils;
+
+import com.power.common.util.StringUtil;
+import com.power.doc.filter.ReturnTypeProcessor;
+import com.power.doc.model.ApiReturn;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Description:
+ * Doc class handle util
+ *
+ * @author yu 2018//14.
+ */
+public class DocClassUtil {
+
+
+ /**
+ * get class names by generic class name
+ *
+ * @param returnType generic class name
+ * @return array of string
+ */
+ public static String[] getSimpleGicName(String returnType) {
+ if (returnType.contains("<")) {
+ String pre = returnType.substring(0, returnType.indexOf("<"));
+ if (JavaClassValidateUtil.isMap(pre)) {
+ return getMapKeyValueType(returnType);
+ }
+ String type = returnType.substring(returnType.indexOf("<") + 1, returnType.lastIndexOf(">"));
+ if (JavaClassValidateUtil.isCollection(pre)) {
+ return type.split(" ");
+ }
+ String[] arr = type.split(",");
+ return classNameFix(arr);
+ } else {
+ return returnType.split(" ");
+ }
+ }
+
+ /**
+ * Get a simple type name from a generic class name
+ *
+ * @param gicName Generic class name
+ * @return String
+ */
+ public static String getSimpleName(String gicName) {
+ if (gicName.contains("<")) {
+ return gicName.substring(0, gicName.indexOf("<"));
+ } else {
+ return gicName;
+ }
+ }
+
+ /**
+ * Automatic repair of generic split class names
+ *
+ * @param arr arr of class name
+ * @return array of String
+ */
+ private static String[] classNameFix(String[] arr) {
+ List classes = new ArrayList<>();
+ List indexList = new ArrayList<>();
+ int globIndex = 0;
+ int length = arr.length;
+ for (int i = 0; i < length; i++) {
+ if (classes.size() > 0) {
+ int index = classes.size() - 1;
+ if (!isClassName(classes.get(index))) {
+ globIndex = globIndex + 1;
+ if (globIndex < length) {
+ indexList.add(globIndex);
+ String className = classes.get(index) + "," + arr[globIndex];
+ classes.set(index, className);
+ }
+ } else {
+ globIndex = globIndex + 1;
+ if (globIndex < length) {
+ if (isClassName(arr[globIndex])) {
+ indexList.add(globIndex);
+ classes.add(arr[globIndex]);
+ } else {
+ if (!indexList.contains(globIndex) && !indexList.contains(globIndex + 1)) {
+ indexList.add(globIndex);
+ classes.add(arr[globIndex] + "," + arr[globIndex + 1]);
+ globIndex = globIndex + 1;
+ indexList.add(globIndex);
+ }
+ }
+ }
+ }
+ } else {
+ if (isClassName(arr[i])) {
+ indexList.add(i);
+ classes.add(arr[i]);
+ } else {
+ if (!indexList.contains(i) && !indexList.contains(i + 1)) {
+ globIndex = i + 1;
+ classes.add(arr[i] + "," + arr[globIndex]);
+ indexList.add(i);
+ indexList.add(i + 1);
+ }
+ }
+ }
+ }
+ return classes.toArray(new String[classes.size()]);
+ }
+
+ /**
+ * get map key and value type name populate into array.
+ *
+ * @param gName generic class name
+ * @return array of string
+ */
+ public static String[] getMapKeyValueType(String gName) {
+ if (gName.contains("<")) {
+ String[] arr = new String[2];
+ String key = gName.substring(gName.indexOf("<") + 1, gName.indexOf(","));
+ String value = gName.substring(gName.indexOf(",") + 1, gName.lastIndexOf(">"));
+ arr[0] = key;
+ arr[1] = value;
+ return arr;
+ } else {
+ return new String[0];
+ }
+
+ }
+
+ /**
+ * Convert the parameter types exported to the api document
+ *
+ * @param javaTypeName java simple typeName
+ * @return String
+ */
+ public static String processTypeNameForParams(String javaTypeName) {
+ if (StringUtil.isEmpty(javaTypeName)) {
+ return "object";
+ }
+ if (javaTypeName.length() == 1) {
+ return "object";
+ }
+ if (javaTypeName.contains("[]")) {
+ return "array";
+ }
+ switch (javaTypeName) {
+ case "java.lang.String":
+ case "string":
+ case "char":
+ case "java.util.Byte":
+ case "byte":
+ case "date":
+ case "localdatetime":
+ case "localdate":
+ case "localtime":
+ case "timestamp":
+ return "string";
+ case "java.util.List":
+ case "list":
+ return "array";
+ case "java.lang.Integer":
+ case "integer":
+ case "int":
+ return "int32";
+ case "short":
+ case "java.lang.Short":
+ return "int16";
+ case "double":
+ return "double";
+ case "java.lang.Long":
+ case "long":
+ return "int64";
+ case "java.lang.Float":
+ case "float":
+ return "float";
+ case "bigdecimal":
+ case "biginteger":
+ return "number";
+ case "java.lang.Boolean":
+ case "boolean":
+ return "boolean";
+ case "map":
+ return "map";
+ case "multipartfile":
+ return "file";
+ default:
+ return "object";
+ }
+
+ }
+
+ /**
+ * process return type
+ *
+ * @param fullyName fully name
+ * @return ApiReturn
+ */
+ public static ApiReturn processReturnType(String fullyName) {
+ ReturnTypeProcessor processor = new ReturnTypeProcessor();
+ processor.setTypeName(fullyName);
+ return processor.process();
+ }
+
+ /**
+ * rewrite request param
+ *
+ * @param typeName param type name
+ * @return String
+ */
+ public static String rewriteRequestParam(String typeName) {
+ switch (typeName) {
+ case "org.springframework.data.domain.Pageable":
+ return "org.springframework.data.domain.PageRequest";
+ default:
+ return typeName;
+ }
+ }
+
+ private static boolean isClassName(String className) {
+ if (StringUtil.isEmpty(className)) {
+ return false;
+ }
+ if (className.contains("<") && !className.contains(">")) {
+ return false;
+ } else if (className.contains(">") && !className.contains("<")) {
+ return false;
+ } else {
+ return true;
+ }
+ }
+}
+
diff --git a/src/main/java/com/power/doc/utils/Iterables.java b/src/main/java/com/power/doc/utils/Iterables.java
new file mode 100644
index 0000000..808ba86
--- /dev/null
+++ b/src/main/java/com/power/doc/utils/Iterables.java
@@ -0,0 +1,14 @@
+package com.power.doc.utils;
+
+import java.util.function.BiConsumer;
+
+public class Iterables {
+ public static void forEach(
+ Iterable extends E> elements, BiConsumer action) {
+ if(elements==null||action==null) return;
+ int index = 0;
+ for (E element : elements) {
+ action.accept(index++, element);
+ }
+ }
+}
diff --git a/src/main/java/com/power/doc/utils/JavaClassValidateUtil.java b/src/main/java/com/power/doc/utils/JavaClassValidateUtil.java
index 12e10ca..df40bd9 100644
--- a/src/main/java/com/power/doc/utils/JavaClassValidateUtil.java
+++ b/src/main/java/com/power/doc/utils/JavaClassValidateUtil.java
@@ -1,251 +1,253 @@
-/*
- * smart-doc
- *
- * Copyright (C) 2018-2020 smart-doc
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package com.power.doc.utils;
-
-import com.power.common.util.CollectionUtil;
-
-import java.util.List;
-import java.util.Objects;
-
-/**
- * @author yu 2019/12/25.
- */
-public class JavaClassValidateUtil {
-
- /**
- * Check if it is the basic data array type of json data
- *
- * @param type0 java class name
- * @return boolean
- */
- public static boolean isPrimitiveArray(String type0) {
- String type = type0.contains("java.lang") ? type0.substring(type0.lastIndexOf(".") + 1, type0.length()) : type0;
- type = type.toLowerCase();
- switch (type) {
- case "integer[]":
- case "void":
- case "int[]":
- case "long[]":
- case "double[]":
- case "float[]":
- case "short[]":
- case "bigdecimal[]":
- case "char[]":
- case "string[]":
- case "boolean[]":
- case "byte[]":
- return true;
- default:
- return false;
- }
- }
-
- /**
- * Check if it is the basic data type of json data
- *
- * @param type0 java class name
- * @return boolean
- */
- public static boolean isPrimitive(String type0) {
- if (Objects.isNull(type0)) {
- return true;
- }
- String type = type0.contains("java.lang") ? type0.substring(type0.lastIndexOf(".") + 1, type0.length()) : type0;
- type = type.toLowerCase();
- switch (type) {
- case "integer":
- case "void":
- case "int":
- case "long":
- case "double":
- case "float":
- case "short":
- case "bigdecimal":
- case "char":
- case "string":
- case "boolean":
- case "byte":
- case "java.sql.timestamp":
- case "java.util.date":
- case "java.time.localdatetime":
- case "java.time.localtime":
- case "localdatetime":
- case "localdate":
- case "java.time.localdate":
- case "java.math.bigdecimal":
- case "java.math.biginteger":
- case "java.io.serializable":
- return true;
- default:
- return false;
- }
- }
-
- /**
- * validate java collection
- *
- * @param type java typeName
- * @return boolean
- */
- public static boolean isCollection(String type) {
- switch (type) {
- case "java.util.List":
- case "java.util.LinkedList":
- case "java.util.ArrayList":
- case "java.util.Set":
- case "java.util.TreeSet":
- case "java.util.HashSet":
- case "java.util.SortedSet":
- case "java.util.Collection":
- case "java.util.ArrayDeque":
- case "java.util.PriorityQueue":
- return true;
- default:
- return false;
- }
- }
-
- /**
- * Check if it is an map
- *
- * @param type java type
- * @return boolean
- */
- public static boolean isMap(String type) {
- switch (type) {
- case "java.util.Map":
- case "java.util.SortedMap":
- case "java.util.TreeMap":
- case "java.util.LinkedHashMap":
- case "java.util.HashMap":
- case "java.util.concurrent.ConcurrentHashMap":
- case "java.util.concurrent.ConcurrentMap":
- case "java.util.Properties":
- case "java.util.Hashtable":
- return true;
- default:
- return false;
- }
- }
-
- /**
- * check array
- *
- * @param type type name
- * @return boolean
- */
- public static boolean isArray(String type) {
- return type.contains("[]");
- }
-
- /**
- * check JSR303
- *
- * @param annotationSimpleName annotation name
- * @return boolean
- */
- public static boolean isJSR303Required(String annotationSimpleName) {
- switch (annotationSimpleName) {
- case "NotNull":
- case "NotEmpty":
- case "NotBlank":
- case "Required":
- return true;
- default:
- return false;
- }
- }
-
-
- /**
- * custom tag
- *
- * @param tagName custom field tag
- * @return boolean
- */
- public static boolean isRequiredTag(String tagName) {
- switch (tagName) {
- case "required":
- return true;
- default:
- return false;
- }
- }
-
- /**
- * ignore tag request field
- *
- * @param tagName custom field tag
- * @return boolean
- */
- public static boolean isIgnoreTag(String tagName) {
- switch (tagName) {
- case "ignore":
- return true;
- default:
- return false;
- }
- }
-
- /**
- * ignore param of spring mvc
- *
- * @param paramType param type name
- * @return boolean
- */
- public static boolean isMvcIgnoreParams(String paramType,List ignoreParams) {
- if(CollectionUtil.isNotEmpty(ignoreParams) && ignoreParams.contains(paramType)){
- return true;
- }
- switch (paramType) {
- case "org.springframework.ui.Model":
- case "org.springframework.ui.ModelMap":
- case "org.springframework.web.servlet.ModelAndView":
- case "org.springframework.validation.BindingResult":
- case "javax.servlet.http.HttpServletRequest":
- case "org.springframework.web.context.request.WebRequest":
- case "javax.servlet.http.HttpSession":
- case "javax.servlet.http.HttpServletResponse":
- case "org.springframework.web.reactive.function.server.ServerRequest":
- return true;
- default:
- return false;
- }
- }
-
- /**
- * ignore field type name
- *
- * @param typeName field type name
- * @return String
- */
- public static boolean isIgnoreFieldTypes(String typeName) {
- switch (typeName) {
- case "org.slf4j.Logger":
- case "org.apache.ibatis.logging.Log":
- return true;
- default:
- return false;
- }
- }
-}
+/*
+ * smart-doc
+ *
+ * Copyright (C) 2018-2020 smart-doc
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package com.power.doc.utils;
+
+import com.power.common.util.CollectionUtil;
+
+import java.util.List;
+import java.util.Objects;
+
+/**
+ * @author yu 2019/12/25.
+ */
+public class JavaClassValidateUtil {
+
+ /**
+ * Check if it is the basic data array type of json data
+ *
+ * @param type0 java class name
+ * @return boolean
+ */
+ public static boolean isPrimitiveArray(String type0) {
+ String type = type0.contains("java.lang") ? type0.substring(type0.lastIndexOf(".") + 1, type0.length()) : type0;
+ type = type.toLowerCase();
+ switch (type) {
+ case "integer[]":
+ case "void":
+ case "int[]":
+ case "long[]":
+ case "double[]":
+ case "float[]":
+ case "short[]":
+ case "bigdecimal[]":
+ case "char[]":
+ case "string[]":
+ case "boolean[]":
+ case "byte[]":
+ return true;
+ default:
+ return false;
+ }
+ }
+
+ /**
+ * Check if it is the basic data type of json data
+ *
+ * @param type0 java class name
+ * @return boolean
+ */
+ public static boolean isPrimitive(String type0) {
+ if (Objects.isNull(type0)) {
+ return true;
+ }
+ String type = type0.contains("java.lang") ? type0.substring(type0.lastIndexOf(".") + 1, type0.length()) : type0;
+ type = type.toLowerCase();
+ switch (type) {
+ case "integer":
+ case "void":
+ case "int":
+ case "long":
+ case "double":
+ case "float":
+ case "short":
+ case "bigdecimal":
+ case "char":
+ case "string":
+ case "boolean":
+ case "byte":
+ case "java.sql.timestamp":
+ case "java.util.date":
+ case "java.time.localdatetime":
+ case "java.time.localtime":
+ case "localdatetime":
+ case "localdate":
+ case "java.time.localdate":
+ case "java.math.bigdecimal":
+ case "java.math.biginteger":
+ case "java.io.serializable":
+ return true;
+ default:
+ return false;
+ }
+ }
+
+ /**
+ * validate java collection
+ *
+ * @param type java typeName
+ * @return boolean
+ */
+ public static boolean isCollection(String type) {
+ switch (type) {
+ case "java.util.List":
+ case "java.util.LinkedList":
+ case "java.util.ArrayList":
+ case "java.util.Set":
+ case "java.util.TreeSet":
+ case "java.util.HashSet":
+ case "java.util.SortedSet":
+ case "java.util.Collection":
+ case "java.util.ArrayDeque":
+ case "java.util.PriorityQueue":
+ return true;
+ default:
+ return false;
+ }
+ }
+
+ /**
+ * Check if it is an map
+ *
+ * @param type java type
+ * @return boolean
+ */
+ public static boolean isMap(String type) {
+ switch (type) {
+ case "java.util.Map":
+ case "java.util.SortedMap":
+ case "java.util.TreeMap":
+ case "java.util.LinkedHashMap":
+ case "java.util.HashMap":
+ case "java.util.concurrent.ConcurrentHashMap":
+ case "java.util.concurrent.ConcurrentMap":
+ case "java.util.Properties":
+ case "java.util.Hashtable":
+ return true;
+ default:
+ return false;
+ }
+ }
+
+ /**
+ * check array
+ *
+ * @param type type name
+ * @return boolean
+ */
+ public static boolean isArray(String type) {
+ return type.contains("[]");
+ }
+
+ /**
+ * check JSR303
+ *
+ * @param annotationSimpleName annotation name
+ * @return boolean
+ */
+ public static boolean isJSR303Required(String annotationSimpleName) {
+ switch (annotationSimpleName) {
+ case "NotNull":
+ case "NotEmpty":
+ case "NotBlank":
+ case "Required":
+ return true;
+ default:
+ return false;
+ }
+ }
+
+
+ /**
+ * custom tag
+ *
+ * @param tagName custom field tag
+ * @return boolean
+ */
+ public static boolean isRequiredTag(String tagName) {
+ switch (tagName) {
+ case "required":
+ return true;
+ default:
+ return false;
+ }
+ }
+
+ /**
+ * ignore tag request field
+ *
+ * @param tagName custom field tag
+ * @return boolean
+ */
+ public static boolean isIgnoreTag(String tagName) {
+ switch (tagName) {
+ case "ignore":
+ return true;
+ default:
+ return false;
+ }
+ }
+
+ /**
+ * ignore param of spring mvc
+ *
+ * @param paramType param type name
+ * @param ignoreParams ignore param list
+ * @return boolean
+ */
+ public static boolean isMvcIgnoreParams(String paramType, List ignoreParams) {
+ if (CollectionUtil.isNotEmpty(ignoreParams) && ignoreParams.contains(paramType)) {
+ return true;
+ }
+ switch (paramType) {
+ case "org.springframework.ui.Model":
+ case "org.springframework.ui.ModelMap":
+ case "org.springframework.web.servlet.ModelAndView":
+ case "org.springframework.validation.BindingResult":
+ case "javax.servlet.http.HttpServletRequest":
+ case "org.springframework.web.context.request.WebRequest":
+ case "javax.servlet.http.HttpSession":
+ case "javax.servlet.http.HttpServletResponse":
+ case "org.springframework.web.reactive.function.server.ServerRequest":
+ case "org.springframework.web.multipart.MultipartHttpServletRequest":
+ return true;
+ default:
+ return false;
+ }
+ }
+
+ /**
+ * ignore field type name
+ *
+ * @param typeName field type name
+ * @return String
+ */
+ public static boolean isIgnoreFieldTypes(String typeName) {
+ switch (typeName) {
+ case "org.slf4j.Logger":
+ case "org.apache.ibatis.logging.Log":
+ return true;
+ default:
+ return false;
+ }
+ }
+}
diff --git a/src/main/resources/template/yapiJson.btl b/src/main/resources/template/yapiJson.btl
new file mode 100644
index 0000000..5c1cddf
--- /dev/null
+++ b/src/main/resources/template/yapiJson.btl
@@ -0,0 +1,5 @@
+{
+ "$schema": "http://json-schema.org/draft-04/schema#",
+ ${respList}
+}
+