9
9
import com .ztianzeng .apidoc .converter .AnnotatedType ;
10
10
import com .ztianzeng .apidoc .converter .ModelConverter ;
11
11
import com .ztianzeng .apidoc .converter .ModelConverterContext ;
12
+ import com .ztianzeng .apidoc .models .media .ArraySchema ;
12
13
import com .ztianzeng .apidoc .models .media .MapSchema ;
13
14
import com .ztianzeng .apidoc .models .media .PrimitiveType ;
14
15
import com .ztianzeng .apidoc .models .media .Schema ;
@@ -59,7 +60,6 @@ public Schema resolve(AnnotatedType annotatedType,
59
60
}
60
61
61
62
62
-
63
63
Schema resolvedModel = context .resolve (annotatedType );
64
64
if (resolvedModel != null ) {
65
65
if (parentName .equals (resolvedModel .getName ())) {
@@ -69,9 +69,14 @@ public Schema resolve(AnnotatedType annotatedType,
69
69
70
70
71
71
// 转换成OpenApi定义的字段信息
72
- PrimitiveType parentType = PrimitiveType .fromType (targetClass .getFullyQualifiedName ());
72
+ PrimitiveType parentType = PrimitiveType .fromType (targetClass .getBinaryName ());
73
73
schema .setType (Optional .ofNullable (parentType ).orElse (PrimitiveType .OBJECT ).getCommonName ());
74
74
if (DocUtils .isPrimitive (targetClass .getName ())) {
75
+ if (targetClass .isArray ()) {
76
+ Schema array = new Schema ();
77
+ array .setType (schema .getType ());
78
+ schema = new ArraySchema ().items (array );
79
+ }
75
80
return schema ;
76
81
}
77
82
schema .name (parentName );
@@ -89,6 +94,9 @@ public Schema resolve(AnnotatedType annotatedType,
89
94
if (targetClass .isA (Map .class .getName ())) {
90
95
// 泛型信息
91
96
List <JavaType > actualTypeArguments = ((DefaultJavaParameterizedType ) targetClass ).getActualTypeArguments ();
97
+ if (actualTypeArguments .isEmpty ()) {
98
+ return null ;
99
+ }
92
100
JavaType javaType = actualTypeArguments .get (1 );
93
101
94
102
Schema addPropertiesSchema = context .resolve (
@@ -116,6 +124,28 @@ public Schema resolve(AnnotatedType annotatedType,
116
124
}
117
125
}
118
126
schema = new MapSchema ().additionalProperties (addPropertiesSchema );
127
+ } else if (targetClass .isA (Collection .class .getName ())
128
+ || targetClass .isA (List .class .getName ())) {
129
+ // 泛型信息
130
+ List <JavaType > actualTypeArguments = ((DefaultJavaParameterizedType ) targetClass ).getActualTypeArguments ();
131
+ if (actualTypeArguments .isEmpty ()) {
132
+ return null ;
133
+ }
134
+ JavaType javaType = actualTypeArguments .get (0 );
135
+ // 处理集合
136
+ Schema items = context .resolve (new AnnotatedType ()
137
+ .javaClass (builder .getClassByName (javaType .getFullyQualifiedName ()))
138
+ .schemaProperty (annotatedType .isSchemaProperty ())
139
+ .skipSchemaName (true )
140
+ .resolveAsRef (annotatedType .isResolveAsRef ())
141
+ .propertyName (annotatedType .getPropertyName ())
142
+ .jsonViewAnnotation (annotatedType .getJsonViewAnnotation ())
143
+ .parent (annotatedType .getParent ()));
144
+
145
+ if (items == null ) {
146
+ return null ;
147
+ }
148
+ schema = new ArraySchema ().items (items );
119
149
}
120
150
// // 如果是集合类型,将类型向上抛出继续处理
121
151
// if (targetType.isContainerType()) {
0 commit comments