@@ -257,11 +257,6 @@ public void calculateRequestBodyInfo(Components components, MethodAttributes met
257257 ParameterInfo parameterInfo , RequestBodyInfo requestBodyInfo ) {
258258 RequestBody requestBody = requestBodyInfo .getRequestBody ();
259259 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- }
265260
266261 RequestPart requestPart = methodParameter .getParameterAnnotation (RequestPart .class );
267262 String paramName = null ;
@@ -273,41 +268,38 @@ public void calculateRequestBodyInfo(Components components, MethodAttributes met
273268 paramName = StringUtils .defaultIfEmpty (paramName , parameterInfo .getpName ());
274269 parameterInfo .setpName (paramName );
275270
276- requestBody = buildRequestBody (requestBody , components , methodAttributes , parameterInfo ,
271+ io .swagger .v3 .oas .annotations .parameters .RequestBody requestBodyDoc = methodParameter .getParameterAnnotation (io .swagger .v3 .oas .annotations .parameters .RequestBody .class );
272+ requestBody = buildRequestBody (requestBodyDoc , components , methodAttributes , parameterInfo ,
277273 requestBodyInfo );
278274 requestBodyInfo .setRequestBody (requestBody );
279275 }
280276
281277 /**
282278 * Build request body.
283279 *
284- * @param requestBody the request body
280+ * @param requestBodyDoc the request body
285281 * @param components the components
286282 * @param methodAttributes the method attributes
287283 * @param parameterInfo the parameter info
288284 * @param requestBodyInfo the request body info
289285 * @return the request body
290286 */
291- private RequestBody buildRequestBody (RequestBody requestBody , Components components ,
287+ private RequestBody buildRequestBody (io . swagger . v3 . oas . annotations . parameters . RequestBody requestBodyDoc , Components components ,
292288 MethodAttributes methodAttributes ,
293289 ParameterInfo parameterInfo , RequestBodyInfo requestBodyInfo ) {
290+ RequestBody requestBody = requestBodyInfo .getRequestBody ();
294291 if (requestBody == null ) {
295292 requestBody = new RequestBody ();
296293 requestBodyInfo .setRequestBody (requestBody );
297294 }
298295
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- }
296+ if (requestBodyDoc != null )
297+ requestBody = this .buildRequestBodyFromDoc (requestBodyDoc , methodAttributes , components ).orElse (requestBody );
298+
299+ Schema <?> schema = parameterBuilder .calculateSchema (components , parameterInfo , requestBodyInfo ,
300+ methodAttributes .getJsonViewAnnotationForRequestBody ());
301+ Map <String , Encoding > parameterEncoding = getParameterEncoding (parameterInfo );
302+ buildContent (requestBody , methodAttributes , schema , parameterEncoding );
311303
312304 // Add requestBody javadoc
313305 if (StringUtils .isBlank (requestBody .getDescription ()) && parameterBuilder .getJavadocProvider () != null
@@ -320,18 +312,6 @@ else if (!methodAttributes.isWithResponseBodySchemaDoc()) {
320312 return requestBody ;
321313 }
322314
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-
335315 /**
336316 * Build content.
337317 *
@@ -341,31 +321,27 @@ private void mergeContent(RequestBody requestBody, MethodAttributes methodAttrib
341321 * @param parameterEncoding the parameter encoding
342322 */
343323 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- }
324+ Content content ;
325+ if (requestBody .getContent () == null ) {
326+ content = new Content ();
327+ }
328+ else {
329+ content = requestBody .getContent ();
330+ }
347331
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 ) {
358332 for (String value : methodAttributes .getMethodConsumes ()) {
359333 MediaType mediaTypeObject = new MediaType ();
360- mediaTypeObject .setSchema (schema );
361334 MediaType mediaType = content .get (value );
335+ mediaTypeObject .setSchema (schema );
362336 if (mediaType != null ) {
363337 if (mediaType .getExample () != null )
364338 mediaTypeObject .setExample (mediaType .getExample ());
365339 if (mediaType .getExamples () != null )
366340 mediaTypeObject .setExamples (mediaType .getExamples ());
367341 if (mediaType .getEncoding () != null )
368342 mediaTypeObject .setEncoding (mediaType .getEncoding ());
343+ if (mediaType .getSchema () != null )
344+ mediaTypeObject .setSchema (mediaType .getSchema ());
369345 }
370346 else if (!CollectionUtils .isEmpty (parameterEncoding )) {
371347 mediaTypeObject .setEncoding (parameterEncoding );
0 commit comments