2828import java .beans .Introspector ;
2929import java .beans .PropertyDescriptor ;
3030import java .lang .reflect .Field ;
31- import java .util .*;
31+ import java .util .ArrayList ;
32+ import java .util .Arrays ;
33+ import java .util .Iterator ;
34+ import java .util .List ;
35+ import java .util .Map ;
36+ import java .util .Optional ;
37+ import java .util .Set ;
3238
3339import com .fasterxml .jackson .databind .JavaType ;
40+ import com .fasterxml .jackson .databind .ObjectMapper ;
41+ import com .fasterxml .jackson .databind .introspect .SimpleMixInResolver ;
3442import io .swagger .v3 .core .converter .AnnotatedType ;
3543import io .swagger .v3 .core .converter .ModelConverter ;
3644import io .swagger .v3 .core .converter .ModelConverterContext ;
45+ import io .swagger .v3 .core .converter .ModelConverterContextImpl ;
3746import io .swagger .v3 .core .util .AnnotationsUtils ;
47+ import io .swagger .v3 .oas .annotations .media .SchemaProperty ;
3848import io .swagger .v3 .oas .models .media .Schema ;
3949import org .apache .commons .lang3 .StringUtils ;
4050import org .apache .commons .lang3 .reflect .FieldUtils ;
4858
4959/**
5060 * The type Javadoc property customizer.
61+ *
5162 * @author bnasslahsen
5263 */
5364public record JavadocPropertyCustomizer (JavadocProvider javadocProvider ,
5465 ObjectMapperProvider objectMapperProvider )
5566 implements ModelConverter {
5667
5768 private static final Logger LOGGER = LoggerFactory .getLogger (DelegatingMethodParameter .class );
69+
5870 /**
5971 * Instantiates a new Javadoc property customizer.
6072 *
61- * @param javadocProvider the javadoc provider
73+ * @param javadocProvider the javadoc provider
6274 * @param objectMapperProvider the object mapper provider
6375 */
6476 public JavadocPropertyCustomizer {
@@ -67,9 +79,9 @@ public record JavadocPropertyCustomizer(JavadocProvider javadocProvider,
6779 /**
6880 * Resolve schema.
6981 *
70- * @param type the type
82+ * @param type the type
7183 * @param context the context
72- * @param chain the chain
84+ * @param chain the chain
7385 * @return the schema
7486 */
7587 @ Override
@@ -83,18 +95,30 @@ public Schema resolve(AnnotatedType type, ModelConverterContext context, Iterato
8395 List <PropertyDescriptor > clsProperties = new ArrayList <>();
8496 try {
8597 clsProperties = Arrays .asList (Introspector .getBeanInfo (cls ).getPropertyDescriptors ());
86- } catch (IntrospectionException ignored ) {
98+ }
99+ catch (IntrospectionException ignored ) {
87100 LOGGER .warn (ignored .getMessage ());
88101 }
89102 if (!CollectionUtils .isEmpty (fields ) || !CollectionUtils .isEmpty (clsProperties )) {
90103 if (!type .isSchemaProperty ()) {
91104 Schema existingSchema = context .resolve (type );
92- setJavadocDescription (cls , fields , clsProperties , existingSchema );
105+ setJavadocDescription (cls , fields , clsProperties , existingSchema , false );
93106 }
94107 else if (resolvedSchema != null && resolvedSchema .get$ref () != null && resolvedSchema .get$ref ().contains (AnnotationsUtils .COMPONENTS_REF )) {
95108 String schemaName = resolvedSchema .get$ref ().substring (21 );
96109 Schema existingSchema = context .getDefinedModels ().get (schemaName );
97- setJavadocDescription (cls , fields , clsProperties , existingSchema );
110+ setJavadocDescription (cls , fields , clsProperties , existingSchema , false );
111+ }
112+ else {
113+ try {
114+ Field processedTypesField = FieldUtils .getDeclaredField (ModelConverterContextImpl .class , "processedTypes" , true );
115+ Set <AnnotatedType > processedType = (Set <AnnotatedType >) processedTypesField .get (context );
116+ if (processedType .contains (type ))
117+ setJavadocDescription (cls , fields , clsProperties , resolvedSchema , true );
118+ }
119+ catch (IllegalAccessException e ) {
120+ LOGGER .warn (e .getMessage ());
121+ }
98122 }
99123 }
100124 return resolvedSchema ;
@@ -106,14 +130,15 @@ else if (resolvedSchema != null && resolvedSchema.get$ref() != null && resolvedS
106130 /**
107131 * Sets javadoc description.
108132 *
109- * @param cls the cls
110- * @param fields the fields
111- * @param clsProperties the bean properties of cls
112- * @param existingSchema the existing schema
133+ * @param cls the cls
134+ * @param fields the fields
135+ * @param clsProperties the bean properties of cls
136+ * @param existingSchema the existing schema
137+ * @param isProcessedType the is processed type
113138 */
114- public void setJavadocDescription (Class <?> cls , List <Field > fields , List <PropertyDescriptor > clsProperties , Schema existingSchema ) {
139+ public void setJavadocDescription (Class <?> cls , List <Field > fields , List <PropertyDescriptor > clsProperties , Schema existingSchema , boolean isProcessedType ) {
115140 if (existingSchema != null ) {
116- if (StringUtils .isBlank (existingSchema .getDescription ())) {
141+ if (StringUtils .isBlank (existingSchema .getDescription ()) && ! isProcessedType ) {
117142 String classJavadoc = javadocProvider .getClassJavadoc (cls );
118143 if (StringUtils .isNotBlank (classJavadoc )) {
119144 existingSchema .setDescription (classJavadoc );
0 commit comments