Skip to content

Commit dc65875

Browse files
mikhael-sokolov-rsfrantuma
authored andcommitted
Treat kotlin's kotlin.Deprecated as a deprecated operation
1 parent bfd25e2 commit dc65875

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package io.swagger.v3.core.util;
2+
3+
import java.lang.annotation.Annotation;
4+
5+
public class KotlinDetector {
6+
private static final Boolean kotlinAvailable;
7+
private static final Class<? extends Annotation> kotlinDeprecated;
8+
9+
static {
10+
kotlinAvailable = loadByClassOrNull("kotlin.Metadata") != null;
11+
kotlinDeprecated = loadByClassOrNull("kotlin.Deprecated");
12+
}
13+
14+
private static <T> Class<T> loadByClassOrNull(String className) {
15+
try {
16+
return (Class<T>) ReflectionUtils.loadClassByName(className);
17+
} catch (ClassNotFoundException ex) {
18+
return null;
19+
}
20+
}
21+
22+
public static boolean isKotlinPresent() {
23+
return kotlinAvailable;
24+
}
25+
26+
public static Class<? extends Annotation> getKotlinDeprecated() {
27+
return kotlinDeprecated;
28+
}
29+
}

modules/swagger-jaxrs2/src/main/java/io/swagger/v3/jaxrs2/Reader.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import io.swagger.v3.core.util.AnnotationsUtils;
1313
import io.swagger.v3.core.util.Json;
1414
import io.swagger.v3.core.util.Json31;
15+
import io.swagger.v3.core.util.KotlinDetector;
1516
import io.swagger.v3.core.util.ParameterProcessor;
1617
import io.swagger.v3.core.util.PathUtils;
1718
import io.swagger.v3.core.util.ReflectionUtils;
@@ -305,7 +306,8 @@ public OpenAPI read(Class<?> cls,
305306
javax.ws.rs.Consumes classConsumes = ReflectionUtils.getAnnotation(cls, javax.ws.rs.Consumes.class);
306307
javax.ws.rs.Produces classProduces = ReflectionUtils.getAnnotation(cls, javax.ws.rs.Produces.class);
307308

308-
boolean classDeprecated = ReflectionUtils.getAnnotation(cls, Deprecated.class) != null;
309+
boolean classDeprecated = ReflectionUtils.getAnnotation(cls, Deprecated.class) != null
310+
|| (KotlinDetector.isKotlinPresent() && ReflectionUtils.getAnnotation(cls, KotlinDetector.getKotlinDeprecated()) != null);
309311

310312
// OpenApiDefinition
311313
OpenAPIDefinition openAPIDefinition = ReflectionUtils.getAnnotation(cls, OpenAPIDefinition.class);
@@ -434,7 +436,8 @@ public OpenAPI read(Class<?> cls,
434436
continue;
435437
}
436438

437-
boolean methodDeprecated = ReflectionUtils.getAnnotation(method, Deprecated.class) != null;
439+
boolean methodDeprecated = ReflectionUtils.getAnnotation(method, Deprecated.class) != null
440+
|| (KotlinDetector.isKotlinPresent() && ReflectionUtils.getAnnotation(method, KotlinDetector.getKotlinDeprecated()) != null);
438441

439442
javax.ws.rs.Path methodPath = ReflectionUtils.getAnnotation(method, javax.ws.rs.Path.class);
440443

0 commit comments

Comments
 (0)