Skip to content

Commit c5dba4b

Browse files
committed
又通过一批测试用例
1 parent 96cd0fd commit c5dba4b

File tree

7 files changed

+23
-46
lines changed

7 files changed

+23
-46
lines changed

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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,6 @@ public Map<String, Schema> read(AnnotatedType type) {
5656
return modelMap;
5757
}
5858

59-
public Map<String, Schema> readAll(Type type) {
60-
return readAll(new AnnotatedType().type(type));
61-
}
6259

6360
public Map<String, Schema> readAll(JavaClass type) {
6461
return readAll(new AnnotatedType().javaClass(type));
@@ -75,9 +72,6 @@ public Map<String, Schema> readAll(AnnotatedType type) {
7572
return new HashMap<>();
7673
}
7774

78-
public Schema resolve(Type type) {
79-
return resolve(new AnnotatedType().type(type));
80-
}
8175

8276
public Schema resolve(JavaClass type) {
8377
return resolve(new AnnotatedType().javaClass(type));

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ public Operation parseMethod(JavaMethod javaMethod, boolean deprecated, String t
277277
if (objectSchema instanceof ArraySchema) {
278278
((ArraySchema) objectSchema).getItems().$ref(constructRef(schemaMap.keySet().stream().findFirst().orElse("")));
279279
} else {
280-
objectSchema.$ref(constructRef(""));
280+
objectSchema.$ref(constructRef(schemaMap.keySet().stream().findFirst().orElse("")));
281281

282282
}
283283
}
@@ -328,7 +328,7 @@ private void setParametersItem(Operation apiMethodDoc, JavaMethod method) {
328328
apiMethodDoc.addParametersItem(inputParameter);
329329
} else {
330330
Map<String, Schema> stringSchemaMap = ModelConverters.getInstance()
331-
.readAll(DocUtils.getTypeForName(parameter.getJavaClass().getBinaryName()));
331+
.readAll(parameter.getJavaClass());
332332
for (String s : stringSchemaMap.keySet()) {
333333
Schema schema = stringSchemaMap.get(s);
334334
Map<String, Schema> properties = schema.getProperties();

apidoc-core/src/main/java/com/ztianzeng/apidoc/converter/AnnotatedType.java

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
import java.util.function.Function;
1515

1616
public class AnnotatedType {
17-
private Type type;
1817
private JavaClass javaClass;
1918
private String name;
2019
private Schema parent;
@@ -31,9 +30,6 @@ public class AnnotatedType {
3130
public AnnotatedType() {
3231
}
3332

34-
public AnnotatedType(Type type) {
35-
this.type = type;
36-
}
3733

3834
public AnnotatedType(JavaClass javaClass) {
3935
this.javaClass = javaClass;
@@ -156,18 +152,6 @@ public AnnotatedType ctxAnnotations(Annotation[] ctxAnnotations) {
156152
return this;
157153
}
158154

159-
public Type getType() {
160-
return type;
161-
}
162-
163-
public void setType(Type type) {
164-
this.type = type;
165-
}
166-
167-
public AnnotatedType type(Type type) {
168-
setType(type);
169-
return this;
170-
}
171155

172156
public JsonView getJsonViewAnnotation() {
173157
return jsonViewAnnotation;
@@ -223,13 +207,7 @@ public boolean equals(Object o) {
223207
}
224208
AnnotatedType that = (AnnotatedType) o;
225209

226-
if ((type == null && that.type != null) || (type != null && that.type == null)) {
227-
return false;
228-
}
229210

230-
if (type != null && that.type != null && !type.equals(that.type)) {
231-
return false;
232-
}
233211

234212
if (javaClass != null && that.javaClass != null && !javaClass.equals(that.javaClass)) {
235213
return false;
@@ -241,7 +219,7 @@ public boolean equals(Object o) {
241219
@Override
242220
public int hashCode() {
243221
if (ctxAnnotations == null || ctxAnnotations.length == 0) {
244-
return Objects.hash(type, "fixed");
222+
return Objects.hash(javaClass, "fixed");
245223
}
246224
List<Annotation> meaningfulAnnotations = new ArrayList<>();
247225

@@ -254,7 +232,7 @@ public int hashCode() {
254232
}
255233
}
256234
int result = 1;
257-
result = 31 * result + (type == null ? 0 : Objects.hash(type, "fixed"));
235+
result = 31 * result + (javaClass == null ? 0 : Objects.hash(javaClass, "fixed"));
258236
if (hasDifference) {
259237
result = 31 * result + (meaningfulAnnotations == null ? 0 : Arrays.hashCode(meaningfulAnnotations.toArray(new Annotation[meaningfulAnnotations.size()])));
260238
} else {

apidoc-core/src/main/java/com/ztianzeng/apidoc/converter/ModelConverterContext.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package com.ztianzeng.apidoc.converter;
22

33

4+
import com.thoughtworks.qdox.model.JavaClass;
45
import com.ztianzeng.apidoc.models.media.Schema;
56

6-
import java.lang.reflect.Type;
77
import java.util.Iterator;
88
import java.util.Map;
99

@@ -33,12 +33,12 @@ public interface ModelConverterContext {
3333
* needs to be called whenever a Schema is defined which can be referenced from another
3434
* Model or Property
3535
*
36-
* @param name the name of the model
37-
* @param model the Model
38-
* @param type the Type
39-
* @param prevName the (optional) previous name
36+
* @param name the name of the model
37+
* @param model the Model
38+
* @param javaClass the Type
39+
* @param prevName the (optional) previous name
4040
*/
41-
void defineModel(String name, Schema model, Type type, String prevName);
41+
void defineModel(String name, Schema model, JavaClass javaClass, String prevName);
4242

4343
/**
4444
* @param type The Schema

apidoc-core/src/main/java/com/ztianzeng/apidoc/converter/ModelConverterContextImpl.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
package com.ztianzeng.apidoc.converter;
22

3+
import com.thoughtworks.qdox.model.JavaClass;
34
import com.ztianzeng.apidoc.models.media.Schema;
45
import org.apache.commons.lang3.StringUtils;
56
import org.slf4j.Logger;
67
import org.slf4j.LoggerFactory;
78

8-
import java.lang.reflect.Type;
99
import java.util.*;
1010

1111
public class ModelConverterContextImpl implements ModelConverterContext {
@@ -40,9 +40,10 @@ public void defineModel(String name, Schema model) {
4040
}
4141

4242
@Override
43-
public void defineModel(String name, Schema model, Type type, String prevName) {
44-
defineModel(name, model, new AnnotatedType().type(type), prevName);
43+
public void defineModel(String name, Schema model, JavaClass type, String prevName) {
44+
defineModel(name, model, new AnnotatedType().javaClass(type), prevName);
4545
}
46+
4647
@Override
4748
public void defineModel(String name, Schema model, AnnotatedType type, String prevName) {
4849
modelByName.put(name, model);
@@ -51,7 +52,7 @@ public void defineModel(String name, Schema model, AnnotatedType type, String pr
5152
modelByName.remove(prevName);
5253
}
5354

54-
if (type != null && type.getType() != null) {
55+
if (type != null && type.getJavaClass() != null) {
5556
modelByType.put(type, model);
5657
}
5758
}

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.ztianzeng.apidoc.test;
22

33

4+
import com.thoughtworks.qdox.model.JavaClass;
45
import com.ztianzeng.apidoc.ModelResolver;
56
import com.ztianzeng.apidoc.converter.AnnotatedType;
67
import com.ztianzeng.apidoc.converter.ModelConverterContextImpl;
@@ -23,9 +24,10 @@ public void testArray() throws Exception {
2324
final ModelResolver modelResolver = new ModelResolver(mapper(), sourceBuilder);
2425

2526
final ModelConverterContextImpl context = new ModelConverterContextImpl(modelResolver);
27+
JavaClass classByName = TestBase.builder.getClassByName(ArrayBean.class.getName());
2628

2729
final Schema model = context
28-
.resolve(new AnnotatedType(ArrayBean.class));
30+
.resolve(new AnnotatedType(classByName));
2931

3032
final Map<String, Schema> props = model.getProperties();
3133
assertEquals(1, props.size());
@@ -42,9 +44,10 @@ public void testArray() throws Exception {
4244
public void testMap() throws Exception {
4345
final ModelResolver modelResolver = new ModelResolver(mapper(), sourceBuilder);
4446
final ModelConverterContextImpl context = new ModelConverterContextImpl(modelResolver);
47+
JavaClass classByName = TestBase.builder.getClassByName(ArrayBean.class.getName());
4548

4649
final Schema model = context
47-
.resolve(new AnnotatedType(MapBean.class));
50+
.resolve(new AnnotatedType(classByName));
4851

4952
final Map<String, Schema> props = model.getProperties();
5053
assertEquals(1, props.size());
@@ -62,7 +65,8 @@ public void testComplexMap() throws Exception {
6265
ModelResolver resolver = new ModelResolver(mapper(), sourceBuilder);
6366

6467
final ModelConverterContextImpl context = new ModelConverterContextImpl(resolver);
65-
context.resolve(new AnnotatedType(WrapperType.class));
68+
JavaClass classByName = TestBase.builder.getClassByName(WrapperType.class.getName());
69+
context.resolve(new AnnotatedType(classByName));
6670

6771
final Map<String, Schema> models = context.getDefinedModels();
6872
final Schema innerType = models.get("InnerType");

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ public void print() {
134134
@Test
135135
public void testMoreResponses() {
136136
Reader reader = new Reader(new OpenAPI());
137-
JavaClass classByName = TestBase.builder.getClassByName(TestController.class.getName());
137+
JavaClass classByName = TestBase.builder.getClassByName(EnhancedResponsesResource.class.getName());
138138

139139
OpenAPI openAPI = reader.read(classByName);
140140
String yaml = "openapi: 3.0.1\n" +

0 commit comments

Comments
 (0)