Skip to content

Commit 03976ef

Browse files
mikhael-sokolov-rsfrantuma
authored andcommitted
Treat kotlin's kotlin.Deprecated as a deprecated operation
1 parent 2fbef29 commit 03976ef

File tree

3 files changed

+51
-2
lines changed

3 files changed

+51
-2
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/**
2+
* Copyright 2016 SmartBear Software
3+
* <p>
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
* <p>
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
* <p>
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package io.swagger.util;
18+
19+
import java.lang.annotation.Annotation;
20+
21+
public class KotlinDetector {
22+
private static final Boolean kotlinAvailable;
23+
private static final Class<? extends Annotation> kotlinDeprecated;
24+
25+
static {
26+
kotlinAvailable = loadByClassOrNull("kotlin.Metadata") != null;
27+
kotlinDeprecated = loadByClassOrNull("kotlin.Deprecated");
28+
}
29+
30+
private static <T> Class<T> loadByClassOrNull(String className) {
31+
try {
32+
return (Class<T>) ReflectionUtils.loadClassByName(className);
33+
} catch (ClassNotFoundException ex) {
34+
return null;
35+
}
36+
}
37+
38+
public static boolean isKotlinPresent() {
39+
return kotlinAvailable;
40+
}
41+
42+
public static Class<? extends Annotation> getKotlinDeprecated() {
43+
return kotlinDeprecated;
44+
}
45+
}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
import io.swagger.models.properties.RefProperty;
7171
import io.swagger.util.BaseReaderUtils;
7272
import io.swagger.util.Json;
73+
import io.swagger.util.KotlinDetector;
7374
import io.swagger.util.ParameterProcessor;
7475
import io.swagger.util.PathUtils;
7576
import io.swagger.util.ReflectionUtils;
@@ -917,7 +918,8 @@ private Operation parseMethod(Class<?> cls, Method method, AnnotatedMethod annot
917918
addResponse(operation, apiResponse, jsonViewAnnotation);
918919
}
919920

920-
if (ReflectionUtils.getAnnotation(method, Deprecated.class) != null) {
921+
if (ReflectionUtils.getAnnotation(method, Deprecated.class) != null
922+
|| (KotlinDetector.isKotlinPresent() && ReflectionUtils.getAnnotation(method, KotlinDetector.getKotlinDeprecated()) != null)) {
921923
operation.setDeprecated(true);
922924
}
923925

modules/swagger-servlet/src/main/java/io/swagger/servlet/extensions/ServletReaderExtension.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import io.swagger.models.properties.RefProperty;
3535
import io.swagger.servlet.ReaderContext;
3636
import io.swagger.util.BaseReaderUtils;
37+
import io.swagger.util.KotlinDetector;
3738
import io.swagger.util.ParameterProcessor;
3839
import io.swagger.util.PathUtils;
3940
import io.swagger.util.ReflectionUtils;
@@ -271,7 +272,8 @@ public void applySchemes(ReaderContext context, Operation operation, Method meth
271272

272273
@Override
273274
public void setDeprecated(Operation operation, Method method) {
274-
if (ReflectionUtils.getAnnotation(method, Deprecated.class) != null) {
275+
if (ReflectionUtils.getAnnotation(method, Deprecated.class) != null
276+
|| (KotlinDetector.isKotlinPresent() && ReflectionUtils.getAnnotation(method, KotlinDetector.getKotlinDeprecated()) != null)) {
275277
operation.deprecated(true);
276278
}
277279
}

0 commit comments

Comments
 (0)