@@ -180,22 +180,22 @@ public GenericResponseService(OperationService operationService,
180180 * @param components the components
181181 * @param apiResponsesOp the api responses op
182182 * @param methodAttributes the method attributes
183- * @param apiResponseAnnotations the api response annotations
183+ * @param apiResponseAnnotation the api response annotation
184184 * @param apiResponse the api response
185185 * @param openapi31 the openapi 31
186186 */
187187 public static void buildContentFromDoc (Components components , ApiResponses apiResponsesOp ,
188188 MethodAttributes methodAttributes ,
189- io .swagger .v3 .oas .annotations .responses .ApiResponse apiResponseAnnotations ,
189+ io .swagger .v3 .oas .annotations .responses .ApiResponse apiResponseAnnotation ,
190190 ApiResponse apiResponse , boolean openapi31 ) {
191191
192- methodAttributes .setUseReturnTypeSchema ( apiResponseAnnotations .useReturnTypeSchema ());
193- io .swagger .v3 .oas .annotations .media .Content [] contentdoc = apiResponseAnnotations .content ();
192+ methodAttributes .putUseReturnTypeSchema ( apiResponseAnnotation . responseCode (), apiResponseAnnotation .useReturnTypeSchema ());
193+ io .swagger .v3 .oas .annotations .media .Content [] contentdoc = apiResponseAnnotation .content ();
194194 Optional <Content > optionalContent = getContent (contentdoc , new String [0 ],
195195 methodAttributes .getMethodProduces (), null , components , methodAttributes .getJsonViewAnnotation (), openapi31 );
196- if (apiResponsesOp .containsKey (apiResponseAnnotations .responseCode ())) {
196+ if (apiResponsesOp .containsKey (apiResponseAnnotation .responseCode ())) {
197197 // Merge with the existing content
198- Content existingContent = apiResponsesOp .get (apiResponseAnnotations .responseCode ()).getContent ();
198+ Content existingContent = apiResponsesOp .get (apiResponseAnnotation .responseCode ()).getContent ();
199199 if (optionalContent .isPresent ()) {
200200 Content newContent = optionalContent .get ();
201201 if (methodAttributes .isMethodOverloaded () && existingContent != null ) {
@@ -387,17 +387,17 @@ private Map<String, ApiResponse> computeResponseFromDoc(Components components, M
387387 Set <io .swagger .v3 .oas .annotations .responses .ApiResponse > responsesArray = getApiResponses (Objects .requireNonNull (methodParameter .getMethod ()));
388388 if (!responsesArray .isEmpty ()) {
389389 methodAttributes .setWithApiResponseDoc (true );
390- for (io .swagger .v3 .oas .annotations .responses .ApiResponse apiResponseAnnotations : responsesArray ) {
391- String httpCode = apiResponseAnnotations .responseCode ();
390+ for (io .swagger .v3 .oas .annotations .responses .ApiResponse apiResponseAnnotation : responsesArray ) {
391+ String httpCode = apiResponseAnnotation .responseCode ();
392392 ApiResponse apiResponse = new ApiResponse ();
393- if (StringUtils .isNotBlank (apiResponseAnnotations .ref ())) {
394- apiResponse .$ref (apiResponseAnnotations .ref ());
395- apiResponsesOp .addApiResponse (apiResponseAnnotations .responseCode (), apiResponse );
393+ if (StringUtils .isNotBlank (apiResponseAnnotation .ref ())) {
394+ apiResponse .$ref (apiResponseAnnotation .ref ());
395+ apiResponsesOp .addApiResponse (apiResponseAnnotation .responseCode (), apiResponse );
396396 continue ;
397397 }
398- apiResponse .setDescription (propertyResolverUtils .resolve (apiResponseAnnotations .description (), methodAttributes .getLocale ()));
399- buildContentFromDoc (components , apiResponsesOp , methodAttributes , apiResponseAnnotations , apiResponse , openapi31 );
400- Map <String , Object > extensions = AnnotationsUtils .getExtensions (propertyResolverUtils .isOpenapi31 (), apiResponseAnnotations .extensions ());
398+ apiResponse .setDescription (propertyResolverUtils .resolve (apiResponseAnnotation .description (), methodAttributes .getLocale ()));
399+ buildContentFromDoc (components , apiResponsesOp , methodAttributes , apiResponseAnnotation , apiResponse , openapi31 );
400+ Map <String , Object > extensions = AnnotationsUtils .getExtensions (propertyResolverUtils .isOpenapi31 (), apiResponseAnnotation .extensions ());
401401 if (!CollectionUtils .isEmpty (extensions )) {
402402 if (propertyResolverUtils .isResolveExtensionsProperties ()) {
403403 Map <String , Object > extensionsResolved = propertyResolverUtils .resolveExtensions (locale , extensions );
@@ -407,7 +407,7 @@ private Map<String, ApiResponse> computeResponseFromDoc(Components components, M
407407 apiResponse .extensions (extensions );
408408 }
409409 }
410- SpringDocAnnotationsUtils .getHeaders (apiResponseAnnotations .headers (), components , methodAttributes .getJsonViewAnnotation (), openapi31 )
410+ SpringDocAnnotationsUtils .getHeaders (apiResponseAnnotation .headers (), components , methodAttributes .getJsonViewAnnotation (), openapi31 )
411411 .ifPresent (apiResponse ::headers );
412412 apiResponsesOp .addApiResponse (httpCode , apiResponse );
413413 }
@@ -622,8 +622,7 @@ else if (CollectionUtils.isEmpty(apiResponse.getContent()))
622622 setDescription (httpCode , apiResponse );
623623 }
624624 }
625- if (apiResponse .getContent () != null && (methodAttributes .isUseReturnTypeSchema () ||
626- ((isGeneric || methodAttributes .isMethodOverloaded ()) && methodAttributes .isNoApiResponseDoc ()))) {
625+ if (apiResponse .getContent () != null && shouldCalculateContent (methodAttributes , isGeneric , httpCode )) {
627626 // Merge with existing schema
628627 Content existingContent = apiResponse .getContent ();
629628 Type type = GenericTypeResolver .resolveType (methodParameter .getGenericParameterType (), methodParameter .getContainingClass ());
@@ -642,6 +641,28 @@ else if (CollectionUtils.isEmpty(apiResponse.getContent()))
642641 apiResponsesOp .addApiResponse (httpCode , apiResponse );
643642 }
644643
644+ /**
645+ * Whether to consider calculating additional content.
646+ *
647+ * @param methodAttributes the method attributes
648+ * @param isGeneric the is generic
649+ * @param httpCode the http code
650+ */
651+ private boolean shouldCalculateContent (MethodAttributes methodAttributes , boolean isGeneric , String httpCode ) {
652+ return useReturnTypeSchema (methodAttributes , httpCode ) ||
653+ ((isGeneric || methodAttributes .isMethodOverloaded ()) && methodAttributes .isNoApiResponseDoc ());
654+ }
655+
656+ /**
657+ * Whether to use return type schema.
658+ *
659+ * @param methodAttributes the method attributes
660+ * @param httpCode the http code
661+ */
662+ private boolean useReturnTypeSchema (MethodAttributes methodAttributes , String httpCode ) {
663+ return methodAttributes .getUseReturnTypeSchema ().getOrDefault (httpCode , false );
664+ }
665+
645666 /**
646667 * Evaluate response status string.
647668 *
0 commit comments