Skip to content

Commit e55d25d

Browse files
committed
fix loop when response inherits generic class fixes #2271, #2280
1 parent 7c8dd16 commit e55d25d

File tree

7 files changed

+168
-2
lines changed

7 files changed

+168
-2
lines changed

springdoc-openapi-starter-common/src/main/java/org/springdoc/core/parsers/ReturnTypeParser.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import java.lang.reflect.ParameterizedType;
2828
import java.lang.reflect.Type;
2929
import java.lang.reflect.TypeVariable;
30+
import java.util.Arrays;
3031
import java.util.Objects;
3132

3233
import org.springframework.core.MethodParameter;
@@ -92,7 +93,8 @@ static void resolveType(ResolvableType[] resolvableTypes, Class<?> contextClass)
9293
resolvableTypes[i] = resolvableType;
9394
}
9495
else if (resolvableTypes[i].hasGenerics()) {
95-
resolveType(resolvableTypes[i].getGenerics(), contextClass);
96+
if(!Arrays.equals(resolvableTypes[i].getGenerics(), resolvableTypes))
97+
resolveType(resolvableTypes[i].getGenerics(), contextClass);
9698
if (resolvableTypes[i].getRawClass() != null)
9799
resolvableTypes[i] = ResolvableType.forClassWithGenerics(Objects.requireNonNull(resolvableTypes[i].getRawClass()), resolvableTypes[i].getGenerics());
98100
}
@@ -201,4 +203,4 @@ default Type getReturnType(MethodParameter methodParameter) {
201203
return methodParameter.getParameterType();
202204
}
203205

204-
}
206+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package test.org.springdoc.api.v30.app207;
2+
3+
import test.org.springdoc.api.v30.AbstractSpringDocV30Test;
4+
5+
import org.springframework.boot.autoconfigure.SpringBootApplication;
6+
7+
public class SpringdocApp207Test extends AbstractSpringDocV30Test {
8+
9+
@SpringBootApplication
10+
static class SpringDocTestApp {}
11+
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package test.org.springdoc.api.v30.app207.controller;
2+
3+
import java.util.ArrayList;
4+
import java.util.List;
5+
6+
import test.org.springdoc.api.v30.app207.model.SuperEntity;
7+
8+
import org.springframework.web.bind.annotation.GetMapping;
9+
import org.springframework.web.bind.annotation.PathVariable;
10+
import org.springframework.web.bind.annotation.RequestParam;
11+
12+
public abstract class SuperController<T extends SuperEntity<T>> {
13+
14+
@GetMapping({"page/{current}/{size}", "page"})
15+
public List<? extends T> findPage(@PathVariable(required = false) Long current,
16+
@PathVariable(required = false) Long size,
17+
@RequestParam(required = false) T params) {
18+
return new ArrayList<>();
19+
}
20+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package test.org.springdoc.api.v30.app207.controller;
2+
3+
4+
import test.org.springdoc.api.v30.app207.model.SysUser;
5+
6+
import org.springframework.web.bind.annotation.RequestMapping;
7+
import org.springframework.web.bind.annotation.RestController;
8+
9+
@RestController
10+
@RequestMapping("/api/sysUser")
11+
public class SysUserController extends SuperController<SysUser> {
12+
13+
14+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package test.org.springdoc.api.v30.app207.model;
2+
3+
public class SuperEntity<T> {
4+
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package test.org.springdoc.api.v30.app207.model;
2+
3+
public class SysUser extends SuperEntity<SysUser> {
4+
}
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
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+
"/api/sysUser/page/{current}/{size}": {
15+
"get": {
16+
"tags": [
17+
"sys-user-controller"
18+
],
19+
"operationId": "findPage",
20+
"parameters": [
21+
{
22+
"name": "current",
23+
"in": "path",
24+
"required": true,
25+
"schema": {
26+
"type": "integer",
27+
"format": "int64"
28+
}
29+
},
30+
{
31+
"name": "size",
32+
"in": "path",
33+
"required": true,
34+
"schema": {
35+
"type": "integer",
36+
"format": "int64"
37+
}
38+
},
39+
{
40+
"name": "params",
41+
"in": "query",
42+
"required": false,
43+
"schema": {
44+
"$ref": "#/components/schemas/SysUser"
45+
}
46+
}
47+
],
48+
"responses": {
49+
"200": {
50+
"description": "OK",
51+
"content": {
52+
"*/*": {
53+
"schema": {
54+
"type": "array",
55+
"items": {
56+
"$ref": "#/components/schemas/SuperEntityObject"
57+
}
58+
}
59+
}
60+
}
61+
}
62+
}
63+
}
64+
},
65+
"/api/sysUser/page": {
66+
"get": {
67+
"tags": [
68+
"sys-user-controller"
69+
],
70+
"operationId": "findPage_1",
71+
"parameters": [
72+
{
73+
"name": "params",
74+
"in": "query",
75+
"required": false,
76+
"schema": {
77+
"$ref": "#/components/schemas/SysUser"
78+
}
79+
}
80+
],
81+
"responses": {
82+
"200": {
83+
"description": "OK",
84+
"content": {
85+
"*/*": {
86+
"schema": {
87+
"type": "array",
88+
"items": {
89+
"$ref": "#/components/schemas/SuperEntityObject"
90+
}
91+
}
92+
}
93+
}
94+
}
95+
}
96+
}
97+
}
98+
},
99+
"components": {
100+
"schemas": {
101+
"SysUser": {
102+
"type": "object"
103+
},
104+
"SuperEntityObject": {
105+
"type": "object"
106+
}
107+
}
108+
}
109+
}

0 commit comments

Comments
 (0)