Skip to content

Commit f34b9be

Browse files
committed
Changes report #1791
1 parent 3dce0c4 commit f34b9be

File tree

19 files changed

+439
-121
lines changed

19 files changed

+439
-121
lines changed

springdoc-openapi-starter-common/src/main/java/org/springdoc/core/service/GenericResponseService.java

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -177,30 +177,25 @@ public ApiResponses build(Components components, HandlerMethod handlerMethod, Op
177177
* @return the filtered and enriched responses
178178
*/
179179
private Map<String, ApiResponse> filterAndEnrichGenericMapResponseByDeclarations(HandlerMethod handlerMethod, Map<String, ApiResponse> genericMapResponse) {
180-
Map<String, ApiResponse> result = new HashMap<>();
181-
for (Map.Entry<String, ApiResponse> genericResponse : genericMapResponse.entrySet()) {
182-
Map<String, Object> extensions = genericResponse.getValue().getExtensions();
183-
Set<Class<?>> genericExceptions = (Set<Class<?>>) extensions.get(EXTENSION_EXCEPTION_CLASSES);
184-
for (Class<?> declaredException : handlerMethod.getMethod().getExceptionTypes()) {
185-
if (genericExceptions.contains(declaredException)) {
186-
ApiResponse clone = cloneApiResponse(genericResponse.getValue());
187-
clone.getExtensions().remove(EXTENSION_EXCEPTION_CLASSES);
188-
if (operationService.getJavadocProvider() != null) {
189-
JavadocProvider javadocProvider = operationService.getJavadocProvider();
180+
if (operationService.getJavadocProvider() != null) {
181+
JavadocProvider javadocProvider = operationService.getJavadocProvider();
182+
for (Map.Entry<String, ApiResponse> genericResponse : genericMapResponse.entrySet()) {
183+
Map<String, Object> extensions = genericResponse.getValue().getExtensions();
184+
Set<Class<?>> genericExceptions = (Set<Class<?>>) extensions.get(EXTENSION_EXCEPTION_CLASSES);
185+
for (Class<?> declaredException : handlerMethod.getMethod().getExceptionTypes()) {
186+
if (genericExceptions.contains(declaredException)) {
190187
Map<String, String> javadocThrows = javadocProvider.getMethodJavadocThrows(handlerMethod.getMethod());
191188
String description = javadocThrows.get(declaredException.getName());
192-
if (description == null) {
189+
if (description == null)
193190
description = javadocThrows.get(declaredException.getSimpleName());
194-
}
195191
if (description != null && !description.trim().isEmpty()) {
196-
clone.setDescription(description);
192+
genericResponse.getValue().setDescription(description);
197193
}
198194
}
199-
result.put(genericResponse.getKey(), clone);
200195
}
201196
}
202197
}
203-
return result;
198+
return genericMapResponse;
204199
}
205200

206201
/**

springdoc-openapi-tests/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<parent>
55
<artifactId>springdoc-openapi</artifactId>
66
<groupId>org.springdoc</groupId>
7-
<version>2.0.0-M4-SNAPSHOT</version>
7+
<version>2.0.0-M5-SNAPSHOT</version>
88
</parent>
99
<packaging>pom</packaging>
1010
<modelVersion>4.0.0</modelVersion>

springdoc-openapi-tests/springdoc-openapi-actuator-webflux-tests/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<parent>
55
<artifactId>springdoc-openapi-tests</artifactId>
66
<groupId>org.springdoc</groupId>
7-
<version>2.0.0-M4-SNAPSHOT</version>
7+
<version>2.0.0-M5-SNAPSHOT</version>
88
</parent>
99
<modelVersion>4.0.0</modelVersion>
1010

springdoc-openapi-tests/springdoc-openapi-actuator-webmvc-tests/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<parent>
55
<artifactId>springdoc-openapi-tests</artifactId>
66
<groupId>org.springdoc</groupId>
7-
<version>2.0.0-M4-SNAPSHOT</version>
7+
<version>2.0.0-M5-SNAPSHOT</version>
88
</parent>
99
<modelVersion>4.0.0</modelVersion>
1010

springdoc-openapi-tests/springdoc-openapi-data-rest-tests/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<parent>
55
<artifactId>springdoc-openapi-tests</artifactId>
66
<groupId>org.springdoc</groupId>
7-
<version>2.0.0-M4-SNAPSHOT</version>
7+
<version>2.0.0-M5-SNAPSHOT</version>
88
</parent>
99
<modelVersion>4.0.0</modelVersion>
1010
<artifactId>springdoc-openapi-data-rest-tests</artifactId>

springdoc-openapi-tests/springdoc-openapi-function-webflux-tests/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<parent>
55
<artifactId>springdoc-openapi-tests</artifactId>
66
<groupId>org.springdoc</groupId>
7-
<version>2.0.0-M4-SNAPSHOT</version>
7+
<version>2.0.0-M5-SNAPSHOT</version>
88
</parent>
99
<modelVersion>4.0.0</modelVersion>
1010

springdoc-openapi-tests/springdoc-openapi-function-webmvc-tests/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<parent>
55
<artifactId>springdoc-openapi-tests</artifactId>
66
<groupId>org.springdoc</groupId>
7-
<version>2.0.0-M4-SNAPSHOT</version>
7+
<version>2.0.0-M5-SNAPSHOT</version>
88
</parent>
99
<modelVersion>4.0.0</modelVersion>
1010

springdoc-openapi-tests/springdoc-openapi-groovy-tests/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<parent>
44
<groupId>org.springdoc</groupId>
55
<artifactId>springdoc-openapi-tests</artifactId>
6-
<version>2.0.0-M4-SNAPSHOT</version>
6+
<version>2.0.0-M5-SNAPSHOT</version>
77
</parent>
88
<artifactId>springdoc-openapi-groovy-tests</artifactId>
99
<dependencies>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package test.org.springdoc.api.app191;
2+
3+
import org.springframework.http.HttpStatus;
4+
import org.springframework.http.ResponseEntity;
5+
import org.springframework.web.bind.annotation.ControllerAdvice;
6+
import org.springframework.web.bind.annotation.ExceptionHandler;
7+
import org.springframework.web.bind.annotation.ResponseStatus;
8+
9+
10+
@ControllerAdvice
11+
class GlobalExceptionHandler {
12+
13+
@ResponseStatus(code = HttpStatus.FORBIDDEN)
14+
@ExceptionHandler(MyException.class)
15+
public ResponseEntity<String> handleException(MyException myException) {
16+
return ResponseEntity.status(HttpStatus.FORBIDDEN)
17+
.body(myException.getMessage());
18+
}
19+
}

springdoc-openapi-tests/springdoc-openapi-groovy-tests/src/test/groovy/test/org/springdoc/api/app191/HelloController.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,19 @@
2424

2525
import java.util.List;
2626

27+
import io.swagger.v3.oas.annotations.Operation;
2728
import org.springdoc.core.annotations.ParameterObject;
2829

2930
import org.springframework.data.domain.Pageable;
3031
import org.springframework.data.domain.Sort;
3132
import org.springframework.data.domain.Sort.Direction;
3233
import org.springframework.data.web.SortDefault;
34+
import org.springframework.http.HttpStatus;
35+
import org.springframework.http.MediaType;
3336
import org.springframework.http.ResponseEntity;
37+
import org.springframework.web.bind.annotation.ExceptionHandler;
3438
import org.springframework.web.bind.annotation.GetMapping;
39+
import org.springframework.web.bind.annotation.ResponseStatus;
3540
import org.springframework.web.bind.annotation.RestController;
3641

3742
@RestController
@@ -70,4 +75,20 @@ public String getPatientList4(@SortDefault(sort = "someField",
7075
@ParameterObject Pageable pageable) {
7176
return "bla";
7277
}
78+
79+
@GetMapping(value = "/hello", produces = MediaType.TEXT_PLAIN_VALUE)
80+
@Operation(summary = "Says hello")
81+
public ResponseEntity<String> getHello() {
82+
return ResponseEntity
83+
.status(HttpStatus.OK)
84+
.body("Hello!");
85+
}
86+
87+
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
88+
@ExceptionHandler(RuntimeException.class)
89+
public ResponseEntity<String> handleException(RuntimeException runtimeException) {
90+
return ResponseEntity
91+
.status(HttpStatus.INTERNAL_SERVER_ERROR)
92+
.body(runtimeException.getMessage());
93+
}
7394
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package test.org.springdoc.api.app191;
2+
3+
public class MyException extends RuntimeException {
4+
public MyException(String message){
5+
super(message);
6+
}
7+
}

springdoc-openapi-tests/springdoc-openapi-groovy-tests/src/test/resources/results/app191.json

Lines changed: 142 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,26 @@
5757
}
5858
],
5959
"responses": {
60+
"403": {
61+
"description": "Forbidden",
62+
"content": {
63+
"*/*": {
64+
"schema": {
65+
"type": "string"
66+
}
67+
}
68+
}
69+
},
70+
"500": {
71+
"description": "Internal Server Error",
72+
"content": {
73+
"*/*": {
74+
"schema": {
75+
"type": "string"
76+
}
77+
}
78+
}
79+
},
6080
"200": {
6181
"description": "OK",
6282
"content": {
@@ -117,6 +137,26 @@
117137
}
118138
],
119139
"responses": {
140+
"403": {
141+
"description": "Forbidden",
142+
"content": {
143+
"*/*": {
144+
"schema": {
145+
"type": "string"
146+
}
147+
}
148+
}
149+
},
150+
"500": {
151+
"description": "Internal Server Error",
152+
"content": {
153+
"*/*": {
154+
"schema": {
155+
"type": "string"
156+
}
157+
}
158+
}
159+
},
120160
"200": {
121161
"description": "OK",
122162
"content": {
@@ -154,6 +194,26 @@
154194
}
155195
],
156196
"responses": {
197+
"403": {
198+
"description": "Forbidden",
199+
"content": {
200+
"*/*": {
201+
"schema": {
202+
"type": "string"
203+
}
204+
}
205+
}
206+
},
207+
"500": {
208+
"description": "Internal Server Error",
209+
"content": {
210+
"*/*": {
211+
"schema": {
212+
"type": "string"
213+
}
214+
}
215+
}
216+
},
157217
"200": {
158218
"description": "OK",
159219
"content": {
@@ -192,6 +252,26 @@
192252
}
193253
],
194254
"responses": {
255+
"403": {
256+
"description": "Forbidden",
257+
"content": {
258+
"*/*": {
259+
"schema": {
260+
"type": "string"
261+
}
262+
}
263+
}
264+
},
265+
"500": {
266+
"description": "Internal Server Error",
267+
"content": {
268+
"*/*": {
269+
"schema": {
270+
"type": "string"
271+
}
272+
}
273+
}
274+
},
195275
"200": {
196276
"description": "OK",
197277
"content": {
@@ -229,6 +309,26 @@
229309
}
230310
],
231311
"responses": {
312+
"403": {
313+
"description": "Forbidden",
314+
"content": {
315+
"*/*": {
316+
"schema": {
317+
"type": "string"
318+
}
319+
}
320+
}
321+
},
322+
"500": {
323+
"description": "Internal Server Error",
324+
"content": {
325+
"*/*": {
326+
"schema": {
327+
"type": "string"
328+
}
329+
}
330+
}
331+
},
232332
"200": {
233333
"description": "OK",
234334
"content": {
@@ -252,6 +352,47 @@
252352
}
253353
}
254354
}
355+
},
356+
"/hello": {
357+
"get": {
358+
"tags": [
359+
"hello-controller"
360+
],
361+
"summary": "Says hello",
362+
"operationId": "getHello",
363+
"responses": {
364+
"403": {
365+
"description": "Forbidden",
366+
"content": {
367+
"*/*": {
368+
"schema": {
369+
"type": "string"
370+
}
371+
}
372+
}
373+
},
374+
"500": {
375+
"description": "Internal Server Error",
376+
"content": {
377+
"*/*": {
378+
"schema": {
379+
"type": "string"
380+
}
381+
}
382+
}
383+
},
384+
"200": {
385+
"description": "OK",
386+
"content": {
387+
"text/plain": {
388+
"schema": {
389+
"type": "string"
390+
}
391+
}
392+
}
393+
}
394+
}
395+
}
255396
}
256397
},
257398
"components": {
@@ -272,4 +413,4 @@
272413
}
273414
}
274415
}
275-
}
416+
}

springdoc-openapi-tests/springdoc-openapi-hateoas-tests/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<parent>
55
<artifactId>springdoc-openapi-tests</artifactId>
66
<groupId>org.springdoc</groupId>
7-
<version>2.0.0-M4-SNAPSHOT</version>
7+
<version>2.0.0-M5-SNAPSHOT</version>
88
</parent>
99
<modelVersion>4.0.0</modelVersion>
1010
<artifactId>springdoc-openapi-hateoas-tests</artifactId>

springdoc-openapi-tests/springdoc-openapi-javadoc-tests/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<parent>
33
<groupId>org.springdoc</groupId>
44
<artifactId>springdoc-openapi-tests</artifactId>
5-
<version>2.0.0-M4-SNAPSHOT</version>
5+
<version>2.0.0-M5-SNAPSHOT</version>
66
</parent>
77
<modelVersion>4.0.0</modelVersion>
88

0 commit comments

Comments
 (0)