Skip to content

Commit 1755c26

Browse files
committed
refs #3926 - extended repeatable annotations support
1 parent 56d233b commit 1755c26

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

modules/swagger-core/src/main/java/io/swagger/v3/core/util/ReflectionUtils.java

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import java.util.Collections;
1919
import java.util.Comparator;
2020
import java.util.HashSet;
21+
import java.util.LinkedHashSet;
2122
import java.util.List;
2223
import java.util.Optional;
2324
import java.util.Set;
@@ -317,23 +318,28 @@ public static <A extends Annotation> A getAnnotation(Class<?> cls, Class<A> anno
317318
* @return List of repeatable annotations if it is found
318319
*/
319320
public static <A extends Annotation> List<A> getRepeatableAnnotations(Method method, Class<A> annotationClass) {
321+
Set<A> annotationsSet = new LinkedHashSet<>();
320322
A[] annotations = method.getAnnotationsByType(annotationClass);
321-
if (annotations == null || annotations.length == 0) {
322-
for (Annotation metaAnnotation : method.getAnnotations()) {
323-
annotations = metaAnnotation.annotationType().getAnnotationsByType(annotationClass);
324-
if (annotations != null && annotations.length > 0) {
325-
return Arrays.asList(annotations);
326-
}
323+
if (annotations != null) {
324+
annotationsSet.addAll(Arrays.asList(annotations));
325+
}
326+
for (Annotation metaAnnotation : method.getAnnotations()) {
327+
annotations = metaAnnotation.annotationType().getAnnotationsByType(annotationClass);
328+
if (annotations != null && annotations.length > 0) {
329+
annotationsSet.addAll(Arrays.asList(annotations));
327330
}
328-
Method superclassMethod = getOverriddenMethod(method);
329-
if (superclassMethod != null) {
330-
return getRepeatableAnnotations(superclassMethod, annotationClass);
331+
}
332+
Method superclassMethod = getOverriddenMethod(method);
333+
if (superclassMethod != null) {
334+
List<A> superAnnotations = getRepeatableAnnotations(superclassMethod, annotationClass);
335+
if (superAnnotations != null) {
336+
annotationsSet.addAll(superAnnotations);
331337
}
332338
}
333-
if (annotations == null) {
339+
if (annotationsSet.isEmpty()) {
334340
return null;
335341
}
336-
return Arrays.asList(annotations);
342+
return new ArrayList<>(annotationsSet);
337343
}
338344

339345
public static <A extends Annotation> List<A> getRepeatableAnnotations(Class<?> cls, Class<A> annotationClass) {

0 commit comments

Comments
 (0)