Skip to content

Commit 805b679

Browse files
committed
新增测试用例
1 parent 6e9cae0 commit 805b679

File tree

6 files changed

+154
-38
lines changed

6 files changed

+154
-38
lines changed

apidoc-core/src/main/java/com/ztianzeng/apidoc/ModelResolver.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -216,16 +216,15 @@ public void setRefType(JavaClass type, Schema schema, AnnotatedType annotatedTyp
216216
List<JavaType> ref = ((DefaultJavaParameterizedType) type).getActualTypeArguments();
217217
if (!ref.isEmpty()) {
218218
for (JavaType actualTypeArgument : ref) {
219-
type = builder.getClassByName(actualTypeArgument.getBinaryName());
220219
AnnotatedType aType = new AnnotatedType()
221-
.javaClass(type)
220+
.javaClass((DefaultJavaParameterizedType) actualTypeArgument)
222221
.parent(schema)
223222
.resolveAsRef(annotatedType.isResolveAsRef())
224223
.jsonViewAnnotation(annotatedType.getJsonViewAnnotation())
225224
.skipSchemaName(true)
226225
.schemaProperty(true)
227226
.propertyName(targetClass.getName());
228-
schema = context.resolve(aType);
227+
context.resolve(aType);
229228
}
230229
}
231230
}

apidoc-core/src/test/java/com/ztianzeng/apidoc/test/ContainerTest.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,25 @@ public void testResult() {
104104
assertEquals(foo.getType(), "string");
105105
final Schema name = innerProps.get("mobile");
106106
assertEquals(name.getType(), "string");
107+
}
108+
109+
@Test
110+
public void testResult2() {
111+
ModelResolver resolver = new ModelResolver(sourceBuilder);
112+
113+
final ModelConverterContextImpl context = new ModelConverterContextImpl(resolver);
114+
JavaClass classByName = TestBase.builder.getClassByName(ResultBean2.class.getName());
115+
context.resolve(new AnnotatedType(classByName));
116+
117+
final Map<String, Schema> models = context.getDefinedModels();
118+
final Schema createParam = models.get("CreateParam");
119+
assertNotNull(createParam);
120+
final Map<String, Schema> innerProps = createParam.getProperties();
121+
assertEquals(innerProps.size(), 2);
122+
final Schema foo = innerProps.get("username");
123+
assertEquals(foo.getType(), "string");
124+
final Schema name = innerProps.get("mobile");
125+
assertEquals(name.getType(), "string");
107126

108127

109128
}
@@ -124,4 +143,8 @@ static class ResultBean {
124143
public Result<CreateParam> result;
125144
}
126145

146+
static class ResultBean2 {
147+
public Result<Result<CreateParam>> result2;
148+
}
149+
127150
}

apidoc-core/src/test/java/com/ztianzeng/apidoc/test/ReaderTest.java

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,57 @@ public void testMoreResponses() {
165165
SerializationMatchers.assertEqualsToYaml(openAPI, yaml);
166166
}
167167

168+
@Test
169+
public void testMuRet() {
170+
Reader reader = new Reader(new OpenAPI());
171+
JavaClass classByName = TestBase.builder.getClassByName(MuRetController.class.getName());
172+
173+
OpenAPI openAPI = reader.read(classByName);
174+
String yaml = "openapi: 3.0.1\n" +
175+
"paths:\n" +
176+
" /get:\n" +
177+
" get:\n" +
178+
" summary: 获取一个实例\n" +
179+
" operationId: get\n" +
180+
" responses:\n" +
181+
" 200:\n" +
182+
" description: 返回信息\n" +
183+
" content:\n" +
184+
" application/json:\n" +
185+
" schema:\n" +
186+
" $ref: '#/components/schemas/Result'\n" +
187+
" deprecated: false\n" +
188+
"components:\n" +
189+
" schemas:\n" +
190+
" CreateParam:\n" +
191+
" required:\n" +
192+
" - username\n" +
193+
" type: object\n" +
194+
" properties:\n" +
195+
" username:\n" +
196+
" type: string\n" +
197+
" description: 用户名\n" +
198+
" mobile:\n" +
199+
" type: string\n" +
200+
" description: 手机\n" +
201+
" Result:\n" +
202+
" type: object\n" +
203+
" properties:\n" +
204+
" msg:\n" +
205+
" type: string\n" +
206+
" data:\n" +
207+
" $ref: '#/components/schemas/Result2'\n" +
208+
" Result2:\n" +
209+
" type: object\n" +
210+
" properties:\n" +
211+
" msg:\n" +
212+
" type: string\n" +
213+
" data:\n" +
214+
" $ref: '#/components/schemas/CreateParam'\n";
215+
216+
SerializationMatchers.assertEqualsToYaml(openAPI, yaml);
217+
}
218+
168219

169220
@Test
170221
public void test2497() {
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package com.ztianzeng.apidoc.test.res;
2+
3+
import org.springframework.web.bind.annotation.GetMapping;
4+
5+
/**
6+
* @author zhaotianzeng
7+
* @version V1.0
8+
* @date 2019-06-12 18:33
9+
*/
10+
public class MuRetController {
11+
/**
12+
* 获取一个实例
13+
*
14+
* @return 返回信息
15+
*/
16+
@GetMapping(value = "/get")
17+
public Result<Result2<CreateParam>> get() {
18+
return new Result<>();
19+
}
20+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package com.ztianzeng.apidoc.test.res;
2+
3+
import lombok.Getter;
4+
5+
/**
6+
* @author zhaotianzeng
7+
* @version V1.0
8+
* @date 2019-06-11 13:13
9+
*/
10+
@Getter
11+
public class Result2<T> {
12+
private String msg;
13+
private T data;
14+
15+
protected Result2() {
16+
}
17+
18+
private Result2(String msg, T t) {
19+
this.msg = msg;
20+
this.data = t;
21+
}
22+
23+
}

apidoc-core/src/test/java/com/ztianzeng/apidoc/test/res/TestController.java

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -18,39 +18,39 @@
1818
public class TestController {
1919

2020

21-
/**
22-
* 新增一个实例
23-
*
24-
* @param createParam 创建对象
25-
* @return 创建后的信息
26-
*/
27-
@PostMapping(value = "/create")
28-
public CreateVO add(@RequestBody @Valid CreateParam createParam) {
29-
return new CreateVO();
30-
}
31-
32-
/**
33-
* 新增一个实例2
34-
*
35-
* @param createParam2 创建对象2
36-
*/
37-
@PostMapping(value = "/create2")
38-
public List<CreateVO> create2(@Valid @RequestBody List<CreateParam> createParam2) {
39-
return new LinkedList<>();
40-
}
41-
42-
/**
43-
* 获取一个实例
44-
*
45-
* @param userId 用户ID
46-
* @param sex 性别
47-
* @return 返回信息
48-
*/
49-
@GetMapping(value = "/get")
50-
public Result<CreateVO> get(@RequestParam(value = "userId", required = false) String userId,
51-
@RequestParam(value = "sex2") String sex) {
52-
return new Result<>();
53-
}
21+
// /**
22+
// * 新增一个实例
23+
// *
24+
// * @param createParam 创建对象
25+
// * @return 创建后的信息
26+
// */
27+
// @PostMapping(value = "/create")
28+
// public CreateVO add(@RequestBody @Valid CreateParam createParam) {
29+
// return new CreateVO();
30+
// }
31+
//
32+
// /**
33+
// * 新增一个实例2
34+
// *
35+
// * @param createParam2 创建对象2
36+
// */
37+
// @PostMapping(value = "/create2")
38+
// public List<CreateVO> create2(@Valid @RequestBody List<CreateParam> createParam2) {
39+
// return new LinkedList<>();
40+
// }
41+
//
42+
// /**
43+
// * 获取一个实例
44+
// *
45+
// * @param userId 用户ID
46+
// * @param sex 性别
47+
// * @return 返回信息
48+
// */
49+
// @GetMapping(value = "/get")
50+
// public Result<CreateVO> get(@RequestParam(value = "userId", required = false) String userId,
51+
// @RequestParam(value = "sex2") String sex) {
52+
// return new Result<>();
53+
// }
5454

5555
/**
5656
* 获取一个实例
@@ -60,8 +60,8 @@ public Result<CreateVO> get(@RequestParam(value = "userId", required = false) St
6060
* @return 返回信息
6161
*/
6262
@GetMapping(value = "/get")
63-
public Result<CreateParam> get2(@RequestParam(value = "userId", required = false) String userId,
64-
@RequestParam(value = "sex2") String sex) {
63+
public Result<Result2<CreateParam>> get2(@RequestParam(value = "userId", required = false) String userId,
64+
@RequestParam(value = "sex2") String sex) {
6565
return new Result<>();
6666
}
6767

0 commit comments

Comments
 (0)