@@ -49,6 +49,7 @@ class SchemaDocBuilder {
49
49
private final KnownTypes knownTypes ;
50
50
private final TypeMirror iterableType ;
51
51
private final TypeMirror mapType ;
52
+ private final TypeMirror completableFutureType ;
52
53
53
54
private final Map <String , Schema > schemas = new TreeMap <>();
54
55
@@ -58,6 +59,7 @@ class SchemaDocBuilder {
58
59
this .knownTypes = new KnownTypes ();
59
60
this .iterableType = types .erasure (elements .getTypeElement ("java.lang.Iterable" ).asType ());
60
61
this .mapType = types .erasure (elements .getTypeElement ("java.util.Map" ).asType ());
62
+ this .completableFutureType = types .erasure (elements .getTypeElement ("java.util.concurrent.CompletableFuture" ).asType ());
61
63
}
62
64
63
65
Map <String , Schema > getSchemas () {
@@ -82,7 +84,6 @@ void addFormParam(Operation operation, String varName, Schema schema) {
82
84
}
83
85
84
86
private Schema requestFormParamSchema (RequestBody body ) {
85
-
86
87
final Content content = body .getContent ();
87
88
MediaType mediaType = content .get (APP_FORM );
88
89
@@ -103,7 +104,6 @@ private Schema requestFormParamSchema(RequestBody body) {
103
104
* Add as request body.
104
105
*/
105
106
void addRequestBody (Operation operation , Schema schema , boolean asForm , String description ) {
106
-
107
107
RequestBody body = requestBody (operation );
108
108
body .setDescription (description );
109
109
@@ -126,15 +126,14 @@ private RequestBody requestBody(Operation operation) {
126
126
return body ;
127
127
}
128
128
129
+ private static TypeMirror typeArgument (TypeMirror type ) {
130
+ List <? extends TypeMirror > typeArguments = ((DeclaredType ) type ).getTypeArguments ();
131
+ return typeArguments .get (0 );
132
+ }
133
+
129
134
Schema <?> toSchema (TypeMirror type ) {
130
- UType uType = UType .parse (type );
131
- if (uType .mainType ().equals ("java.util.concurrent.CompletableFuture" )) {
132
- UType bodyType = uType .paramRaw ();
133
- if (bodyType .isGeneric ()) { // Container type like List, Set etc
134
- bodyType = bodyType .paramRaw ();
135
- }
136
- TypeElement typeElement = elements .getTypeElement (bodyType .full ());
137
- type = typeElement .asType ();
135
+ if (types .isAssignable (type , completableFutureType )) {
136
+ type = typeArgument (type );
138
137
}
139
138
Schema <?> schema = knownTypes .createSchema (typeDef (type ));
140
139
if (schema != null ) {
@@ -143,20 +142,16 @@ Schema<?> toSchema(TypeMirror type) {
143
142
if (types .isAssignable (type , mapType )) {
144
143
return buildMapSchema (type );
145
144
}
146
-
147
145
if (type .getKind () == TypeKind .ARRAY ) {
148
146
return buildArraySchema (type );
149
147
}
150
-
151
148
if (types .isAssignable (type , iterableType )) {
152
149
return buildIterableSchema (type );
153
150
}
154
-
155
151
return buildObjectSchema (type );
156
152
}
157
153
158
154
private Schema <?> buildObjectSchema (TypeMirror type ) {
159
-
160
155
String objectSchemaKey = getObjectSchemaName (type );
161
156
162
157
Schema objectSchema = schemas .get (objectSchemaKey );
@@ -173,7 +168,6 @@ private Schema<?> buildObjectSchema(TypeMirror type) {
173
168
}
174
169
175
170
private Schema <?> buildIterableSchema (TypeMirror type ) {
176
-
177
171
Schema <?> itemSchema = new ObjectSchema ().format ("unknownIterableType" );
178
172
179
173
if (type .getKind () == TypeKind .DECLARED ) {
@@ -189,7 +183,6 @@ private Schema<?> buildIterableSchema(TypeMirror type) {
189
183
}
190
184
191
185
private Schema <?> buildArraySchema (TypeMirror type ) {
192
-
193
186
ArrayType arrayType = (ArrayType ) type ;
194
187
Schema <?> itemSchema = toSchema (arrayType .getComponentType ());
195
188
@@ -199,7 +192,6 @@ private Schema<?> buildArraySchema(TypeMirror type) {
199
192
}
200
193
201
194
private Schema <?> buildMapSchema (TypeMirror type ) {
202
-
203
195
Schema <?> valueSchema = new ObjectSchema ().format ("unknownMapValueType" );
204
196
205
197
if (type .getKind () == TypeKind .DECLARED ) {
@@ -216,7 +208,6 @@ private Schema<?> buildMapSchema(TypeMirror type) {
216
208
}
217
209
218
210
private String getObjectSchemaName (TypeMirror type ) {
219
-
220
211
var canonicalName = Util .trimAnnotations (type .toString ());
221
212
final var pos = canonicalName .lastIndexOf ('.' );
222
213
if (pos > -1 ) {
@@ -246,7 +237,6 @@ private void setFormatFromValidation(Element element, Schema<?> propSchema) {
246
237
}
247
238
248
239
private void setLengthMinMax (Element element , Schema <?> propSchema ) {
249
-
250
240
SizePrism .getOptionalOn (element )
251
241
.ifPresent (
252
242
size -> {
@@ -279,7 +269,6 @@ private boolean isNotNullable(Element element) {
279
269
* Gather all the fields (properties) for the given bean element.
280
270
*/
281
271
private List <VariableElement > allFields (Element element ) {
282
-
283
272
List <VariableElement > list = new ArrayList <>();
284
273
gatherProperties (list , element );
285
274
return list ;
@@ -289,7 +278,6 @@ private List<VariableElement> allFields(Element element) {
289
278
* Recursively gather all the fields (properties) for the given bean element.
290
279
*/
291
280
private void gatherProperties (List <VariableElement > fields , Element element ) {
292
-
293
281
if (element == null ) {
294
282
return ;
295
283
}
@@ -314,7 +302,6 @@ private boolean ignoreField(VariableElement field) {
314
302
}
315
303
316
304
private boolean isHiddenField (VariableElement field ) {
317
-
318
305
if (HiddenPrism .getOptionalOn (field ).isPresent ()) {
319
306
return true ;
320
307
}
0 commit comments