@@ -198,15 +198,8 @@ Schema calculateSchema(Components components, ParameterInfo parameterInfo, Reque
198
198
Class type = methodParameter .getParameterType ();
199
199
200
200
if (parameterInfo .getParameterModel () == null || parameterInfo .getParameterModel ().getSchema () == null ) {
201
- if (isFile (type )) {
202
- schemaN = getFileSchema (requestBodyInfo );
203
- schemaN .addProperties (paramName , new FileSchema ());
204
- return schemaN ;
205
- }
206
- else if (methodParameter .getGenericParameterType () instanceof ParameterizedType ) {
201
+ if (methodParameter .getGenericParameterType () instanceof ParameterizedType ) {
207
202
ParameterizedType parameterizedType = (ParameterizedType ) methodParameter .getGenericParameterType ();
208
- if (isFile (parameterizedType ))
209
- return extractFileSchema (paramName , requestBodyInfo );
210
203
schemaN = SpringDocAnnotationsUtils .extractSchema (components , methodParameter .getGenericParameterType (), jsonView , methodParameter .getParameterAnnotations ());
211
204
}
212
205
else
@@ -220,39 +213,27 @@ else if (methodParameter.getGenericParameterType() instanceof ParameterizedType)
220
213
requestBodyInfo .getMergedSchema ().addProperties (paramName , schemaN );
221
214
schemaN = requestBodyInfo .getMergedSchema ();
222
215
}
216
+ else if (schemaN instanceof FileSchema ) {
217
+ schemaN = new ObjectSchema ().addProperties (paramName , schemaN );
218
+ requestBodyInfo .setMergedSchema (schemaN );
219
+ }
220
+ else if (schemaN instanceof ArraySchema && ((ArraySchema ) schemaN ).getItems () instanceof FileSchema ) {
221
+ schemaN = new ObjectSchema ().addProperties (paramName , schemaN );
222
+ requestBodyInfo .setMergedSchema (schemaN );
223
+ }
223
224
else
224
225
requestBodyInfo .addProperties (paramName , schemaN );
225
226
}
226
227
227
228
return schemaN ;
228
229
}
229
230
230
- public boolean isFile (MethodParameter methodParameter ) {
231
- if (methodParameter .getGenericParameterType () instanceof ParameterizedType ) {
232
- Type type = methodParameter .getGenericParameterType ();
233
- ParameterizedType parameterizedType = (ParameterizedType ) type ;
234
- return isFile (parameterizedType );
235
- }
236
- else {
237
- Class type = methodParameter .getParameterType ();
238
- return isFile (type );
239
- }
240
- }
241
-
242
231
public boolean isAnnotationToIgnore (MethodParameter parameter ) {
243
232
return ANNOTATIOSN_TO_IGNORE .stream ().anyMatch (
244
233
annotation -> parameter .getParameterAnnotation (annotation ) != null
245
234
|| AnnotationUtils .findAnnotation (parameter .getParameterType (), annotation ) != null );
246
235
}
247
236
248
- private Schema extractFileSchema (String paramName , RequestBodyInfo requestBodyInfo ) {
249
- Schema schemaN = getFileSchema (requestBodyInfo );
250
- ArraySchema schemaFile = new ArraySchema ();
251
- schemaFile .items (new FileSchema ());
252
- schemaN .addProperties (paramName , new ArraySchema ().items (new FileSchema ()));
253
- return schemaN ;
254
- }
255
-
256
237
private Schema getFileSchema (RequestBodyInfo requestBodyInfo ) {
257
238
Schema schemaN ;
258
239
if (requestBodyInfo .getMergedSchema () != null )
@@ -264,19 +245,6 @@ private Schema getFileSchema(RequestBodyInfo requestBodyInfo) {
264
245
return schemaN ;
265
246
}
266
247
267
- private boolean isFile (ParameterizedType parameterizedType ) {
268
- Type type = parameterizedType .getActualTypeArguments ()[0 ];
269
- Class fileClass = ResolvableType .forType (type ).getRawClass ();
270
- if (fileClass !=null && isFile (fileClass ))
271
- return true ;
272
- else if (type instanceof WildcardType ) {
273
- WildcardType wildcardType = (WildcardType ) type ;
274
- Type [] upperBounds = wildcardType .getUpperBounds ();
275
- return MultipartFile .class .getName ().equals (upperBounds [0 ].getTypeName ());
276
- }
277
- return false ;
278
- }
279
-
280
248
private void setExamples (io .swagger .v3 .oas .annotations .Parameter parameterDoc , Parameter parameter ) {
281
249
Map <String , Example > exampleMap = new HashMap <>();
282
250
if (parameterDoc .examples ().length == 1 && StringUtils .isBlank (parameterDoc .examples ()[0 ].name ())) {
@@ -328,7 +296,31 @@ private boolean isExplodable(io.swagger.v3.oas.annotations.Parameter p) {
328
296
return explode ;
329
297
}
330
298
331
- private boolean isFile (Class type ) {
299
+ public boolean isFile (MethodParameter methodParameter ) {
300
+ if (methodParameter .getGenericParameterType () instanceof ParameterizedType ) {
301
+ ParameterizedType parameterizedType = (ParameterizedType ) methodParameter .getGenericParameterType ();
302
+ return isFile (parameterizedType );
303
+ }
304
+ else {
305
+ Class type = methodParameter .getParameterType ();
306
+ return isFile (type );
307
+ }
308
+ }
309
+
310
+ private boolean isFile (ParameterizedType parameterizedType ) {
311
+ Type type = parameterizedType .getActualTypeArguments ()[0 ];
312
+ Class fileClass = ResolvableType .forType (type ).getRawClass ();
313
+ if (fileClass != null && isFile (fileClass ))
314
+ return true ;
315
+ else if (type instanceof WildcardType ) {
316
+ WildcardType wildcardType = (WildcardType ) type ;
317
+ Type [] upperBounds = wildcardType .getUpperBounds ();
318
+ return MultipartFile .class .getName ().equals (upperBounds [0 ].getTypeName ());
319
+ }
320
+ return false ;
321
+ }
322
+
323
+ public static boolean isFile (Class type ) {
332
324
return FILE_TYPES .stream ().anyMatch (clazz -> clazz .isAssignableFrom (type ));
333
325
}
334
326
}
0 commit comments