File tree Expand file tree Collapse file tree 6 files changed +156
-31
lines changed
http-generator-core/src/main/java/io/avaje/http/generator/core
tests/test-javalin-jsonb/src/main
java/org/example/myapp/web Expand file tree Collapse file tree 6 files changed +156
-31
lines changed Original file line number Diff line number Diff line change 1
1
package io .avaje .http .generator .core ;
2
2
3
- import static io .avaje .http .generator .core .ProcessingContext .*;
4
3
import static io .avaje .http .generator .core .ParamType .RESPONSE_HANDLER ;
4
+ import static io .avaje .http .generator .core .ProcessingContext .platform ;
5
+ import static io .avaje .http .generator .core .ProcessingContext .typeElement ;
5
6
6
7
import java .util .List ;
7
8
import java .util .Objects ;
@@ -245,7 +246,7 @@ void writeParamName(Append writer) {
245
246
* Build the OpenAPI documentation for this parameter.
246
247
*/
247
248
void buildApiDocumentation (MethodDocBuilder methodDoc ) {
248
- if (!isPlatformContext () && !isParamMap ) {
249
+ if (!isPlatformContext () && !isParamMap && paramType != ParamType . BEANPARAM ) {
249
250
new MethodParamDocBuilder (methodDoc , this ).build ();
250
251
}
251
252
}
Original file line number Diff line number Diff line change 1
1
package io .avaje .http .generator .core ;
2
2
3
- import io .avaje .http .generator .core .openapi . MethodDocBuilder ;
3
+ import static io .avaje .http .generator .core .ProcessingContext . asElement ;
4
4
5
+ import javax .lang .model .element .ElementKind ;
5
6
import javax .lang .model .element .VariableElement ;
6
7
8
+ import io .avaje .http .generator .core .openapi .MethodDocBuilder ;
9
+
7
10
public class MethodParam {
8
11
9
12
private final ElementReader elementParam ;
@@ -29,7 +32,25 @@ public void buildParamName(Append writer) {
29
32
}
30
33
31
34
public void buildApiDocumentation (MethodDocBuilder methodDoc ) {
32
- elementParam .buildApiDocumentation (methodDoc );
35
+ if (elementParam .paramType () != ParamType .BEANPARAM )
36
+ elementParam .buildApiDocumentation (methodDoc );
37
+ else {
38
+ asElement (elementParam .element ().asType ()).getEnclosedElements ().stream ()
39
+ .filter (e -> e .getKind () == ElementKind .FIELD )
40
+ .map (VariableElement .class ::cast )
41
+ .forEach (
42
+ e -> {
43
+ final var typeMirror = e .asType ();
44
+
45
+ new ElementReader (
46
+ e ,
47
+ Util .parse (typeMirror .toString ()),
48
+ Util .typeDef (typeMirror ),
49
+ ParamType .QUERYPARAM ,
50
+ false )
51
+ .buildApiDocumentation (methodDoc );
52
+ });
53
+ }
33
54
}
34
55
35
56
public boolean isBody () {
Original file line number Diff line number Diff line change 22
22
import io .avaje .http .generator .core .SecuritySchemesPrism ;
23
23
import io .avaje .http .generator .core .TagPrism ;
24
24
import io .avaje .http .generator .core .TagsPrism ;
25
+ import io .avaje .http .generator .core .Util ;
25
26
import io .swagger .v3 .oas .models .Components ;
26
27
import io .swagger .v3 .oas .models .OpenAPI ;
27
28
import io .swagger .v3 .oas .models .Operation ;
@@ -77,12 +78,17 @@ private OpenAPI initOpenAPI() {
77
78
}
78
79
79
80
Schema toSchema (String rawType , Element element ) {
80
- TypeElement typeElement = elements .getTypeElement (rawType );
81
+ final var typeElement = elements .getTypeElement (rawType );
82
+ final var varElement =
83
+ elements .getTypeElement (Util .trimAnnotations (element .asType ().toString ()));
84
+
81
85
if (typeElement == null ) {
82
86
// primitive types etc
83
87
return schemaBuilder .toSchema (element .asType ());
88
+ } else if (varElement != null ) {
89
+ return schemaBuilder .toSchema (element );
84
90
} else {
85
- return schemaBuilder .toSchema (typeElement . asType () );
91
+ return schemaBuilder .toSchema (typeElement );
86
92
}
87
93
}
88
94
Original file line number Diff line number Diff line change @@ -134,6 +134,17 @@ private static TypeMirror typeArgument(TypeMirror type) {
134
134
return typeArguments .get (0 );
135
135
}
136
136
137
+ Schema <?> toSchema (Element element ) {
138
+ var schema = toSchema (element .asType ());
139
+
140
+ setLengthMinMax (element , schema );
141
+ setFormatFromValidation (element , schema );
142
+ if (isNotNullable (element )) {
143
+ schema .setNullable (Boolean .FALSE );
144
+ }
145
+ return schema ;
146
+ }
147
+
137
148
Schema <?> toSchema (TypeMirror type ) {
138
149
if (types .isAssignable (type , completableFutureType )) {
139
150
type = typeArgument (type );
Original file line number Diff line number Diff line change 7
7
import javax .validation .constraints .NotNull ;
8
8
import javax .validation .constraints .Size ;
9
9
10
+ import io .avaje .http .api .Header ;
10
11
import io .avaje .jsonb .Json ;
11
12
12
13
@ Json
@@ -22,6 +23,8 @@ public class GetBeanForm {
22
23
private String email ;
23
24
24
25
private List <String > addresses ;
26
+ @ Header
27
+ private String head ;
25
28
26
29
public String getName () {
27
30
return name ;
@@ -56,4 +59,12 @@ public List<String> getAddresses() {
56
59
public void setAddresses (List <String > addresses ) {
57
60
this .addresses = addresses ;
58
61
}
62
+
63
+ public String getHead () {
64
+ return head ;
65
+ }
66
+
67
+ public void setHead (String head ) {
68
+ this .head = head ;
69
+ }
59
70
}
Original file line number Diff line number Diff line change 692
692
"description" : " " ,
693
693
"parameters" : [
694
694
{
695
- "name" : " bean" ,
696
- "in" : " bean" ,
695
+ "name" : " name" ,
696
+ "in" : " query" ,
697
+ "schema" : {
698
+ "maxLength" : 150 ,
699
+ "minLength" : 2 ,
700
+ "type" : " string" ,
701
+ "nullable" : false
702
+ }
703
+ },
704
+ {
705
+ "name" : " email" ,
706
+ "in" : " query" ,
697
707
"schema" : {
698
- "$ref" : " #/components/schemas/GetBeanForm"
708
+ "maxLength" : 100 ,
709
+ "type" : " string" ,
710
+ "format" : " email"
711
+ }
712
+ },
713
+ {
714
+ "name" : " addresses" ,
715
+ "in" : " query" ,
716
+ "schema" : {
717
+ "type" : " array" ,
718
+ "items" : {
719
+ "type" : " string"
720
+ }
721
+ }
722
+ },
723
+ {
724
+ "name" : " head" ,
725
+ "in" : " header" ,
726
+ "schema" : {
727
+ "type" : " string"
699
728
}
700
729
}
701
730
],
1125
1154
}
1126
1155
}
1127
1156
},
1157
+ "/test/byteArray" : {
1158
+ "get" : {
1159
+ "tags" : [
1160
+
1161
+ ],
1162
+ "summary" : " " ,
1163
+ "description" : " " ,
1164
+ "requestBody" : {
1165
+ "content" : {
1166
+ "application/json" : {
1167
+ "schema" : {
1168
+ "type" : " array" ,
1169
+ "items" : {
1170
+ "$ref" : " #/components/schemas/byte"
1171
+ }
1172
+ }
1173
+ }
1174
+ },
1175
+ "required" : true
1176
+ },
1177
+ "responses" : {
1178
+ "200" : {
1179
+ "description" : " " ,
1180
+ "content" : {
1181
+ "application/json" : {
1182
+ "schema" : {
1183
+ "type" : " string"
1184
+ }
1185
+ }
1186
+ }
1187
+ }
1188
+ }
1189
+ }
1190
+ },
1128
1191
"/test/ctx" : {
1129
1192
"get" : {
1130
1193
"tags" : [
1466
1529
}
1467
1530
}
1468
1531
},
1532
+ "/test/inputStream" : {
1533
+ "get" : {
1534
+ "tags" : [
1535
+
1536
+ ],
1537
+ "summary" : " " ,
1538
+ "description" : " " ,
1539
+ "requestBody" : {
1540
+ "content" : {
1541
+ "application/json" : {
1542
+ "schema" : {
1543
+ "$ref" : " #/components/schemas/InputStream"
1544
+ }
1545
+ }
1546
+ },
1547
+ "required" : true
1548
+ },
1549
+ "responses" : {
1550
+ "200" : {
1551
+ "description" : " " ,
1552
+ "content" : {
1553
+ "application/json" : {
1554
+ "schema" : {
1555
+ "type" : " string"
1556
+ }
1557
+ }
1558
+ }
1559
+ }
1560
+ }
1561
+ }
1562
+ },
1469
1563
"/test/int" : {
1470
1564
"put" : {
1471
1565
"tags" : [
1830
1924
}
1831
1925
}
1832
1926
},
1833
- "GetBeanForm" : {
1834
- "type" : " object" ,
1835
- "properties" : {
1836
- "name" : {
1837
- "maxLength" : 150 ,
1838
- "minLength" : 2 ,
1839
- "type" : " string" ,
1840
- "nullable" : false
1841
- },
1842
- "email" : {
1843
- "maxLength" : 100 ,
1844
- "type" : " string" ,
1845
- "format" : " email"
1846
- },
1847
- "addresses" : {
1848
- "type" : " array" ,
1849
- "items" : {
1850
- "type" : " string"
1851
- }
1852
- }
1853
- }
1854
- },
1855
1927
"HelloDto" : {
1856
1928
"type" : " object" ,
1857
1929
"properties" : {
1901
1973
}
1902
1974
}
1903
1975
},
1976
+ "InputStream" : {
1977
+ "type" : " object"
1978
+ },
1904
1979
"MyForm" : {
1905
1980
"type" : " object" ,
1906
1981
"properties" : {
You can’t perform that action at this time.
0 commit comments