|
30 | 30 | import com.ly.doc.constants.DocValidatorAnnotationEnum; |
31 | 31 | import com.ly.doc.constants.JSRAnnotationConstants; |
32 | 32 | import com.ly.doc.constants.JavaTypeConstants; |
| 33 | +import com.ly.doc.constants.ParamTypeConstants; |
33 | 34 | import com.ly.doc.model.ApiConfig; |
34 | 35 | import com.ly.doc.model.ApiDataDictionary; |
35 | 36 | import com.ly.doc.model.DocJavaField; |
@@ -404,7 +405,7 @@ public static Object getEnumValue(JavaClass javaClass, ProjectDocConfigBuilder b |
404 | 405 | } |
405 | 406 |
|
406 | 407 | // Default handling for enum values |
407 | | - return processDefaultEnumFields(javaClass.getEnumConstants(), formDataEnum); |
| 408 | + return processDefaultEnumFields(javaClass.getEnumConstants(), formDataEnum, enumConstant); |
408 | 409 | } |
409 | 410 |
|
410 | 411 | /** |
@@ -475,12 +476,17 @@ private static Optional<JavaField> findFieldWithJsonValue(JavaClass javaClass) { |
475 | 476 | * Handles the default logic for processing enum fields. |
476 | 477 | * @param javaFields The list of JavaField objects representing enum fields |
477 | 478 | * @param formDataEnum A boolean indicating if the enum is a form data enum |
| 479 | + * @param enumConstant The JavaField object representing the enum constant |
478 | 480 | * @return The value based on the enum field processing logic |
479 | 481 | */ |
480 | | - private static Object processDefaultEnumFields(List<JavaField> javaFields, boolean formDataEnum) { |
| 482 | + private static Object processDefaultEnumFields(List<JavaField> javaFields, boolean formDataEnum, |
| 483 | + JavaField enumConstant) { |
481 | 484 | Object value = null; |
482 | 485 | int index = 0; |
483 | 486 | for (JavaField javaField : javaFields) { |
| 487 | + if (!javaField.equals(enumConstant)) { |
| 488 | + continue; |
| 489 | + } |
484 | 490 | String simpleName = javaField.getType().getSimpleName(); |
485 | 491 | StringBuilder valueBuilder = new StringBuilder(); |
486 | 492 | valueBuilder.append("\"").append(javaField.getName()).append("\""); |
@@ -638,15 +644,19 @@ public static EnumInfo getEnumInfo(JavaClass javaClass, ProjectDocConfigBuilder |
638 | 644 | String name = cons.getName(); |
639 | 645 | String enumComment = cons.getComment(); |
640 | 646 | item.setName(name); |
641 | | - if (formDataEnum) { |
642 | | - item.setValue(name); |
643 | | - item.setType("string"); |
644 | | - } |
645 | | - else { |
| 647 | + |
| 648 | + item.setValue(StringUtil.removeDoubleQuotes(name)); |
| 649 | + item.setType("string"); |
| 650 | + if (!formDataEnum) { |
646 | 651 | Object enumValue = getEnumValue(javaClass, builder, false, cons); |
647 | | - item.setValue(Objects.isNull(enumValue) ? null : String.valueOf(enumValue)); |
648 | | - item.setType(Objects.isNull(enumValue) ? null |
649 | | - : DocClassUtil.processTypeNameForParams(enumValue.getClass().getCanonicalName())); |
| 652 | + String stringValue = StringUtil.removeQuotes(String.valueOf(enumValue)); |
| 653 | + if (!StringUtils.equals(name, stringValue)) { |
| 654 | + item.setValueObject(enumValue); |
| 655 | + item.setValue(stringValue); |
| 656 | + if (Objects.nonNull(enumValue)) { |
| 657 | + item.setType(DocClassUtil.processTypeNameForParams(enumValue.getClass().getCanonicalName())); |
| 658 | + } |
| 659 | + } |
650 | 660 | } |
651 | 661 | item.setDescription(enumComment); |
652 | 662 | return item; |
@@ -1465,12 +1475,22 @@ public static EnumInfoAndValues getEnumInfoAndValue(JavaClass javaClass, Project |
1465 | 1475 | // Step 2: Get the enum values based on whether it's formDataEnum or not |
1466 | 1476 | List<String> enumValues = enumInfo.getItems().stream().map(Item::getValue).collect(Collectors.toList()); |
1467 | 1477 |
|
| 1478 | + Item item = enumInfo.getItems().get(0); |
1468 | 1479 | // Step 3: Create the EnumInfoAndValues result |
1469 | | - return EnumInfoAndValues.builder() |
1470 | | - .setEnumInfo(enumInfo) |
| 1480 | + Object valueObject = item.getValueObject(); |
| 1481 | + EnumInfoAndValues result = EnumInfoAndValues.builder() |
1471 | 1482 | .setEnumValues(enumValues) |
1472 | 1483 | // Using the same method to get default value |
1473 | | - .setValue(getEnumValue(javaClass, builder, formDataEnum)); |
| 1484 | + .setValue(Objects.isNull(valueObject) ? item.getValue() : valueObject); |
| 1485 | + |
| 1486 | + result.setType(ParamTypeConstants.PARAM_TYPE_ENUM); |
| 1487 | + if (!formDataEnum) { |
| 1488 | + if (Objects.nonNull(valueObject)) { |
| 1489 | + result.setType(DocClassUtil.processTypeNameForParams(valueObject.getClass().getCanonicalName())); |
| 1490 | + enumInfo.setName(enumInfo.getName() + " To " + result.getType()); |
| 1491 | + } |
| 1492 | + } |
| 1493 | + return result.setEnumInfo(enumInfo); |
1474 | 1494 | } |
1475 | 1495 |
|
1476 | 1496 | } |
0 commit comments