5
5
import com .fasterxml .jackson .databind .ObjectMapper ;
6
6
import com .fasterxml .jackson .databind .introspect .AnnotatedField ;
7
7
import com .fasterxml .jackson .databind .introspect .AnnotatedMethod ;
8
+ import com .fasterxml .jackson .databind .introspect .AnnotationMap ;
8
9
import com .fasterxml .jackson .databind .introspect .BeanPropertyDefinition ;
10
+
9
11
import io .swagger .v3 .core .util .Json ;
10
12
import io .swagger .v3 .core .util .ParameterProcessor ;
11
13
import io .swagger .v3 .jaxrs2 .ext .AbstractOpenAPIExtension ;
12
14
import io .swagger .v3 .jaxrs2 .ext .OpenAPIExtension ;
13
15
import io .swagger .v3 .jaxrs2 .ext .OpenAPIExtensions ;
16
+ import io .swagger .v3 .oas .annotations .Hidden ;
14
17
import io .swagger .v3 .oas .models .Components ;
15
18
import io .swagger .v3 .oas .models .parameters .Parameter ;
16
19
import org .apache .commons .lang3 .StringUtils ;
17
20
18
21
import javax .ws .rs .BeanParam ;
19
22
import javax .ws .rs .CookieParam ;
20
- import javax .ws .rs .FormParam ;
21
23
import javax .ws .rs .HeaderParam ;
22
24
import javax .ws .rs .PathParam ;
23
25
import javax .ws .rs .QueryParam ;
30
32
import java .util .Set ;
31
33
32
34
public class DefaultParameterExtension extends AbstractOpenAPIExtension {
33
- private static String QUERY_PARAM = "query" ;
34
- private static String HEADER_PARAM = "header" ;
35
- private static String COOKIE_PARAM = "cookie" ;
36
- private static String PATH_PARAM = "path" ;
37
- private static String FORM_PARAM = "form" ;
35
+ private static final String QUERY_PARAM = "query" ;
36
+ private static final String HEADER_PARAM = "header" ;
37
+ private static final String COOKIE_PARAM = "cookie" ;
38
+ private static final String PATH_PARAM = "path" ;
38
39
39
40
final ObjectMapper mapper = Json .mapper ();
40
41
@@ -169,17 +170,19 @@ private boolean handleAdditionalAnnotation(List<Parameter> parameters, List<Para
169
170
final AnnotatedField field = propDef .getField ();
170
171
final AnnotatedMethod setter = propDef .getSetter ();
171
172
final AnnotatedMethod getter = propDef .getGetter ();
172
- final List <Annotation > paramAnnotations = new ArrayList <Annotation >();
173
+ final List <Annotation > paramAnnotations = new ArrayList <>();
173
174
final Iterator <OpenAPIExtension > extensions = OpenAPIExtensions .chain ();
174
175
Type paramType = null ;
175
176
176
177
// Gather the field's details
177
178
if (field != null ) {
178
179
paramType = field .getType ();
179
-
180
- for (final Annotation fieldAnnotation : field .annotations ()) {
181
- if (!paramAnnotations .contains (fieldAnnotation )) {
182
- paramAnnotations .add (fieldAnnotation );
180
+ AnnotationMap annotationMap = field .getAllAnnotations ();
181
+ if (annotationMap != null ) {
182
+ for (final Annotation fieldAnnotation : annotationMap .annotations ()) {
183
+ if (!paramAnnotations .contains (fieldAnnotation )) {
184
+ paramAnnotations .add (fieldAnnotation );
185
+ }
183
186
}
184
187
}
185
188
}
@@ -191,10 +194,12 @@ private boolean handleAdditionalAnnotation(List<Parameter> parameters, List<Para
191
194
// paramType will stay null if there is no parameter
192
195
paramType = setter .getParameterType (0 );
193
196
}
194
-
195
- for (final Annotation fieldAnnotation : setter .annotations ()) {
196
- if (!paramAnnotations .contains (fieldAnnotation )) {
197
- paramAnnotations .add (fieldAnnotation );
197
+ AnnotationMap annotationMap = setter .getAllAnnotations ();
198
+ if (annotationMap != null ) {
199
+ for (final Annotation fieldAnnotation : annotationMap .annotations ()) {
200
+ if (!paramAnnotations .contains (fieldAnnotation )) {
201
+ paramAnnotations .add (fieldAnnotation );
202
+ }
198
203
}
199
204
}
200
205
}
@@ -205,10 +210,12 @@ private boolean handleAdditionalAnnotation(List<Parameter> parameters, List<Para
205
210
if (paramType == null ) {
206
211
paramType = getter .getType ();
207
212
}
208
-
209
- for (final Annotation fieldAnnotation : getter .annotations ()) {
210
- if (!paramAnnotations .contains (fieldAnnotation )) {
211
- paramAnnotations .add (fieldAnnotation );
213
+ AnnotationMap annotationMap = getter .getAllAnnotations ();
214
+ if (annotationMap != null ) {
215
+ for (final Annotation fieldAnnotation : annotationMap .annotations ()) {
216
+ if (!paramAnnotations .contains (fieldAnnotation )) {
217
+ paramAnnotations .add (fieldAnnotation );
218
+ }
212
219
}
213
220
}
214
221
}
@@ -217,6 +224,22 @@ private boolean handleAdditionalAnnotation(List<Parameter> parameters, List<Para
217
224
continue ;
218
225
}
219
226
227
+ // skip hidden properties
228
+ boolean hidden = false ;
229
+ for (Annotation a : paramAnnotations ) {
230
+ if (a instanceof io .swagger .v3 .oas .annotations .media .Schema ) {
231
+ if (((io .swagger .v3 .oas .annotations .media .Schema ) a ).hidden ()) {
232
+ hidden = true ;
233
+ break ;
234
+ };
235
+ } else if (a instanceof Hidden ) {
236
+ hidden = true ;
237
+ break ;
238
+ }
239
+ }
240
+ if (hidden ) {
241
+ continue ;
242
+ }
220
243
// Re-process all Bean fields and let the default swagger-jaxrs/swagger-jersey-jaxrs processors do their thing
221
244
ResolvedParameter resolvedParameter = extensions .next ().extractParameters (
222
245
paramAnnotations ,
0 commit comments