Skip to content

Commit 7278ffe

Browse files
author
bnasslahsen
committed
JsonMappingException on UI render. Fixes #630
1 parent 3dd6a59 commit 7278ffe

File tree

5 files changed

+105
-2
lines changed

5 files changed

+105
-2
lines changed

springdoc-openapi-common/src/main/java/org/springdoc/core/GenericResponseBuilder.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,8 +195,9 @@ private void buildApiResponses(Components components, MethodParameter methodPara
195195
String httpCode = evaluateResponseStatus(methodParameter.getMethod(), methodParameter.getMethod().getClass(), isGeneric);
196196
ApiResponse apiResponse = methodAttributes.getGenericMapResponse().containsKey(httpCode) ? methodAttributes.getGenericMapResponse().get(httpCode)
197197
: new ApiResponse();
198-
buildApiResponses(components, methodParameter, apiResponsesOp, methodAttributes, httpCode, apiResponse,
199-
isGeneric);
198+
if (httpCode != null)
199+
buildApiResponses(components, methodParameter, apiResponsesOp, methodAttributes, httpCode, apiResponse,
200+
isGeneric);
200201
}
201202
}
202203

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package test.org.springdoc.api.app116;
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+
8+
@ControllerAdvice(assignableTypes = HelloController.class)
9+
public class FooErrorHandler {
10+
11+
@ExceptionHandler
12+
public ResponseEntity<String> storeAssignmentPublishingError(Exception e) {
13+
return new ResponseEntity<>("foo", HttpStatus.INTERNAL_SERVER_ERROR);
14+
}
15+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package test.org.springdoc.api.app116;
2+
3+
import io.swagger.v3.oas.annotations.OpenAPIDefinition;
4+
import io.swagger.v3.oas.annotations.info.Info;
5+
import io.swagger.v3.oas.annotations.tags.Tag;
6+
7+
import org.springframework.web.bind.annotation.PostMapping;
8+
import org.springframework.web.bind.annotation.RequestBody;
9+
import org.springframework.web.bind.annotation.RequestMapping;
10+
import org.springframework.web.bind.annotation.RestController;
11+
12+
@RestController
13+
@RequestMapping("/api")
14+
@OpenAPIDefinition(info = @Info(title = "API Examples", version = "1.0"), tags = @Tag(name = "Operations"))
15+
public class HelloController {
16+
17+
@PostMapping("/foo")
18+
public String create(@RequestBody String foo) {
19+
return "foo";
20+
}
21+
}
22+
23+
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package test.org.springdoc.api.app116;
2+
3+
import test.org.springdoc.api.AbstractSpringDocTest;
4+
5+
import org.springframework.boot.autoconfigure.SpringBootApplication;
6+
7+
8+
public class SpringDocApp116Test extends AbstractSpringDocTest {
9+
10+
@SpringBootApplication
11+
static class SpringDocTestApp {}
12+
13+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
{
2+
"openapi": "3.0.1",
3+
"info": {
4+
"title": "API Examples",
5+
"version": "1.0"
6+
},
7+
"servers": [
8+
{
9+
"url": "http://localhost",
10+
"description": "Generated server url"
11+
}
12+
],
13+
"tags": [
14+
{
15+
"name": "Operations"
16+
}
17+
],
18+
"paths": {
19+
"/api/foo": {
20+
"post": {
21+
"tags": [
22+
"hello-controller"
23+
],
24+
"operationId": "create",
25+
"requestBody": {
26+
"content": {
27+
"application/json": {
28+
"schema": {
29+
"type": "string"
30+
}
31+
}
32+
},
33+
"required": true
34+
},
35+
"responses": {
36+
"200": {
37+
"description": "OK",
38+
"content": {
39+
"*/*": {
40+
"schema": {
41+
"type": "string"
42+
}
43+
}
44+
}
45+
}
46+
}
47+
}
48+
}
49+
},
50+
"components": {}
51+
}

0 commit comments

Comments
 (0)