File tree Expand file tree Collapse file tree 1 file changed +33
-1
lines changed
modules/swagger-jaxrs2/src/main/java/io/swagger/v3/jaxrs2 Expand file tree Collapse file tree 1 file changed +33
-1
lines changed Original file line number Diff line number Diff line change @@ -379,7 +379,7 @@ public OpenAPI read(Class<?> cls,
379379 // Make sure that the class methods are sorted for deterministic order
380380 // See https://docs.oracle.com/javase/8/docs/api/java/lang/Class.html#getMethods--
381381 final List <Method > methods = Arrays .stream (cls .getMethods ())
382- .sorted (Comparator . comparing ( Method :: getName ))
382+ .sorted (new MethodComparator ( ))
383383 .collect (Collectors .toList ());
384384
385385 // iterate class methods
@@ -1479,4 +1479,36 @@ private static Class<?> getClassArgument(Type cls) {
14791479 return null ;
14801480 }
14811481 }
1482+
1483+ /**
1484+ * Comparator for uniquely sorting a collection of Method objects.
1485+ * Supports overloaded methods (with the same name).
1486+ *
1487+ * @see Method
1488+ */
1489+ private static class MethodComparator implements Comparator <Method > {
1490+
1491+ @ Override
1492+ public int compare (Method m1 , Method m2 ) {
1493+ // First compare the names of the method
1494+ int val = m1 .getName ().compareTo (m2 .getName ());
1495+
1496+ // If the names are equal, compare each argument type
1497+ if (val == 0 ) {
1498+ val = m1 .getParameterTypes ().length - m2 .getParameterTypes ().length ;
1499+ if (val == 0 ) {
1500+ Class <?>[] types1 = m1 .getParameterTypes ();
1501+ Class <?>[] types2 = m2 .getParameterTypes ();
1502+ for (int i = 0 ; i < types1 .length ; i ++) {
1503+ val = types1 [i ].getName ().compareTo (types2 [i ].getName ());
1504+
1505+ if (val != 0 ) {
1506+ break ;
1507+ }
1508+ }
1509+ }
1510+ }
1511+ return val ;
1512+ }
1513+ }
14821514}
You can’t perform that action at this time.
0 commit comments