Skip to content

Commit

Permalink
Merge pull request #1003 from jasonkung22/fix_map_enum
Browse files Browse the repository at this point in the history
Fix the request parameter is Map<Enum, Value> is not parsed correctly
  • Loading branch information
shalousun authored Dec 19, 2024
2 parents b53345b + fabcd5d commit 1ba1deb
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
6 changes: 6 additions & 0 deletions src/main/java/com/ly/doc/helper/ParamsBuildHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -707,6 +707,12 @@ public static List<ApiParam> buildMapParam(String[] globGicName, String pre, int
.orElse(DocGlobalConstants.DEFAULT_MAP_KEY_DESC))
.setVersion(DocGlobalConstants.DEFAULT_VERSION)
.setPid(null == keyParentId ? pid : keyParentId);

Object enumValueWithJsonValue = JavaClassUtil.getEnumValueWithJsonValue(mapKeyClass, projectBuilder,
enumConstant);
if (jsonRequest && enumValueWithJsonValue != null) {
apiParam.setField(pre + enumValueWithJsonValue);
}
apiParam.setId(apiParam.getPid() + paramList.size() + 1);
if (null == keyParentId) {
keyParentId = apiParam.getPid();
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/ly/doc/template/IRestDocTemplate.java
Original file line number Diff line number Diff line change
Expand Up @@ -1247,7 +1247,7 @@ else if (JavaClassValidateUtil.isMap(fullyQualifiedName)) {

paramList.addAll(ParamsBuildHelper.buildMapParam(gicNameArr, DocGlobalConstants.EMPTY, 0,
String.valueOf(required), Boolean.FALSE, new HashMap<>(16), builder, groupClasses,
docJavaMethod.getJsonViewClasses(), 0, Boolean.FALSE, 1, null));
docJavaMethod.getJsonViewClasses(), 0, jsonRequest, 1, null));

// is map without Gic
if (JavaClassValidateUtil.isMap(typeName)) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/ly/doc/utils/JavaClassUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ public static Object getDefaultEnumValue(JavaClass javaClass, ProjectDocConfigBu
* @return Object The enum value, whose type depends on the specific enum definition
* @throws RuntimeException If the enum constants do not exist
*/
private static Object getEnumValueWithJsonValue(JavaClass javaClass, ProjectDocConfigBuilder builder,
public static Object getEnumValueWithJsonValue(JavaClass javaClass, ProjectDocConfigBuilder builder,
JavaField enumConstant) {
String methodName = findMethodWithJsonValue(javaClass);
if (Objects.nonNull(methodName)) {
Expand Down

0 comments on commit 1ba1deb

Please sign in to comment.