44
44
import io .swagger .v3 .oas .models .media .ComposedSchema ;
45
45
import io .swagger .v3 .oas .models .media .ObjectSchema ;
46
46
import io .swagger .v3 .oas .models .media .Schema ;
47
+ import org .apache .commons .lang3 .ArrayUtils ;
47
48
import org .apache .commons .lang3 .reflect .FieldUtils ;
48
49
import org .springdoc .core .providers .ObjectMapperProvider ;
49
50
@@ -68,7 +69,7 @@ public class PolymorphicModelConverter implements ModelConverter {
68
69
* The constant PARENT_TYPES_TO_IGNORE.
69
70
*/
70
71
private static final List <String > TYPES_TO_SKIP = Collections .synchronizedList (new ArrayList <>());
71
-
72
+
72
73
static {
73
74
PARENT_TYPES_TO_IGNORE .add ("JsonSchema" );
74
75
PARENT_TYPES_TO_IGNORE .add ("Pageable" );
@@ -121,7 +122,10 @@ public Schema resolve(AnnotatedType type, ModelConverterContext context, Iterato
121
122
PARENT_TYPES_TO_IGNORE .add (javaType .getRawClass ().getSimpleName ());
122
123
}
123
124
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
+ }
125
129
}
126
130
}
127
131
if (chain .hasNext ()) {
@@ -133,7 +137,7 @@ else if (field.isAnnotationPresent(io.swagger.v3.oas.annotations.media.Schema.cl
133
137
if (resolvedSchema == null || resolvedSchema .get$ref () == null ) {
134
138
return resolvedSchema ;
135
139
}
136
- if (resolvedSchema .get$ref ().contains (Components .COMPONENTS_SCHEMAS_REF )) {
140
+ if (resolvedSchema .get$ref ().contains (Components .COMPONENTS_SCHEMAS_REF )) {
137
141
String schemaName = resolvedSchema .get$ref ().substring (Components .COMPONENTS_SCHEMAS_REF .length ());
138
142
Schema existingSchema = context .getDefinedModels ().get (schemaName );
139
143
if (existingSchema != null && (existingSchema .getOneOf () != null || existingSchema .getAllOf () != null )) {
@@ -162,7 +166,7 @@ private Schema composePolymorphicSchema(AnnotatedType type, Schema schema, Colle
162
166
if (isConcreteClass (type )) result .addOneOfItem (schema );
163
167
JavaType javaType = springDocObjectMapper .jsonMapper ().constructType (type .getType ());
164
168
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 ())))
166
170
composedSchemas .forEach (result ::addOneOfItem );
167
171
return result ;
168
172
}
0 commit comments