4444import io .swagger .v3 .oas .models .media .ComposedSchema ;
4545import io .swagger .v3 .oas .models .media .ObjectSchema ;
4646import io .swagger .v3 .oas .models .media .Schema ;
47+ import org .apache .commons .lang3 .ArrayUtils ;
4748import org .apache .commons .lang3 .reflect .FieldUtils ;
4849import org .springdoc .core .providers .ObjectMapperProvider ;
4950
@@ -68,7 +69,7 @@ public class PolymorphicModelConverter implements ModelConverter {
6869 * The constant PARENT_TYPES_TO_IGNORE.
6970 */
7071 private static final List <String > TYPES_TO_SKIP = Collections .synchronizedList (new ArrayList <>());
71-
72+
7273 static {
7374 PARENT_TYPES_TO_IGNORE .add ("JsonSchema" );
7475 PARENT_TYPES_TO_IGNORE .add ("Pageable" );
@@ -121,7 +122,10 @@ public Schema resolve(AnnotatedType type, ModelConverterContext context, Iterato
121122 PARENT_TYPES_TO_IGNORE .add (javaType .getRawClass ().getSimpleName ());
122123 }
123124 else if (field .isAnnotationPresent (io .swagger .v3 .oas .annotations .media .Schema .class )) {
124- TYPES_TO_SKIP .add (field .getType ().getSimpleName ());
125+ io .swagger .v3 .oas .annotations .media .Schema declaredSchema = field .getDeclaredAnnotation (io .swagger .v3 .oas .annotations .media .Schema .class );
126+ if (ArrayUtils .isNotEmpty (declaredSchema .oneOf ()) || ArrayUtils .isNotEmpty (declaredSchema .allOf ())) {
127+ TYPES_TO_SKIP .add (field .getType ().getSimpleName ());
128+ }
125129 }
126130 }
127131 if (chain .hasNext ()) {
@@ -133,7 +137,7 @@ else if (field.isAnnotationPresent(io.swagger.v3.oas.annotations.media.Schema.cl
133137 if (resolvedSchema == null || resolvedSchema .get$ref () == null ) {
134138 return resolvedSchema ;
135139 }
136- if (resolvedSchema .get$ref ().contains (Components .COMPONENTS_SCHEMAS_REF )) {
140+ if (resolvedSchema .get$ref ().contains (Components .COMPONENTS_SCHEMAS_REF )) {
137141 String schemaName = resolvedSchema .get$ref ().substring (Components .COMPONENTS_SCHEMAS_REF .length ());
138142 Schema existingSchema = context .getDefinedModels ().get (schemaName );
139143 if (existingSchema != null && (existingSchema .getOneOf () != null || existingSchema .getAllOf () != null )) {
@@ -162,7 +166,7 @@ private Schema composePolymorphicSchema(AnnotatedType type, Schema schema, Colle
162166 if (isConcreteClass (type )) result .addOneOfItem (schema );
163167 JavaType javaType = springDocObjectMapper .jsonMapper ().constructType (type .getType ());
164168 Class <?> clazz = javaType .getRawClass ();
165- if (TYPES_TO_SKIP .stream ().noneMatch (typeToSkip -> typeToSkip .equals (clazz .getSimpleName ())))
169+ if (TYPES_TO_SKIP .stream ().noneMatch (typeToSkip -> typeToSkip .equals (clazz .getSimpleName ())))
166170 composedSchemas .forEach (result ::addOneOfItem );
167171 return result ;
168172 }
0 commit comments