Skip to content

Commit

Permalink
Treat kotlin's kotlin.Deprecated as a deprecated operation
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikhael Sokolov committed Aug 15, 2023
1 parent d0d584d commit 803d754
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -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<? extends Annotation> kotlinDeprecated;

static {
kotlinAvailable = loadByClassOrNull("kotlin.Metadata") != null;
kotlinDeprecated = loadByClassOrNull("kotlin.Deprecated");
}

private static <T> Class<T> loadByClassOrNull(String className) {
try {
return (Class<T>) ReflectionUtils.loadClassByName(className);
} catch (ClassNotFoundException ex) {
return null;
}
}

public static boolean isKotlinPresent() {
return kotlinAvailable;
}

public static Class<? extends Annotation> getKotlinDeprecated() {
return kotlinDeprecated;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit 803d754

Please sign in to comment.