Skip to content
This repository was archived by the owner on Dec 4, 2025. It is now read-only.

Commit 1593df5

Browse files
committed
fix: Fix the error in document generation when the response field uses @JsonProperty(access = JsonProperty.Access.READ_ONLY)
1 parent 0446bf6 commit 1593df5

2 files changed

Lines changed: 10 additions & 8 deletions

File tree

src/main/java/com/ly/doc/helper/JsonBuildHelper.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -287,8 +287,6 @@ else if (JavaClassValidateUtil.isReactor(typeName)) {
287287

288288
// get tags value from the field
289289
Map<String, String> tagsMap = DocUtil.getFieldTagsValue(field, docField);
290-
// get annotations on the field
291-
List<JavaAnnotation> annotations = docField.getAnnotations();
292290

293291
// field json annotation
294292
FieldJsonAnnotationInfo annotationInfo = getFieldJsonAnnotationInfo(projectBuilder, docField, isResp,
@@ -301,7 +299,7 @@ else if (JavaClassValidateUtil.isReactor(typeName)) {
301299
String fieldJsonFormatValue = annotationInfo.getFieldJsonFormatValue();
302300
// has Annotation @JsonSerialize And using ToStringSerializer
303301
boolean toStringSerializer = Boolean.TRUE.equals(annotationInfo.getToStringSerializer());
304-
if (Objects.nonNull(annotationInfo.getFieldName())) {
302+
if (StringUtil.isNotEmpty(annotationInfo.getFieldName())) {
305303
fieldName = annotationInfo.getFieldName();
306304
}
307305

@@ -545,10 +543,14 @@ public static void buildMapJson(String genericCanonicalName, boolean isResp, int
545543
}
546544
JavaClass mapKeyClass = builder.getJavaProjectBuilder().getClassByName(getKeyValType[0]);
547545
boolean mapKeyIsEnum = mapKeyClass.isEnum();
548-
if ((!JavaTypeConstants.JAVA_STRING_FULLY.equals(getKeyValType[0]) || !mapKeyIsEnum
549-
|| mapKeyClass.getEnumConstants().isEmpty()) && builder.getApiConfig().isStrict()) {
550-
throw new RuntimeException(
551-
"Map's key can only use String or Enum for json,but you use " + getKeyValType[0]);
546+
String keyType = getKeyValType[0];
547+
548+
if (builder.getApiConfig().isStrict()) {
549+
boolean isStringKey = JavaTypeConstants.JAVA_STRING_FULLY.equals(keyType);
550+
boolean isValidEnumKey = mapKeyIsEnum && !mapKeyClass.getEnumConstants().isEmpty();
551+
if (!isStringKey && !isValidEnumKey) {
552+
throw new RuntimeException("Map's key can only use String or Enum for JSON, but you used: " + keyType);
553+
}
552554
}
553555
String gicName = getKeyValType[1];
554556
// when map key is enum

src/main/java/com/ly/doc/helper/ParamsBuildHelper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ private static List<ApiParam> processFields(String className, String pre, int le
290290
String fieldJsonFormatValue = annotationInfo.getFieldJsonFormatValue();
291291
// has Annotation @JsonSerialize And using ToStringSerializer
292292
boolean toStringSerializer = Boolean.TRUE.equals(annotationInfo.getToStringSerializer());
293-
if (Objects.nonNull(annotationInfo.getFieldName())) {
293+
if (StringUtil.isNotEmpty(annotationInfo.getFieldName())) {
294294
fieldName = annotationInfo.getFieldName();
295295
}
296296
if (Objects.nonNull(annotationInfo.getStrRequired())) {

0 commit comments

Comments
 (0)