diff --git a/modules/swagger-core/src/main/java/io/swagger/v3/core/util/KotlinDetector.java b/modules/swagger-core/src/main/java/io/swagger/v3/core/util/KotlinDetector.java new file mode 100644 index 0000000000..a861fd89d7 --- /dev/null +++ b/modules/swagger-core/src/main/java/io/swagger/v3/core/util/KotlinDetector.java @@ -0,0 +1,29 @@ +package io.swagger.v3.core.util; + +import java.lang.annotation.Annotation; + +public class KotlinDetector { + private static final Boolean kotlinAvailable; + private static final Class kotlinDeprecated; + + static { + kotlinAvailable = loadByClassOrNull("kotlin.Metadata") != null; + kotlinDeprecated = loadByClassOrNull("kotlin.Deprecated"); + } + + private static Class loadByClassOrNull(String className) { + try { + return (Class) ReflectionUtils.loadClassByName(className); + } catch (ClassNotFoundException ex) { + return null; + } + } + + public static boolean isKotlinPresent() { + return kotlinAvailable; + } + + public static Class getKotlinDeprecated() { + return kotlinDeprecated; + } +} diff --git a/modules/swagger-jaxrs2/src/main/java/io/swagger/v3/jaxrs2/Reader.java b/modules/swagger-jaxrs2/src/main/java/io/swagger/v3/jaxrs2/Reader.java index be60e5f8af..18dcbefea1 100644 --- a/modules/swagger-jaxrs2/src/main/java/io/swagger/v3/jaxrs2/Reader.java +++ b/modules/swagger-jaxrs2/src/main/java/io/swagger/v3/jaxrs2/Reader.java @@ -12,6 +12,7 @@ import io.swagger.v3.core.util.AnnotationsUtils; import io.swagger.v3.core.util.Json; import io.swagger.v3.core.util.Json31; +import io.swagger.v3.core.util.KotlinDetector; import io.swagger.v3.core.util.ParameterProcessor; import io.swagger.v3.core.util.PathUtils; import io.swagger.v3.core.util.ReflectionUtils; @@ -304,7 +305,8 @@ public OpenAPI read(Class cls, javax.ws.rs.Consumes classConsumes = ReflectionUtils.getAnnotation(cls, javax.ws.rs.Consumes.class); javax.ws.rs.Produces classProduces = ReflectionUtils.getAnnotation(cls, javax.ws.rs.Produces.class); - boolean classDeprecated = ReflectionUtils.getAnnotation(cls, Deprecated.class) != null; + boolean classDeprecated = ReflectionUtils.getAnnotation(cls, Deprecated.class) != null + || (KotlinDetector.isKotlinPresent() && ReflectionUtils.getAnnotation(cls, KotlinDetector.getKotlinDeprecated()) != null); // OpenApiDefinition OpenAPIDefinition openAPIDefinition = ReflectionUtils.getAnnotation(cls, OpenAPIDefinition.class); @@ -433,7 +435,8 @@ public OpenAPI read(Class cls, continue; } - boolean methodDeprecated = ReflectionUtils.getAnnotation(method, Deprecated.class) != null; + boolean methodDeprecated = ReflectionUtils.getAnnotation(method, Deprecated.class) != null + || (KotlinDetector.isKotlinPresent() && ReflectionUtils.getAnnotation(method, KotlinDetector.getKotlinDeprecated()) != null); javax.ws.rs.Path methodPath = ReflectionUtils.getAnnotation(method, javax.ws.rs.Path.class);