@@ -1082,7 +1082,7 @@ private Annotation[] addGenericTypeArgumentAnnotationsForOptionalField(BeanPrope
1082
1082
.map (field -> !(field .getType ().equals (Optional .class )))
1083
1083
.orElse (false );
1084
1084
1085
- if (isNotOptionalType ) {
1085
+ if (isNotOptionalType || isRecordType ( propDef ) ) {
1086
1086
return annotations ;
1087
1087
}
1088
1088
@@ -1091,21 +1091,51 @@ private Annotation[] addGenericTypeArgumentAnnotationsForOptionalField(BeanPrope
1091
1091
}
1092
1092
1093
1093
private Stream <Annotation > extractGenericTypeArgumentAnnotations (BeanPropertyDefinition propDef ) {
1094
+ if (isRecordType (propDef )){
1095
+ return getRecordComponentAnnotations (propDef );
1096
+ }
1094
1097
return Optional .ofNullable (propDef )
1095
1098
.map (BeanPropertyDefinition ::getField )
1096
1099
.map (AnnotatedField ::getAnnotated )
1097
1100
.map (this ::getGenericTypeArgumentAnnotations )
1098
1101
.orElseGet (Stream ::of );
1099
1102
}
1100
1103
1104
+ private Stream <Annotation > getRecordComponentAnnotations (BeanPropertyDefinition propDef ) {
1105
+ try {
1106
+ Method accessor = propDef .getPrimaryMember ().getDeclaringClass ().getDeclaredMethod (propDef .getName ());
1107
+ return getGenericTypeArgumentAnnotations (accessor .getAnnotatedReturnType ());
1108
+ } catch (NoSuchMethodException e ) {
1109
+ LOGGER .error ("Accessor for record component not found" );
1110
+ return Stream .empty ();
1111
+ }
1112
+ }
1113
+
1114
+ private Boolean isRecordType (BeanPropertyDefinition propDef ){
1115
+ try {
1116
+ Class <?> clazz = propDef .getPrimaryMember ().getDeclaringClass ();
1117
+ Method isRecordMethod = Class .class .getMethod ("isRecord" );
1118
+ return (Boolean ) isRecordMethod .invoke (clazz );
1119
+ } catch (NoSuchMethodException e ) {
1120
+ return false ;
1121
+ } catch (Exception e ) {
1122
+ e .printStackTrace ();
1123
+ return false ;
1124
+ }
1125
+ }
1126
+
1101
1127
private Stream <Annotation > getGenericTypeArgumentAnnotations (Field field ) {
1102
- return Optional .of (field .getAnnotatedType ())
1103
- .filter (annotatedType -> annotatedType instanceof AnnotatedParameterizedType )
1104
- .map (annotatedType -> (AnnotatedParameterizedType ) annotatedType )
1105
- .map (AnnotatedParameterizedType ::getAnnotatedActualTypeArguments )
1106
- .map (types -> Stream .of (types )
1107
- .flatMap (type -> Stream .of (type .getAnnotations ())))
1108
- .orElseGet (Stream ::of );
1128
+ return getGenericTypeArgumentAnnotations (field .getAnnotatedType ());
1129
+ }
1130
+
1131
+ private Stream <Annotation > getGenericTypeArgumentAnnotations (java .lang .reflect .AnnotatedType annotatedType ) {
1132
+ return Optional .of (annotatedType )
1133
+ .filter (type -> type instanceof AnnotatedParameterizedType )
1134
+ .map (type -> (AnnotatedParameterizedType ) type )
1135
+ .map (AnnotatedParameterizedType ::getAnnotatedActualTypeArguments )
1136
+ .map (types -> Stream .of (types )
1137
+ .flatMap (type -> Stream .of (type .getAnnotations ())))
1138
+ .orElseGet (Stream ::of );
1109
1139
}
1110
1140
1111
1141
private boolean shouldResolveEnumAsRef (io .swagger .v3 .oas .annotations .media .Schema resolvedSchemaAnnotation ) {
0 commit comments