Skip to content

Commit e072391

Browse files
author
springdoc
committed
fixes #90
1 parent 41cd495 commit e072391

File tree

5 files changed

+85
-12
lines changed

5 files changed

+85
-12
lines changed

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

+9-12
Original file line numberDiff line numberDiff line change
@@ -86,14 +86,10 @@ public void buildGenericResponse(Components components, Map<String, Object> find
8686

8787
protected Schema calculateSchemaParameterizedType(Components components, ParameterizedType parameterizedType) {
8888
Schema schemaN = null;
89-
if (parameterizedType.getActualTypeArguments()[0] instanceof Class
90-
&& !Void.class.equals(parameterizedType.getActualTypeArguments()[0])) {
89+
Type type = parameterizedType.getActualTypeArguments()[0];
90+
if ((type instanceof Class || type instanceof ParameterizedType) && !Void.class.equals(type)) {
9191
schemaN = calculateSchema(components, parameterizedType);
92-
} else if (parameterizedType.getActualTypeArguments()[0] instanceof ParameterizedType
93-
&& !Void.class.equals(parameterizedType.getActualTypeArguments()[0])) {
94-
parameterizedType = (ParameterizedType) parameterizedType.getActualTypeArguments()[0];
95-
schemaN = SpringDocAnnotationsUtils.extractSchema(components, parameterizedType);
96-
} else if (Void.class.equals(parameterizedType.getActualTypeArguments()[0])) {
92+
} else if (Void.class.equals(type)) {
9793
// if void, no content
9894
schemaN = AnnotationsUtils.resolveSchemaFromType(String.class, null, null);
9995
}
@@ -127,9 +123,11 @@ private Map<String, ApiResponse> computeResponse(Components components, Method m
127123
ApiResponse apiResponse1 = new ApiResponse();
128124
apiResponse1.setDescription(apiResponse2.description());
129125
io.swagger.v3.oas.annotations.media.Content[] contentdoc = apiResponse2.content();
130-
SpringDocAnnotationsUtils.getContent(contentdoc, new String[0],
131-
methodAttributes.getAllProduces() == null ? new String[0] : methodAttributes.getAllProduces(),
132-
null, components, null)
126+
SpringDocAnnotationsUtils
127+
.getContent(contentdoc, new String[0],
128+
methodAttributes.getAllProduces() == null ? new String[0]
129+
: methodAttributes.getAllProduces(),
130+
null, components, null)
133131
.ifPresent(apiResponse1::content);
134132
AnnotationsUtils.getHeaders(apiResponse2.headers(), null).ifPresent(apiResponse1::headers);
135133
apiResponsesOp.addApiResponse(apiResponse2.responseCode(), apiResponse1);
@@ -221,8 +219,7 @@ private void setContent(String[] methodProduces, Content content,
221219

222220
private Schema calculateSchema(Components components, ParameterizedType parameterizedType) {
223221
Schema schemaN;
224-
schemaN = AnnotationsUtils.resolveSchemaFromType((Class<?>) parameterizedType.getActualTypeArguments()[0], null,
225-
null);
222+
schemaN = SpringDocAnnotationsUtils.extractSchema(components, parameterizedType.getActualTypeArguments()[0]);
226223
if (schemaN.getType() == null) {
227224
schemaN = SpringDocAnnotationsUtils.extractSchema(components,
228225
parameterizedType.getActualTypeArguments()[0]);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package test.org.springdoc.api.app38;
2+
3+
import org.springframework.http.HttpStatus;
4+
import org.springframework.http.ResponseEntity;
5+
import org.springframework.web.bind.annotation.RequestMapping;
6+
import org.springframework.web.bind.annotation.RequestMethod;
7+
import org.springframework.web.bind.annotation.RestController;
8+
9+
@RestController("/api")
10+
public class HelloController {
11+
12+
@RequestMapping(value = "/npe_error", method = RequestMethod.GET)
13+
public ResponseEntity<byte[]> getModelResource() {
14+
return new ResponseEntity<>(new byte[0], HttpStatus.OK);
15+
}
16+
17+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package test.org.springdoc.api.app38;
2+
3+
import test.org.springdoc.api.AbstractSpringDocTest;
4+
5+
public class SpringDocApp38Test extends AbstractSpringDocTest {
6+
7+
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package test.org.springdoc.api.app38;
2+
3+
import org.springframework.boot.SpringApplication;
4+
import org.springframework.boot.autoconfigure.SpringBootApplication;
5+
6+
@SpringBootApplication
7+
public class SpringDocTestApp {
8+
9+
public static void main(String[] args) {
10+
SpringApplication.run(SpringDocTestApp.class, args);
11+
}
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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+
"/npe_error":{
15+
"get":{
16+
"operationId":"getModelResource",
17+
"responses":{
18+
"200":{
19+
"description":"default response",
20+
"content":{
21+
"*/*":{
22+
"schema":{
23+
"type":"array",
24+
"items":{
25+
"type":"string",
26+
"format":"byte"
27+
}
28+
}
29+
}
30+
}
31+
}
32+
}
33+
}
34+
}
35+
},
36+
"components":{
37+
38+
}
39+
}

0 commit comments

Comments
 (0)