|
29 | 29 | import com.ly.doc.constants.ParamTypeConstants; |
30 | 30 | import com.ly.doc.extension.json.PropertyNameHelper; |
31 | 31 | import com.ly.doc.extension.json.PropertyNamingStrategies; |
32 | | -import com.ly.doc.model.*; |
33 | | -import com.ly.doc.utils.*; |
| 32 | +import com.ly.doc.model.ApiConfig; |
| 33 | +import com.ly.doc.model.ApiDataDictionary; |
| 34 | +import com.ly.doc.model.ApiParam; |
| 35 | +import com.ly.doc.model.CustomField; |
| 36 | +import com.ly.doc.model.CustomFieldInfo; |
| 37 | +import com.ly.doc.model.DocJavaField; |
| 38 | +import com.ly.doc.model.FieldJsonAnnotationInfo; |
| 39 | +import com.ly.doc.model.torna.EnumInfoAndValues; |
| 40 | +import com.ly.doc.utils.DocClassUtil; |
| 41 | +import com.ly.doc.utils.DocUtil; |
| 42 | +import com.ly.doc.utils.JavaClassUtil; |
| 43 | +import com.ly.doc.utils.JavaClassValidateUtil; |
| 44 | +import com.ly.doc.utils.JavaFieldUtil; |
| 45 | +import com.ly.doc.utils.ParamUtil; |
34 | 46 | import com.power.common.model.EnumDictionary; |
35 | 47 | import com.power.common.util.StringUtil; |
36 | 48 | import com.thoughtworks.qdox.model.JavaAnnotation; |
37 | 49 | import com.thoughtworks.qdox.model.JavaClass; |
38 | 50 | import com.thoughtworks.qdox.model.JavaField; |
39 | 51 | import org.apache.commons.lang3.StringUtils; |
40 | 52 |
|
41 | | -import java.util.*; |
| 53 | +import java.util.ArrayList; |
| 54 | +import java.util.Collections; |
| 55 | +import java.util.HashMap; |
| 56 | +import java.util.LinkedHashMap; |
| 57 | +import java.util.List; |
| 58 | +import java.util.Map; |
| 59 | +import java.util.Objects; |
| 60 | +import java.util.Optional; |
| 61 | +import java.util.Set; |
42 | 62 | import java.util.concurrent.atomic.AtomicInteger; |
43 | 63 | import java.util.stream.Collectors; |
44 | 64 |
|
@@ -245,8 +265,8 @@ private static List<ApiParam> processFields(String className, String pre, int le |
245 | 265 | // handle extension |
246 | 266 | Map<String, String> extensions = DocUtil.getCommentsByTag(field.getTagsByName(DocTags.EXTENSION), |
247 | 267 | DocTags.EXTENSION); |
248 | | - Map<String, Object> extensionParams = new HashMap<>(); |
249 | | - if (extensions != null && !extensions.isEmpty()) { |
| 268 | + Map<String, Object> extensionParams = new HashMap<>(extensions.size()); |
| 269 | + if (!extensions.isEmpty()) { |
250 | 270 | extensions.forEach((k, v) -> extensionParams.put(k, DocUtil.detectTagValue(v))); |
251 | 271 | } |
252 | 272 |
|
@@ -367,8 +387,8 @@ private static List<ApiParam> processFields(String className, String pre, int le |
367 | 387 | // handle param |
368 | 388 | commonHandleParam(paramList, param, isRequired, comment.toString(), since, strRequired); |
369 | 389 |
|
370 | | - JavaClass enumClass = ParamUtil.handleSeeEnum(param, field, projectBuilder, jsonRequest, tagsMap, |
371 | | - fieldJsonFormatValue); |
| 390 | + JavaClass enumClass = ParamUtil.handleSeeEnum(param, field, projectBuilder, isResp || jsonRequest, |
| 391 | + tagsMap, fieldJsonFormatValue); |
372 | 392 | if (Objects.nonNull(enumClass)) { |
373 | 393 | String enumClassComment = DocGlobalConstants.EMPTY; |
374 | 394 | if (StringUtil.isNotEmpty(enumClass.getComment())) { |
@@ -431,7 +451,8 @@ private static List<ApiParam> processFields(String className, String pre, int le |
431 | 451 | JavaClass javaClass = field.getType(); |
432 | 452 | if (javaClass.isEnum()) { |
433 | 453 | comment.append(handleEnumComment(javaClass, projectBuilder)); |
434 | | - ParamUtil.handleSeeEnum(param, field, projectBuilder, jsonRequest, tagsMap, fieldJsonFormatValue); |
| 454 | + ParamUtil.handleSeeEnum(param, field, projectBuilder, isResp || jsonRequest, tagsMap, |
| 455 | + fieldJsonFormatValue); |
435 | 456 | // hand Param |
436 | 457 | commonHandleParam(paramList, param, isRequired, comment + appendComment, since, strRequired); |
437 | 458 | } |
@@ -484,10 +505,12 @@ else if (JavaClassValidateUtil.isCollection(subTypeName) |
484 | 505 | if (!simpleName.equals(gName)) { |
485 | 506 | JavaClass arraySubClass = projectBuilder.getJavaProjectBuilder().getClassByName(gName); |
486 | 507 | if (arraySubClass.isEnum()) { |
487 | | - Object value = JavaClassUtil.getEnumValue(arraySubClass, projectBuilder, Boolean.FALSE); |
488 | | - param.setValue("[\"" + value + "\"]") |
489 | | - .setEnumInfo(JavaClassUtil.getEnumInfo(arraySubClass, projectBuilder)) |
490 | | - .setEnumValues(JavaClassUtil.getEnumValues(arraySubClass)); |
| 508 | + EnumInfoAndValues enumInfoAndValue = JavaClassUtil.getEnumInfoAndValue(arraySubClass, |
| 509 | + projectBuilder, Boolean.FALSE); |
| 510 | + if (Objects.nonNull(enumInfoAndValue)) { |
| 511 | + param.setValue("[\"" + enumInfoAndValue.getValue() + "\"]") |
| 512 | + .setEnumInfoAndValues(enumInfoAndValue); |
| 513 | + } |
491 | 514 | } |
492 | 515 | else if (gName.length() == 1) { |
493 | 516 | // handle generic |
@@ -782,6 +805,15 @@ private static void commonHandleParam(List<ApiParam> paramList, ApiParam param, |
782 | 805 | paramList.add(param); |
783 | 806 | } |
784 | 807 |
|
| 808 | + /** |
| 809 | + * Handles the generation of comments for enum types in a Java class. If the class is |
| 810 | + * an enum, it generates the corresponding enum comment based on the project |
| 811 | + * configuration; otherwise, it returns an empty comment string. |
| 812 | + * @param javaClass The JavaClass object containing class information. |
| 813 | + * @param projectBuilder The ProjectDocConfigBuilder object containing project |
| 814 | + * configuration information. |
| 815 | + * @return The generated enum comment string. |
| 816 | + */ |
785 | 817 | public static String handleEnumComment(JavaClass javaClass, ProjectDocConfigBuilder projectBuilder) { |
786 | 818 | String comment = ""; |
787 | 819 | if (!javaClass.isEnum()) { |
|
0 commit comments