Skip to content

Commit

Permalink
Merge pull request #1027 from linwumingshi/fix/maxLength-constants
Browse files Browse the repository at this point in the history
fix: 🐛 resolve incorrect parsing of constants in `maxLength`
  • Loading branch information
shalousun authored Feb 17, 2025
2 parents 3cf8a57 + f82fbab commit aa53b1b
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/main/java/com/ly/doc/helper/ParamsBuildHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ private static List<ApiParam> processFields(String className, String pre, int le
continue;
}

String maxLength = JavaFieldUtil.getParamMaxLength(field.getAnnotations());
String maxLength = JavaFieldUtil.getParamMaxLength(classLoader, field.getAnnotations());
StringBuilder comment = new StringBuilder();
comment.append(docField.getComment());

Expand Down
32 changes: 26 additions & 6 deletions src/main/java/com/ly/doc/template/IJavadocDocTemplate.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2018-2024 smart-doc
* Copyright (C) 2018-2025 smart-doc
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
Expand All @@ -21,17 +21,37 @@
package com.ly.doc.template;

import com.ly.doc.builder.ProjectDocConfigBuilder;
import com.ly.doc.constants.*;
import com.ly.doc.constants.DocAnnotationConstants;
import com.ly.doc.constants.DocGlobalConstants;
import com.ly.doc.constants.DocTags;
import com.ly.doc.constants.JavaTypeConstants;
import com.ly.doc.constants.ParamTypeConstants;
import com.ly.doc.helper.ParamsBuildHelper;
import com.ly.doc.model.ApiConfig;
import com.ly.doc.model.ApiParam;
import com.ly.doc.model.DocJavaMethod;
import com.ly.doc.model.JavadocJavaMethod;
import com.ly.doc.utils.*;
import com.ly.doc.utils.ApiParamTreeUtil;
import com.ly.doc.utils.DocClassUtil;
import com.ly.doc.utils.DocUtil;
import com.ly.doc.utils.JavaClassUtil;
import com.ly.doc.utils.JavaClassValidateUtil;
import com.ly.doc.utils.JavaFieldUtil;
import com.power.common.util.StringUtil;
import com.thoughtworks.qdox.model.*;
import com.thoughtworks.qdox.model.JavaAnnotation;
import com.thoughtworks.qdox.model.JavaClass;
import com.thoughtworks.qdox.model.JavaMethod;
import com.thoughtworks.qdox.model.JavaParameter;
import com.thoughtworks.qdox.model.JavaType;

import java.util.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Function;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -267,7 +287,7 @@ else if (JavaClassValidateUtil.isPrimitive(fullTypeName)) {
.setType(JavaClassUtil.getClassSimpleName(typeName))
.setDesc(comment.toString())
.setRequired(required)
.setMaxLength(JavaFieldUtil.getParamMaxLength(parameter.getAnnotations()))
.setMaxLength(JavaFieldUtil.getParamMaxLength(classLoader, parameter.getAnnotations()))
.setValue(mockValue)
.setVersion(DocGlobalConstants.DEFAULT_VERSION);
paramList.add(param);
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/com/ly/doc/utils/JavaFieldUtil.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* smart-doc
*
* Copyright (C) 2018-2024 smart-doc
* Copyright (C) 2018-2025 smart-doc
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
Expand Down Expand Up @@ -118,10 +118,11 @@ public static String createMockValue(Map<String, String> paramsComments, String

/**
* get param max length
* @param classLoader classLoader
* @param annotations annotation
* @return max length
*/
public static String getParamMaxLength(List<JavaAnnotation> annotations) {
public static String getParamMaxLength(ClassLoader classLoader, List<JavaAnnotation> annotations) {
String maxLength = "";
for (JavaAnnotation annotation : annotations) {
String simpleAnnotationName = annotation.getType().getValue();
Expand All @@ -133,7 +134,7 @@ public static String getParamMaxLength(List<JavaAnnotation> annotations) {
annotationValue = annotation.getProperty(JSRAnnotationPropConstants.MAX_PROP);
}
if (Objects.nonNull(annotationValue)) {
maxLength = annotationValue.toString();
maxLength = DocUtil.resolveAnnotationValue(classLoader, annotationValue);
}
}
return maxLength;
Expand Down

0 comments on commit aa53b1b

Please sign in to comment.