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
}

0 commit comments

Comments
 (0)