6060import io .swagger .v3 .oas .models .responses .ApiResponses ;
6161import org .apache .commons .lang3 .ArrayUtils ;
6262import org .apache .commons .lang3 .StringUtils ;
63- import org .slf4j .Logger ;
64- import org .slf4j .LoggerFactory ;
6563import org .springdoc .core .models .ControllerAdviceInfo ;
6664import org .springdoc .core .models .MethodAdviceInfo ;
6765import org .springdoc .core .models .MethodAttributes ;
@@ -113,11 +111,6 @@ public class GenericResponseService implements ApplicationContextAware {
113111 */
114112 private static final String EXTENSION_EXCEPTION_CLASSES = "x-exception-class" ;
115113
116- /**
117- * The constant LOGGER.
118- */
119- private static final Logger LOGGER = LoggerFactory .getLogger (GenericResponseService .class );
120-
121114 /**
122115 * The Response entity exception handler class.
123116 */
@@ -180,22 +173,22 @@ public GenericResponseService(OperationService operationService,
180173 * @param components the components
181174 * @param apiResponsesOp the api responses op
182175 * @param methodAttributes the method attributes
183- * @param apiResponseAnnotations the api response annotations
176+ * @param apiResponseAnnotation the api response annotations
184177 * @param apiResponse the api response
185178 * @param openapi31 the openapi 31
186179 */
187180 public static void buildContentFromDoc (Components components , ApiResponses apiResponsesOp ,
188181 MethodAttributes methodAttributes ,
189- io .swagger .v3 .oas .annotations .responses .ApiResponse apiResponseAnnotations ,
182+ io .swagger .v3 .oas .annotations .responses .ApiResponse apiResponseAnnotation ,
190183 ApiResponse apiResponse , boolean openapi31 ) {
191184
192- methodAttributes .setUseReturnTypeSchema ( apiResponseAnnotations .useReturnTypeSchema ());
193- io .swagger .v3 .oas .annotations .media .Content [] contentdoc = apiResponseAnnotations .content ();
185+ methodAttributes .putUseReturnTypeSchema ( apiResponseAnnotation . responseCode (), apiResponseAnnotation .useReturnTypeSchema ());
186+ io .swagger .v3 .oas .annotations .media .Content [] contentdoc = apiResponseAnnotation .content ();
194187 Optional <Content > optionalContent = getContent (contentdoc , new String [0 ],
195188 methodAttributes .getMethodProduces (), null , components , methodAttributes .getJsonViewAnnotation (), openapi31 );
196- if (apiResponsesOp .containsKey (apiResponseAnnotations .responseCode ())) {
189+ if (apiResponsesOp .containsKey (apiResponseAnnotation .responseCode ())) {
197190 // Merge with the existing content
198- Content existingContent = apiResponsesOp .get (apiResponseAnnotations .responseCode ()).getContent ();
191+ Content existingContent = apiResponsesOp .get (apiResponseAnnotation .responseCode ()).getContent ();
199192 if (optionalContent .isPresent ()) {
200193 Content newContent = optionalContent .get ();
201194 if (methodAttributes .isMethodOverloaded () && existingContent != null ) {
@@ -217,6 +210,7 @@ public static void buildContentFromDoc(Components components, ApiResponses apiRe
217210 }
218211 }
219212
213+
220214 /**
221215 * Sets description.
222216 *
@@ -387,17 +381,17 @@ private Map<String, ApiResponse> computeResponseFromDoc(Components components, M
387381 Set <io .swagger .v3 .oas .annotations .responses .ApiResponse > responsesArray = getApiResponses (Objects .requireNonNull (methodParameter .getMethod ()));
388382 if (!responsesArray .isEmpty ()) {
389383 methodAttributes .setWithApiResponseDoc (true );
390- for (io .swagger .v3 .oas .annotations .responses .ApiResponse apiResponseAnnotations : responsesArray ) {
391- String httpCode = apiResponseAnnotations .responseCode ();
384+ for (io .swagger .v3 .oas .annotations .responses .ApiResponse apiResponseAnnotation : responsesArray ) {
385+ String httpCode = apiResponseAnnotation .responseCode ();
392386 ApiResponse apiResponse = new ApiResponse ();
393- if (StringUtils .isNotBlank (apiResponseAnnotations .ref ())) {
394- apiResponse .$ref (apiResponseAnnotations .ref ());
395- apiResponsesOp .addApiResponse (apiResponseAnnotations .responseCode (), apiResponse );
387+ if (StringUtils .isNotBlank (apiResponseAnnotation .ref ())) {
388+ apiResponse .$ref (apiResponseAnnotation .ref ());
389+ apiResponsesOp .addApiResponse (apiResponseAnnotation .responseCode (), apiResponse );
396390 continue ;
397391 }
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 ());
392+ apiResponse .setDescription (propertyResolverUtils .resolve (apiResponseAnnotation .description (), methodAttributes .getLocale ()));
393+ buildContentFromDoc (components , apiResponsesOp , methodAttributes , apiResponseAnnotation , apiResponse , openapi31 );
394+ Map <String , Object > extensions = AnnotationsUtils .getExtensions (propertyResolverUtils .isOpenapi31 (), apiResponseAnnotation .extensions ());
401395 if (!CollectionUtils .isEmpty (extensions )) {
402396 if (propertyResolverUtils .isResolveExtensionsProperties ()) {
403397 Map <String , Object > extensionsResolved = propertyResolverUtils .resolveExtensions (locale , extensions );
@@ -407,7 +401,7 @@ private Map<String, ApiResponse> computeResponseFromDoc(Components components, M
407401 apiResponse .extensions (extensions );
408402 }
409403 }
410- SpringDocAnnotationsUtils .getHeaders (apiResponseAnnotations .headers (), components , methodAttributes .getJsonViewAnnotation (), openapi31 )
404+ SpringDocAnnotationsUtils .getHeaders (apiResponseAnnotation .headers (), components , methodAttributes .getJsonViewAnnotation (), openapi31 )
411405 .ifPresent (apiResponse ::headers );
412406 apiResponsesOp .addApiResponse (httpCode , apiResponse );
413407 }
@@ -622,8 +616,7 @@ else if (CollectionUtils.isEmpty(apiResponse.getContent()))
622616 setDescription (httpCode , apiResponse );
623617 }
624618 }
625- if (apiResponse .getContent () != null && (methodAttributes .isUseReturnTypeSchema () ||
626- ((isGeneric || methodAttributes .isMethodOverloaded ()) && methodAttributes .isNoApiResponseDoc ()))) {
619+ if (apiResponse .getContent () != null && shouldCalculateContent (methodAttributes , isGeneric , httpCode )) {
627620 // Merge with existing schema
628621 Content existingContent = apiResponse .getContent ();
629622 Type type = GenericTypeResolver .resolveType (methodParameter .getGenericParameterType (), methodParameter .getContainingClass ());
@@ -642,6 +635,28 @@ else if (CollectionUtils.isEmpty(apiResponse.getContent()))
642635 apiResponsesOp .addApiResponse (httpCode , apiResponse );
643636 }
644637
638+ /**
639+ * Whether to consider calculating additional content.
640+ *
641+ * @param methodAttributes the method attributes
642+ * @param isGeneric the is generic
643+ * @param httpCode the http code
644+ */
645+ private boolean shouldCalculateContent (MethodAttributes methodAttributes , boolean isGeneric , String httpCode ) {
646+ return useReturnTypeSchema (methodAttributes , httpCode ) ||
647+ ((isGeneric || methodAttributes .isMethodOverloaded ()) && methodAttributes .isNoApiResponseDoc ());
648+ }
649+
650+ /**
651+ * Whether to use return type schema.
652+ *
653+ * @param methodAttributes the method attributes
654+ * @param httpCode the http code
655+ */
656+ private boolean useReturnTypeSchema (MethodAttributes methodAttributes , String httpCode ) {
657+ return methodAttributes .getUseReturnTypeSchema ().getOrDefault (httpCode , false );
658+ }
659+
645660 /**
646661 * Evaluate response status string.
647662 *
0 commit comments