1
1
package io .avaje .http .generator .core ;
2
2
3
+ import java .lang .annotation .Annotation ;
4
+ import java .util .ArrayList ;
5
+ import java .util .List ;
6
+
7
+ import javax .lang .model .element .Element ;
8
+ import javax .lang .model .element .ExecutableElement ;
9
+ import javax .lang .model .element .VariableElement ;
10
+ import javax .lang .model .type .ExecutableType ;
11
+ import javax .lang .model .type .TypeKind ;
12
+ import javax .lang .model .type .TypeMirror ;
13
+ import javax .validation .Valid ;
14
+
3
15
import io .avaje .http .api .Delete ;
4
16
import io .avaje .http .api .Form ;
5
17
import io .avaje .http .api .Get ;
9
21
import io .avaje .http .api .Put ;
10
22
import io .avaje .http .generator .core .javadoc .Javadoc ;
11
23
import io .avaje .http .generator .core .openapi .MethodDocBuilder ;
24
+ import io .swagger .v3 .oas .annotations .responses .ApiResponse ;
12
25
import io .swagger .v3 .oas .annotations .tags .Tag ;
13
26
import io .swagger .v3 .oas .annotations .tags .Tags ;
14
27
15
- import javax .lang .model .element .Element ;
16
- import javax .lang .model .element .ExecutableElement ;
17
- import javax .lang .model .element .VariableElement ;
18
- import javax .lang .model .type .ExecutableType ;
19
- import javax .lang .model .type .TypeKind ;
20
- import javax .lang .model .type .TypeMirror ;
21
- import javax .validation .Valid ;
22
- import java .lang .annotation .Annotation ;
23
- import java .util .ArrayList ;
24
- import java .util .List ;
25
-
26
28
public class MethodReader {
27
29
28
30
private final ProcessingContext ctx ;
@@ -46,13 +48,19 @@ public class MethodReader {
46
48
47
49
private final String produces ;
48
50
51
+ private final ApiResponse [] apiResponses ;
52
+
49
53
private final ExecutableType actualExecutable ;
50
54
private final List <? extends TypeMirror > actualParams ;
51
55
52
56
private final PathSegments pathSegments ;
53
57
private final boolean hasValid ;
54
58
55
- MethodReader (ControllerReader bean , ExecutableElement element , ExecutableType actualExecutable , ProcessingContext ctx ) {
59
+ MethodReader (
60
+ ControllerReader bean ,
61
+ ExecutableElement element ,
62
+ ExecutableType actualExecutable ,
63
+ ProcessingContext ctx ) {
56
64
this .ctx = ctx ;
57
65
this .bean = bean ;
58
66
this .element = element ;
@@ -62,6 +70,7 @@ public class MethodReader {
62
70
this .methodRoles = Util .findRoles (element );
63
71
this .javadoc = Javadoc .parse (ctx .getDocComment (element ));
64
72
this .produces = produces (bean );
73
+ this .apiResponses = getApiResponses ();
65
74
initWebMethodViaAnnotation ();
66
75
if (isWebMethod ()) {
67
76
this .hasValid = findAnnotation (Valid .class ) != null ;
@@ -122,6 +131,10 @@ private String produces(ControllerReader bean) {
122
131
return (produces != null ) ? produces .value () : bean .produces ();
123
132
}
124
133
134
+ private ApiResponse [] getApiResponses () {
135
+ return element .getAnnotationsByType (ApiResponse .class );
136
+ }
137
+
125
138
public <A extends Annotation > A findAnnotation (Class <A > type ) {
126
139
A annotation = element .getAnnotation (type );
127
140
if (annotation != null ) {
@@ -216,6 +229,10 @@ public String produces() {
216
229
return produces ;
217
230
}
218
231
232
+ public ApiResponse [] apiResponses () {
233
+ return apiResponses ;
234
+ }
235
+
219
236
public TypeMirror returnType () {
220
237
if (actualExecutable != null ) {
221
238
return actualExecutable .getReturnType ();
0 commit comments