Skip to content

Commit c56df04

Browse files
authored
Merge pull request #1500 from eshishkin/master
Pick up exception handler in case there is no controller advice at alll, fixes 1498
2 parents d875d5d + ec7e1a0 commit c56df04

File tree

4 files changed

+157
-1
lines changed

4 files changed

+157
-1
lines changed

springdoc-openapi-common/src/main/java/org/springdoc/api/AbstractOpenApiResource.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ protected synchronized OpenAPI getOpenApi(Locale locale) {
324324
Map<String, Object> findControllerAdvice = openAPIService.getControllerAdviceMap();
325325
// calculate generic responses
326326
openApi = openAPIService.getCalculatedOpenAPI();
327-
if (springDocConfigProperties.isOverrideWithGenericResponse() && !CollectionUtils.isEmpty(findControllerAdvice)) {
327+
if (springDocConfigProperties.isOverrideWithGenericResponse()) {
328328
if (!CollectionUtils.isEmpty(mappingsMap))
329329
findControllerAdvice.putAll(mappingsMap);
330330
responseBuilder.buildGenericResponse(openApi.getComponents(), findControllerAdvice, finalLocale);
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
*
3+
* * Copyright 2019-2020 the original author or authors.
4+
* *
5+
* * Licensed under the Apache License, Version 2.0 (the "License");
6+
* * you may not use this file except in compliance with the License.
7+
* * You may obtain a copy of the License at
8+
* *
9+
* * https://www.apache.org/licenses/LICENSE-2.0
10+
* *
11+
* * Unless required by applicable law or agreed to in writing, software
12+
* * distributed under the License is distributed on an "AS IS" BASIS,
13+
* * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* * See the License for the specific language governing permissions and
15+
* * limitations under the License.
16+
*
17+
*/
18+
19+
package test.org.springdoc.api.app182;
20+
21+
import io.swagger.v3.oas.annotations.Operation;
22+
import io.swagger.v3.oas.annotations.media.Content;
23+
import io.swagger.v3.oas.annotations.responses.ApiResponse;
24+
import org.springdoc.api.annotations.ParameterObject;
25+
import org.springframework.http.HttpStatus;
26+
import org.springframework.http.ResponseEntity;
27+
import org.springframework.web.bind.annotation.ExceptionHandler;
28+
import org.springframework.web.bind.annotation.GetMapping;
29+
import org.springframework.web.bind.annotation.PathVariable;
30+
import org.springframework.web.bind.annotation.ResponseStatus;
31+
import org.springframework.web.bind.annotation.RestController;
32+
import test.org.springdoc.api.app181.ConcreteParameterObject;
33+
34+
@RestController
35+
public class HelloController<T> {
36+
37+
@ExceptionHandler(IllegalArgumentException.class)
38+
@ApiResponse(responseCode = "404", description = "Not here", content = @Content)
39+
@ResponseStatus(HttpStatus.NOT_FOUND)
40+
public void bad(IllegalArgumentException e) {
41+
42+
}
43+
44+
@ExceptionHandler(RuntimeException.class)
45+
@ResponseStatus(HttpStatus.BAD_GATEWAY)
46+
public Object gateway(RuntimeException e) {
47+
return null;
48+
}
49+
50+
@GetMapping(value = "/hello/{numTelco}")
51+
@Operation(summary = "GET Persons", responses = @ApiResponse(responseCode = "418"))
52+
public T index(@PathVariable("numTelco") String numTel, String adresse) {
53+
throw new IllegalArgumentException();
54+
55+
}
56+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
*
3+
* * Copyright 2019-2020 the original author or authors.
4+
* *
5+
* * Licensed under the Apache License, Version 2.0 (the "License");
6+
* * you may not use this file except in compliance with the License.
7+
* * You may obtain a copy of the License at
8+
* *
9+
* * https://www.apache.org/licenses/LICENSE-2.0
10+
* *
11+
* * Unless required by applicable law or agreed to in writing, software
12+
* * distributed under the License is distributed on an "AS IS" BASIS,
13+
* * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* * See the License for the specific language governing permissions and
15+
* * limitations under the License.
16+
*
17+
*/
18+
19+
package test.org.springdoc.api.app182;
20+
21+
import org.springframework.boot.autoconfigure.SpringBootApplication;
22+
import test.org.springdoc.api.AbstractSpringDocTest;
23+
24+
25+
/**
26+
* Copy of 124 without RestControllerAdvice class
27+
*/
28+
public class SpringDocApp182Test extends AbstractSpringDocTest {
29+
30+
@SpringBootApplication
31+
static class SpringDocTestApp {}
32+
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
{
2+
"openapi": "3.0.1",
3+
"info": {
4+
"title": "OpenAPI definition",
5+
"version": "v0"
6+
},
7+
"servers": [
8+
{
9+
"url": "http://localhost",
10+
"description": "Generated server url"
11+
}
12+
],
13+
"paths": {
14+
"/hello/{numTelco}": {
15+
"get": {
16+
"tags": [
17+
"hello-controller"
18+
],
19+
"summary": "GET Persons",
20+
"operationId": "index",
21+
"parameters": [
22+
{
23+
"name": "numTelco",
24+
"in": "path",
25+
"required": true,
26+
"schema": {
27+
"type": "string"
28+
}
29+
},
30+
{
31+
"name": "adresse",
32+
"in": "query",
33+
"required": true,
34+
"schema": {
35+
"type": "string"
36+
}
37+
}
38+
],
39+
"responses": {
40+
"502": {
41+
"description": "Bad Gateway",
42+
"content": {
43+
"*/*": {
44+
"schema": {
45+
"type": "object"
46+
}
47+
}
48+
}
49+
},
50+
"404": {
51+
"description": "Not here"
52+
},
53+
"418": {
54+
"description": "I'm a teapot",
55+
"content": {
56+
"*/*": {
57+
"schema": {
58+
"type": "object"
59+
}
60+
}
61+
}
62+
}
63+
}
64+
}
65+
}
66+
},
67+
"components": {}
68+
}

0 commit comments

Comments
 (0)