diff --git a/modules/swagger-core/src/main/java/io/swagger/v3/core/util/ReflectionUtils.java b/modules/swagger-core/src/main/java/io/swagger/v3/core/util/ReflectionUtils.java index af29d54be9..ba1f73dae1 100644 --- a/modules/swagger-core/src/main/java/io/swagger/v3/core/util/ReflectionUtils.java +++ b/modules/swagger-core/src/main/java/io/swagger/v3/core/util/ReflectionUtils.java @@ -18,6 +18,7 @@ import java.util.Collections; import java.util.Comparator; import java.util.HashSet; +import java.util.LinkedHashSet; import java.util.List; import java.util.Optional; import java.util.Set; @@ -317,23 +318,28 @@ public static A getAnnotation(Class cls, Class anno * @return List of repeatable annotations if it is found */ public static List getRepeatableAnnotations(Method method, Class annotationClass) { + Set annotationsSet = new LinkedHashSet<>(); A[] annotations = method.getAnnotationsByType(annotationClass); - if (annotations == null || annotations.length == 0) { - for (Annotation metaAnnotation : method.getAnnotations()) { - annotations = metaAnnotation.annotationType().getAnnotationsByType(annotationClass); - if (annotations != null && annotations.length > 0) { - return Arrays.asList(annotations); - } + if (annotations != null) { + annotationsSet.addAll(Arrays.asList(annotations)); + } + for (Annotation metaAnnotation : method.getAnnotations()) { + annotations = metaAnnotation.annotationType().getAnnotationsByType(annotationClass); + if (annotations != null && annotations.length > 0) { + annotationsSet.addAll(Arrays.asList(annotations)); } - Method superclassMethod = getOverriddenMethod(method); - if (superclassMethod != null) { - return getRepeatableAnnotations(superclassMethod, annotationClass); + } + Method superclassMethod = getOverriddenMethod(method); + if (superclassMethod != null) { + List superAnnotations = getRepeatableAnnotations(superclassMethod, annotationClass); + if (superAnnotations != null) { + annotationsSet.addAll(superAnnotations); } } - if (annotations == null) { + if (annotationsSet.isEmpty()) { return null; } - return Arrays.asList(annotations); + return new ArrayList<>(annotationsSet); } public static List getRepeatableAnnotations(Class cls, Class annotationClass) {