4343import org .apache .commons .lang3 .ArrayUtils ;
4444import org .apache .commons .lang3 .StringUtils ;
4545
46+ import org .springframework .core .MethodParameter ;
4647import org .springframework .core .annotation .AnnotatedElementUtils ;
4748import org .springframework .http .HttpStatus ;
4849import org .springframework .util .CollectionUtils ;
@@ -82,7 +83,7 @@ public ApiResponses build(Components components, HandlerMethod handlerMethod, Op
8283 apiResponsesFromDoc .forEach (apiResponses ::addApiResponse );
8384 // for each one build ApiResponse and add it to existing responses
8485 // Fill api Responses
85- computeResponse (components , handlerMethod .getMethod (), handlerMethod . getReturnType (). getParameterType (), apiResponses , methodAttributes , false );
86+ computeResponse (components , handlerMethod .getReturnType (), apiResponses , methodAttributes , false );
8687 return apiResponses ;
8788 }
8889
@@ -97,7 +98,7 @@ public void buildGenericResponse(Components components, Map<String, Object> find
9798 if (reqMappringMethod != null ) {
9899 methodProduces = reqMappringMethod .produces ();
99100 }
100- Map <String , ApiResponse > apiResponses = computeResponse (components , method ,null , new ApiResponses (),
101+ Map <String , ApiResponse > apiResponses = computeResponse (components , new MethodParameter ( method ,- 1 ) , new ApiResponses (),
101102 new MethodAttributes (methodProduces , springDocConfigProperties .getDefaultConsumesMediaType (), springDocConfigProperties .getDefaultProducesMediaType ()), true );
102103 apiResponses .forEach (genericMapResponse ::put );
103104 }
@@ -118,10 +119,10 @@ private List<Method> getMethods(Map<String, Object> findControllerAdvice) {
118119 return methods ;
119120 }
120121
121- private Map <String , ApiResponse > computeResponse (Components components , Method method , Class <?> clazz , ApiResponses apiResponsesOp ,
122+ private Map <String , ApiResponse > computeResponse (Components components , MethodParameter methodParameter , ApiResponses apiResponsesOp ,
122123 MethodAttributes methodAttributes , boolean isGeneric ) {
123124 // Parsing documentation, if present
124- Set <io .swagger .v3 .oas .annotations .responses .ApiResponse > responsesArray = getApiResponses (method );
125+ Set <io .swagger .v3 .oas .annotations .responses .ApiResponse > responsesArray = getApiResponses (methodParameter . getMethod () );
125126 if (!responsesArray .isEmpty ()) {
126127 methodAttributes .setWithApiResponseDoc (true );
127128 if (!springDocConfigProperties .isOverrideWithGenericResponse ())
@@ -146,7 +147,7 @@ private Map<String, ApiResponse> computeResponse(Components components, Method m
146147 apiResponsesOp .addApiResponse (apiResponseAnnotations .responseCode (), apiResponse );
147148 }
148149 }
149- buildApiResponses (components , method , clazz , apiResponsesOp , methodAttributes , isGeneric );
150+ buildApiResponses (components , methodParameter , apiResponsesOp , methodAttributes , isGeneric );
150151 return apiResponsesOp ;
151152 }
152153
@@ -174,25 +175,25 @@ private void buildContentFromDoc(Components components, ApiResponses apiResponse
174175 }
175176 }
176177
177- private void buildApiResponses (Components components , Method method , Class <?> clazz , ApiResponses apiResponsesOp ,
178+ private void buildApiResponses (Components components , MethodParameter methodParameter , ApiResponses apiResponsesOp ,
178179 MethodAttributes methodAttributes , boolean isGeneric ) {
179180 if (!CollectionUtils .isEmpty (apiResponsesOp ) && (apiResponsesOp .size () != genericMapResponse .size () || isGeneric )) {
180181 // API Responses at operation and @ApiResponse annotation
181182 for (Map .Entry <String , ApiResponse > entry : apiResponsesOp .entrySet ()) {
182183 String httpCode = entry .getKey ();
183184 ApiResponse apiResponse = entry .getValue ();
184- buildApiResponses (components , method , clazz , apiResponsesOp , methodAttributes , httpCode , apiResponse ,
185+ buildApiResponses (components , methodParameter , apiResponsesOp , methodAttributes , httpCode , apiResponse ,
185186 isGeneric );
186187 }
187188 }
188189 else {
189190 // Use response parameters with no description filled - No documentation
190191 // available
191- String httpCode = evaluateResponseStatus (method , method .getClass (), isGeneric );
192+ String httpCode = evaluateResponseStatus (methodParameter . getMethod (), methodParameter . getMethod () .getClass (), isGeneric );
192193 ApiResponse apiResponse = genericMapResponse .containsKey (httpCode ) ? genericMapResponse .get (httpCode )
193194 : new ApiResponse ();
194195 if (httpCode != null )
195- buildApiResponses (components , method , clazz , apiResponsesOp , methodAttributes , httpCode , apiResponse ,
196+ buildApiResponses (components , methodParameter , apiResponsesOp , methodAttributes , httpCode , apiResponse ,
196197 isGeneric );
197198 }
198199 }
@@ -222,9 +223,9 @@ private Set<io.swagger.v3.oas.annotations.responses.ApiResponse> getApiResponses
222223 return responses ;
223224 }
224225
225- private Content buildContent (Components components , Method method , Class <?> clazz , String [] methodProduces , JsonView jsonView ) {
226+ private Content buildContent (Components components , MethodParameter methodParameter , String [] methodProduces , JsonView jsonView ) {
226227 Content content = new Content ();
227- Type returnType = getReturnType (method , clazz );
228+ Type returnType = getReturnType (methodParameter );
228229 if (isVoid (returnType )) {
229230 // if void, no content
230231 content = null ;
@@ -241,11 +242,11 @@ else if (ArrayUtils.isNotEmpty(methodProduces)) {
241242 return content ;
242243 }
243244
244- private Type getReturnType (Method method , Class <?> clazz ) {
245+ private Type getReturnType (MethodParameter methodParameter ) {
245246 Type returnType = Object .class ;
246247 for (ReturnTypeParser returnTypeParser : returnTypeParsers ) {
247248 if (returnType .getTypeName ().equals (Object .class .getTypeName ())) {
248- returnType = returnTypeParser .getReturnType (method , clazz );
249+ returnType = returnTypeParser .getReturnType (methodParameter );
249250 }
250251 else {
251252 break ;
@@ -272,12 +273,12 @@ private void setContent(String[] methodProduces, Content content,
272273 Arrays .stream (methodProduces ).forEach (mediaTypeStr -> content .addMediaType (mediaTypeStr , mediaType ));
273274 }
274275
275- private void buildApiResponses (Components components , Method method , Class <?> clazz , ApiResponses apiResponsesOp ,
276+ private void buildApiResponses (Components components , MethodParameter methodParameter , ApiResponses apiResponsesOp ,
276277 MethodAttributes methodAttributes , String httpCode , ApiResponse apiResponse , boolean isGeneric ) {
277278 // No documentation
278279 if (StringUtils .isBlank (apiResponse .get$ref ())) {
279280 if (apiResponse .getContent () == null ) {
280- Content content = buildContent (components , method , clazz , methodAttributes .getMethodProduces (),
281+ Content content = buildContent (components , methodParameter , methodAttributes .getMethodProduces (),
281282 methodAttributes .getJsonViewAnnotation ());
282283 apiResponse .setContent (content );
283284 }
@@ -292,7 +293,7 @@ else if (CollectionUtils.isEmpty(apiResponse.getContent())) {
292293 && ((isGeneric || methodAttributes .isMethodOverloaded ()) && methodAttributes .isNoApiResponseDoc ())) {
293294 // Merge with existing schema
294295 Content existingContent = apiResponse .getContent ();
295- Schema <?> schemaN = calculateSchema (components , method . getGenericReturnType (),
296+ Schema <?> schemaN = calculateSchema (components , methodParameter . getGenericParameterType (),
296297 methodAttributes .getJsonViewAnnotation ());
297298 if (schemaN != null && ArrayUtils .isNotEmpty (methodAttributes .getMethodProduces ())) {
298299 Arrays .stream (methodAttributes .getMethodProduces ()).forEach (mediaTypeStr -> mergeSchema (existingContent , schemaN , mediaTypeStr ));
0 commit comments