Skip to content

Commit 6e98fe9

Browse files
author
Chris Vogel
committed
Look for parameter annotations on parent classes/interfaces.
This is a fix for issue #1506. Reader got parameter annotations from a child method, ignoring any on a parent class or interface. This fix will look for annotation on the parent class or interface, if it exists. Credit mohitmutha with the fix. I just implemented it and created the pull request.
1 parent b0ec2e0 commit 6e98fe9

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

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

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package io.swagger.util;
22

33
import com.fasterxml.jackson.databind.type.TypeFactory;
4+
5+
import org.apache.commons.lang3.ArrayUtils;
46
import org.slf4j.Logger;
57
import org.slf4j.LoggerFactory;
68

@@ -209,7 +211,34 @@ public static <A extends Annotation> A getAnnotation(Class<?> cls, Class<A> anno
209211
}
210212
return annotation;
211213
}
214+
215+
public static Annotation[][] getParameterAnnotations(Method method) {
216+
Annotation[][] methodAnnotations = method.getParameterAnnotations();
217+
Method overriddenmethod = getOverriddenMethod(method);
218+
219+
if (overriddenmethod != null) {
220+
Annotation[][] overriddenAnnotations = overriddenmethod
221+
.getParameterAnnotations();
212222

223+
for (int i = 0; i < methodAnnotations.length; i++) {
224+
List<Type> types = new ArrayList<Type>();
225+
for (int j = 0; j < methodAnnotations[i].length; j++) {
226+
types.add(methodAnnotations[i][j].annotationType());
227+
}
228+
for (int j = 0; j < overriddenAnnotations[i].length; j++) {
229+
if (!types.contains(overriddenAnnotations[i][j]
230+
.annotationType())) {
231+
methodAnnotations[i] = ArrayUtils.add(
232+
methodAnnotations[i],
233+
overriddenAnnotations[i][j]);
234+
}
235+
}
236+
237+
}
238+
}
239+
return methodAnnotations;
240+
}
241+
213242
/**
214243
* Checks if the type is void.
215244
*

modules/swagger-jaxrs/src/main/java/io/swagger/jaxrs/Reader.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -858,7 +858,7 @@ private Operation parseMethod(Class<?> cls, Method method, List<Parameter> globa
858858
}
859859

860860
Type[] genericParameterTypes = method.getGenericParameterTypes();
861-
Annotation[][] paramAnnotations = method.getParameterAnnotations();
861+
Annotation[][] paramAnnotations = ReflectionUtils.getParameterAnnotations(method);
862862
for (int i = 0; i < genericParameterTypes.length; i++) {
863863
final Type type = TypeFactory.defaultInstance().constructType(genericParameterTypes[i], cls);
864864
List<Parameter> parameters = getParameters(type, Arrays.asList(paramAnnotations[i]));

0 commit comments

Comments
 (0)