@@ -82,7 +82,7 @@ public ApiResponses build(Components components, HandlerMethod handlerMethod, Op
82
82
apiResponsesFromDoc .forEach (apiResponses ::addApiResponse );
83
83
// for each one build ApiResponse and add it to existing responses
84
84
// Fill api Responses
85
- computeResponse (components , handlerMethod .getMethod (), apiResponses , methodAttributes , false );
85
+ computeResponse (components , handlerMethod .getMethod (), handlerMethod . getReturnType (). getParameterType (), apiResponses , methodAttributes , false );
86
86
return apiResponses ;
87
87
}
88
88
@@ -97,7 +97,7 @@ public void buildGenericResponse(Components components, Map<String, Object> find
97
97
if (reqMappringMethod != null ) {
98
98
methodProduces = reqMappringMethod .produces ();
99
99
}
100
- Map <String , ApiResponse > apiResponses = computeResponse (components , method , new ApiResponses (),
100
+ Map <String , ApiResponse > apiResponses = computeResponse (components , method ,null , new ApiResponses (),
101
101
new MethodAttributes (methodProduces , springDocConfigProperties .getDefaultConsumesMediaType (), springDocConfigProperties .getDefaultProducesMediaType ()), true );
102
102
apiResponses .forEach (genericMapResponse ::put );
103
103
}
@@ -118,7 +118,7 @@ private List<Method> getMethods(Map<String, Object> findControllerAdvice) {
118
118
return methods ;
119
119
}
120
120
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 ,
122
122
MethodAttributes methodAttributes , boolean isGeneric ) {
123
123
// Parsing documentation, if present
124
124
Set <io .swagger .v3 .oas .annotations .responses .ApiResponse > responsesArray = getApiResponses (method );
@@ -146,7 +146,7 @@ private Map<String, ApiResponse> computeResponse(Components components, Method m
146
146
apiResponsesOp .addApiResponse (apiResponseAnnotations .responseCode (), apiResponse );
147
147
}
148
148
}
149
- buildApiResponses (components , method , apiResponsesOp , methodAttributes , isGeneric );
149
+ buildApiResponses (components , method , clazz , apiResponsesOp , methodAttributes , isGeneric );
150
150
return apiResponsesOp ;
151
151
}
152
152
@@ -174,14 +174,14 @@ private void buildContentFromDoc(Components components, ApiResponses apiResponse
174
174
}
175
175
}
176
176
177
- private void buildApiResponses (Components components , Method method , ApiResponses apiResponsesOp ,
177
+ private void buildApiResponses (Components components , Method method , Class <?> clazz , ApiResponses apiResponsesOp ,
178
178
MethodAttributes methodAttributes , boolean isGeneric ) {
179
179
if (!CollectionUtils .isEmpty (apiResponsesOp ) && (apiResponsesOp .size () != genericMapResponse .size () || isGeneric )) {
180
180
// API Responses at operation and @ApiResponse annotation
181
181
for (Map .Entry <String , ApiResponse > entry : apiResponsesOp .entrySet ()) {
182
182
String httpCode = entry .getKey ();
183
183
ApiResponse apiResponse = entry .getValue ();
184
- buildApiResponses (components , method , apiResponsesOp , methodAttributes , httpCode , apiResponse ,
184
+ buildApiResponses (components , method , clazz , apiResponsesOp , methodAttributes , httpCode , apiResponse ,
185
185
isGeneric );
186
186
}
187
187
}
@@ -192,7 +192,7 @@ private void buildApiResponses(Components components, Method method, ApiResponse
192
192
ApiResponse apiResponse = genericMapResponse .containsKey (httpCode ) ? genericMapResponse .get (httpCode )
193
193
: new ApiResponse ();
194
194
if (httpCode != null )
195
- buildApiResponses (components , method , apiResponsesOp , methodAttributes , httpCode , apiResponse ,
195
+ buildApiResponses (components , method , clazz , apiResponsesOp , methodAttributes , httpCode , apiResponse ,
196
196
isGeneric );
197
197
}
198
198
}
@@ -222,9 +222,9 @@ private Set<io.swagger.v3.oas.annotations.responses.ApiResponse> getApiResponses
222
222
return responses ;
223
223
}
224
224
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 ) {
226
226
Content content = new Content ();
227
- Type returnType = getReturnType (method );
227
+ Type returnType = getReturnType (method , clazz );
228
228
if (isVoid (returnType )) {
229
229
// if void, no content
230
230
content = null ;
@@ -241,11 +241,11 @@ else if (ArrayUtils.isNotEmpty(methodProduces)) {
241
241
return content ;
242
242
}
243
243
244
- private Type getReturnType (Method method ) {
244
+ private Type getReturnType (Method method , Class <?> clazz ) {
245
245
Type returnType = Object .class ;
246
246
for (ReturnTypeParser returnTypeParser : returnTypeParsers ) {
247
247
if (returnType .getTypeName ().equals (Object .class .getTypeName ())) {
248
- returnType = returnTypeParser .getReturnType (method );
248
+ returnType = returnTypeParser .getReturnType (method , clazz );
249
249
}
250
250
else {
251
251
break ;
@@ -272,12 +272,12 @@ private void setContent(String[] methodProduces, Content content,
272
272
Arrays .stream (methodProduces ).forEach (mediaTypeStr -> content .addMediaType (mediaTypeStr , mediaType ));
273
273
}
274
274
275
- private void buildApiResponses (Components components , Method method , ApiResponses apiResponsesOp ,
275
+ private void buildApiResponses (Components components , Method method , Class <?> clazz , ApiResponses apiResponsesOp ,
276
276
MethodAttributes methodAttributes , String httpCode , ApiResponse apiResponse , boolean isGeneric ) {
277
277
// No documentation
278
278
if (StringUtils .isBlank (apiResponse .get$ref ())) {
279
279
if (apiResponse .getContent () == null ) {
280
- Content content = buildContent (components , method , methodAttributes .getMethodProduces (),
280
+ Content content = buildContent (components , method ,clazz , methodAttributes .getMethodProduces (),
281
281
methodAttributes .getJsonViewAnnotation ());
282
282
apiResponse .setContent (content );
283
283
}
0 commit comments