@@ -257,11 +257,7 @@ public void calculateRequestBodyInfo(Components components, MethodAttributes met
257
257
ParameterInfo parameterInfo , RequestBodyInfo requestBodyInfo ) {
258
258
RequestBody requestBody = requestBodyInfo .getRequestBody ();
259
259
MethodParameter methodParameter = parameterInfo .getMethodParameter ();
260
- // Get it from parameter level, if not present
261
- if (requestBody == null ) {
262
- io .swagger .v3 .oas .annotations .parameters .RequestBody requestBodyDoc = methodParameter .getParameterAnnotation (io .swagger .v3 .oas .annotations .parameters .RequestBody .class );
263
- requestBody = this .buildRequestBodyFromDoc (requestBodyDoc , methodAttributes , components ).orElse (null );
264
- }
260
+
265
261
266
262
RequestPart requestPart = methodParameter .getParameterAnnotation (RequestPart .class );
267
263
String paramName = null ;
@@ -273,41 +269,38 @@ public void calculateRequestBodyInfo(Components components, MethodAttributes met
273
269
paramName = StringUtils .defaultIfEmpty (paramName , parameterInfo .getpName ());
274
270
parameterInfo .setpName (paramName );
275
271
276
- requestBody = buildRequestBody (requestBody , components , methodAttributes , parameterInfo ,
272
+ io .swagger .v3 .oas .annotations .parameters .RequestBody requestBodyDoc = methodParameter .getParameterAnnotation (io .swagger .v3 .oas .annotations .parameters .RequestBody .class );
273
+ requestBody = buildRequestBody (requestBodyDoc , components , methodAttributes , parameterInfo ,
277
274
requestBodyInfo );
278
275
requestBodyInfo .setRequestBody (requestBody );
279
276
}
280
277
281
278
/**
282
279
* Build request body.
283
280
*
284
- * @param requestBody the request body
281
+ * @param requestBodyDoc the request body doc
285
282
* @param components the components
286
283
* @param methodAttributes the method attributes
287
284
* @param parameterInfo the parameter info
288
285
* @param requestBodyInfo the request body info
289
286
* @return the request body
290
287
*/
291
- private RequestBody buildRequestBody (RequestBody requestBody , Components components ,
288
+ private RequestBody buildRequestBody (io . swagger . v3 . oas . annotations . parameters . RequestBody requestBodyDoc , Components components ,
292
289
MethodAttributes methodAttributes ,
293
290
ParameterInfo parameterInfo , RequestBodyInfo requestBodyInfo ) {
291
+ RequestBody requestBody = requestBodyInfo .getRequestBody ();
294
292
if (requestBody == null ) {
295
293
requestBody = new RequestBody ();
296
294
requestBodyInfo .setRequestBody (requestBody );
297
295
}
298
296
299
- if (requestBody .getContent () == null ) {
300
- Schema <?> schema = parameterBuilder .calculateSchema (components , parameterInfo , requestBodyInfo ,
301
- methodAttributes .getJsonViewAnnotationForRequestBody ());
302
- Map <String , Encoding > parameterEncoding = getParameterEncoding (parameterInfo );
303
- buildContent (requestBody , methodAttributes , schema , parameterEncoding );
304
- }
305
- else if (!methodAttributes .isWithResponseBodySchemaDoc ()) {
306
- Schema <?> schema = parameterBuilder .calculateSchema (components , parameterInfo , requestBodyInfo ,
307
- methodAttributes .getJsonViewAnnotationForRequestBody ());
308
- Map <String , Encoding > parameterEncoding = getParameterEncoding (parameterInfo );
309
- mergeContent (requestBody , methodAttributes , schema , parameterEncoding );
310
- }
297
+ if (requestBodyDoc != null )
298
+ requestBody = this .buildRequestBodyFromDoc (requestBodyDoc , methodAttributes , components ).orElse (requestBody );
299
+
300
+ Schema <?> schema = parameterBuilder .calculateSchema (components , parameterInfo , requestBodyInfo ,
301
+ methodAttributes .getJsonViewAnnotationForRequestBody ());
302
+ Map <String , Encoding > parameterEncoding = getParameterEncoding (parameterInfo );
303
+ buildContent (requestBody , methodAttributes , schema , parameterEncoding );
311
304
312
305
// Add requestBody javadoc
313
306
if (StringUtils .isBlank (requestBody .getDescription ()) && parameterBuilder .getJavadocProvider () != null
@@ -320,18 +313,6 @@ else if (!methodAttributes.isWithResponseBodySchemaDoc()) {
320
313
return requestBody ;
321
314
}
322
315
323
- /**
324
- * Merge content.
325
- *
326
- * @param requestBody the request body
327
- * @param methodAttributes the method attributes
328
- * @param parameterEncoding the parameter encoding
329
- */
330
- private void mergeContent (RequestBody requestBody , MethodAttributes methodAttributes , Schema <?> schema , Map <String , Encoding > parameterEncoding ) {
331
- Content content = requestBody .getContent ();
332
- buildContent (requestBody , methodAttributes , schema , content , parameterEncoding );
333
- }
334
-
335
316
/**
336
317
* Build content.
337
318
*
@@ -341,31 +322,27 @@ private void mergeContent(RequestBody requestBody, MethodAttributes methodAttrib
341
322
* @param parameterEncoding the parameter encoding
342
323
*/
343
324
private void buildContent (RequestBody requestBody , MethodAttributes methodAttributes , Schema <?> schema , Map <String , Encoding > parameterEncoding ) {
344
- Content content = new Content ();
345
- buildContent (requestBody , methodAttributes , schema , content , parameterEncoding );
346
- }
325
+ Content content ;
326
+ if (requestBody .getContent () == null ) {
327
+ content = new Content ();
328
+ }
329
+ else {
330
+ content = requestBody .getContent ();
331
+ }
347
332
348
- /**
349
- * Build content.
350
- *
351
- * @param requestBody the request body
352
- * @param methodAttributes the method attributes
353
- * @param schema the schema
354
- * @param content the content
355
- * @param parameterEncoding the parameter encoding
356
- */
357
- private void buildContent (RequestBody requestBody , MethodAttributes methodAttributes , Schema <?> schema , Content content , Map <String , Encoding > parameterEncoding ) {
358
333
for (String value : methodAttributes .getMethodConsumes ()) {
359
334
MediaType mediaTypeObject = new MediaType ();
360
- mediaTypeObject .setSchema (schema );
361
335
MediaType mediaType = content .get (value );
336
+ mediaTypeObject .setSchema (schema );
362
337
if (mediaType != null ) {
363
338
if (mediaType .getExample () != null )
364
339
mediaTypeObject .setExample (mediaType .getExample ());
365
340
if (mediaType .getExamples () != null )
366
341
mediaTypeObject .setExamples (mediaType .getExamples ());
367
342
if (mediaType .getEncoding () != null )
368
343
mediaTypeObject .setEncoding (mediaType .getEncoding ());
344
+ if (mediaType .getSchema () != null )
345
+ mediaTypeObject .setSchema (mediaType .getSchema ());
369
346
}
370
347
else if (!CollectionUtils .isEmpty (parameterEncoding )) {
371
348
mediaTypeObject .setEncoding (parameterEncoding );
@@ -392,7 +369,7 @@ private Map<String, Encoding> getParameterEncoding(ParameterInfo parameterInfo)
392
369
}
393
370
else {
394
371
String encodingContentType = parameterContent .keySet ().iterator ().next ();
395
- if (StringUtils .isNotBlank (encodingContentType )) {
372
+ if (StringUtils .isNotBlank (encodingContentType )) {
396
373
return Map .of (parameterInfo .getpName (), new Encoding ().contentType (encodingContentType ));
397
374
}
398
375
}
0 commit comments