@@ -82,7 +82,7 @@ public ApiResponses build(Components components, HandlerMethod handlerMethod, Op
8282 apiResponsesFromDoc .forEach (apiResponses ::addApiResponse );
8383 // for each one build ApiResponse and add it to existing responses
8484 // Fill api Responses
85- computeResponse (components , handlerMethod .getMethod (), apiResponses , methodAttributes , false );
85+ computeResponse (components , handlerMethod .getMethod (), handlerMethod . getReturnType (). getParameterType (), apiResponses , methodAttributes , false );
8686 return apiResponses ;
8787 }
8888
@@ -97,7 +97,7 @@ public void buildGenericResponse(Components components, Map<String, Object> find
9797 if (reqMappringMethod != null ) {
9898 methodProduces = reqMappringMethod .produces ();
9999 }
100- Map <String , ApiResponse > apiResponses = computeResponse (components , method , new ApiResponses (),
100+ Map <String , ApiResponse > apiResponses = computeResponse (components , method ,null , new ApiResponses (),
101101 new MethodAttributes (methodProduces , springDocConfigProperties .getDefaultConsumesMediaType (), springDocConfigProperties .getDefaultProducesMediaType ()), true );
102102 apiResponses .forEach (genericMapResponse ::put );
103103 }
@@ -118,7 +118,7 @@ private List<Method> getMethods(Map<String, Object> findControllerAdvice) {
118118 return methods ;
119119 }
120120
121- private Map <String , ApiResponse > computeResponse (Components components , Method method , ApiResponses apiResponsesOp ,
121+ private Map <String , ApiResponse > computeResponse (Components components , Method method , Class <?> clazz , ApiResponses apiResponsesOp ,
122122 MethodAttributes methodAttributes , boolean isGeneric ) {
123123 // Parsing documentation, if present
124124 Set <io .swagger .v3 .oas .annotations .responses .ApiResponse > responsesArray = getApiResponses (method );
@@ -146,7 +146,7 @@ private Map<String, ApiResponse> computeResponse(Components components, Method m
146146 apiResponsesOp .addApiResponse (apiResponseAnnotations .responseCode (), apiResponse );
147147 }
148148 }
149- buildApiResponses (components , method , apiResponsesOp , methodAttributes , isGeneric );
149+ buildApiResponses (components , method , clazz , apiResponsesOp , methodAttributes , isGeneric );
150150 return apiResponsesOp ;
151151 }
152152
@@ -174,14 +174,14 @@ private void buildContentFromDoc(Components components, ApiResponses apiResponse
174174 }
175175 }
176176
177- private void buildApiResponses (Components components , Method method , ApiResponses apiResponsesOp ,
177+ private void buildApiResponses (Components components , Method method , Class <?> clazz , ApiResponses apiResponsesOp ,
178178 MethodAttributes methodAttributes , boolean isGeneric ) {
179179 if (!CollectionUtils .isEmpty (apiResponsesOp ) && (apiResponsesOp .size () != genericMapResponse .size () || isGeneric )) {
180180 // API Responses at operation and @ApiResponse annotation
181181 for (Map .Entry <String , ApiResponse > entry : apiResponsesOp .entrySet ()) {
182182 String httpCode = entry .getKey ();
183183 ApiResponse apiResponse = entry .getValue ();
184- buildApiResponses (components , method , apiResponsesOp , methodAttributes , httpCode , apiResponse ,
184+ buildApiResponses (components , method , clazz , apiResponsesOp , methodAttributes , httpCode , apiResponse ,
185185 isGeneric );
186186 }
187187 }
@@ -192,7 +192,7 @@ private void buildApiResponses(Components components, Method method, ApiResponse
192192 ApiResponse apiResponse = genericMapResponse .containsKey (httpCode ) ? genericMapResponse .get (httpCode )
193193 : new ApiResponse ();
194194 if (httpCode != null )
195- buildApiResponses (components , method , apiResponsesOp , methodAttributes , httpCode , apiResponse ,
195+ buildApiResponses (components , method , clazz , apiResponsesOp , methodAttributes , httpCode , apiResponse ,
196196 isGeneric );
197197 }
198198 }
@@ -222,9 +222,9 @@ private Set<io.swagger.v3.oas.annotations.responses.ApiResponse> getApiResponses
222222 return responses ;
223223 }
224224
225- private Content buildContent (Components components , Method method , String [] methodProduces , JsonView jsonView ) {
225+ private Content buildContent (Components components , Method method , Class <?> clazz , String [] methodProduces , JsonView jsonView ) {
226226 Content content = new Content ();
227- Type returnType = getReturnType (method );
227+ Type returnType = getReturnType (method , clazz );
228228 if (isVoid (returnType )) {
229229 // if void, no content
230230 content = null ;
@@ -241,11 +241,11 @@ else if (ArrayUtils.isNotEmpty(methodProduces)) {
241241 return content ;
242242 }
243243
244- private Type getReturnType (Method method ) {
244+ private Type getReturnType (Method method , Class <?> clazz ) {
245245 Type returnType = Object .class ;
246246 for (ReturnTypeParser returnTypeParser : returnTypeParsers ) {
247247 if (returnType .getTypeName ().equals (Object .class .getTypeName ())) {
248- returnType = returnTypeParser .getReturnType (method );
248+ returnType = returnTypeParser .getReturnType (method , clazz );
249249 }
250250 else {
251251 break ;
@@ -272,12 +272,12 @@ private void setContent(String[] methodProduces, Content content,
272272 Arrays .stream (methodProduces ).forEach (mediaTypeStr -> content .addMediaType (mediaTypeStr , mediaType ));
273273 }
274274
275- private void buildApiResponses (Components components , Method method , ApiResponses apiResponsesOp ,
275+ private void buildApiResponses (Components components , Method method , Class <?> clazz , ApiResponses apiResponsesOp ,
276276 MethodAttributes methodAttributes , String httpCode , ApiResponse apiResponse , boolean isGeneric ) {
277277 // No documentation
278278 if (StringUtils .isBlank (apiResponse .get$ref ())) {
279279 if (apiResponse .getContent () == null ) {
280- Content content = buildContent (components , method , methodAttributes .getMethodProduces (),
280+ Content content = buildContent (components , method ,clazz , methodAttributes .getMethodProduces (),
281281 methodAttributes .getJsonViewAnnotation ());
282282 apiResponse .setContent (content );
283283 }
0 commit comments