Skip to content

Commit 3444cfa

Browse files
author
bnasslahsen
committed
Support for kotlin. Deprecated. Fixes #414
1 parent 529fa98 commit 3444cfa

File tree

7 files changed

+169
-52
lines changed

7 files changed

+169
-52
lines changed

Diff for: springdoc-openapi-common/src/main/java/org/springdoc/api/AbstractOpenApiResource.java

+14-1
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,16 @@ public abstract class AbstractOpenApiResource extends SpecFilter {
8585

8686
private static final List<Class<?>> ADDITIONAL_REST_CONTROLLERS = new ArrayList<>();
8787
private static final List<Class<?>> HIDDEN_REST_CONTROLLERS = new ArrayList<>();
88+
private static final List<Class> DEPRECATED_TYPES = new ArrayList<>();
8889

8990
private boolean computeDone;
9091

9192
private final String groupName;
9293

94+
static {
95+
DEPRECATED_TYPES.add(Deprecated.class);
96+
}
97+
9398
protected AbstractOpenApiResource(String groupName, OpenAPIBuilder openAPIBuilder, AbstractRequestBuilder requestBuilder,
9499
GenericResponseBuilder responseBuilder, OperationBuilder operationParser,
95100
Optional<List<OpenApiCustomiser>> openApiCustomisers, SpringDocConfigProperties springDocConfigProperties) {
@@ -177,7 +182,7 @@ protected void calculatePath(HandlerMethod handlerMethod, String operationPath,
177182

178183
Operation operation = (existingOperation != null) ? existingOperation : new Operation();
179184

180-
if (ReflectionUtils.getAnnotation(method, Deprecated.class) != null) {
185+
if (isDeprecatedType(method)) {
181186
operation.setDeprecated(true);
182187
}
183188

@@ -394,4 +399,12 @@ protected Set getDefaultAllowedHttpMethods() {
394399
RequestMethod[] allowedRequestMethods = { RequestMethod.GET, RequestMethod.POST, RequestMethod.PUT, RequestMethod.PATCH, RequestMethod.DELETE, RequestMethod.OPTIONS, RequestMethod.HEAD };
395400
return new HashSet<>(Arrays.asList(allowedRequestMethods));
396401
}
402+
403+
public static void addDeprecatedType(Class<?> cls){
404+
DEPRECATED_TYPES.add(cls);
405+
}
406+
407+
private boolean isDeprecatedType(Method method) {
408+
return DEPRECATED_TYPES.stream().anyMatch(clazz -> (ReflectionUtils.getAnnotation(method, clazz) != null));
409+
}
397410
}

Diff for: springdoc-openapi-kotlin/src/main/java/org/springdoc/core/KotlinCoroutinesRequestBuilder.java

-40
This file was deleted.

Diff for: springdoc-openapi-kotlin/src/main/java/org/springdoc/core/SpringDocKotlinConfiguration.java

+7-11
Original file line numberDiff line numberDiff line change
@@ -18,29 +18,25 @@
1818

1919
package org.springdoc.core;
2020

21-
import java.util.List;
22-
import java.util.Optional;
23-
24-
import org.springdoc.core.customizers.OperationCustomizer;
25-
import org.springdoc.core.customizers.ParameterCustomizer;
21+
import kotlin.Deprecated;
22+
import kotlin.coroutines.Continuation;
2623

2724
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
2825
import org.springframework.context.annotation.Bean;
2926
import org.springframework.context.annotation.Configuration;
3027
import org.springframework.context.annotation.Primary;
3128

29+
import static org.springdoc.api.AbstractOpenApiResource.addDeprecatedType;
30+
import static org.springdoc.core.AbstractRequestBuilder.addRequestWrapperToIgnore;
3231
import static org.springdoc.core.Constants.SPRINGDOC_ENABLED;
3332

3433
@Configuration
3534
@ConditionalOnProperty(name = SPRINGDOC_ENABLED, matchIfMissing = true)
3635
public class SpringDocKotlinConfiguration {
3736

38-
@Bean
39-
@Primary
40-
KotlinCoroutinesRequestBuilder kotlinCoroutinesRequestBuilder(GenericParameterBuilder parameterBuilder, RequestBodyBuilder requestBodyBuilder,
41-
OperationBuilder operationBuilder, Optional<List<OperationCustomizer>> operationCustomizers, Optional<List<ParameterCustomizer>> parameterCustomizers) {
42-
return new KotlinCoroutinesRequestBuilder(parameterBuilder, requestBodyBuilder,
43-
operationBuilder, operationCustomizers, parameterCustomizers);
37+
static {
38+
addRequestWrapperToIgnore(Continuation.class);
39+
addDeprecatedType(Deprecated.class);
4440
}
4541

4642
@Bean

Diff for: springdoc-openapi-kotlin/src/test/kotlin/test/org/springdoc/api/AbstractKotlinSpringDocTest.kt

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ abstract class AbstractKotlinSpringDocTest {
4545
.expectStatus().isOk.expectBody().returnResult()
4646

4747
val result = String(getResult.responseBody!!)
48+
print(result)
4849
val className = javaClass.simpleName
4950
val testNumber = className.replace("[^0-9]".toRegex(), "")
5051

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
*
3+
* * Copyright 2019-2020 the original author or authors.
4+
* *
5+
* * Licensed under the Apache License, Version 2.0 (the "License");
6+
* * you may not use this file except in compliance with the License.
7+
* * You may obtain a copy of the License at
8+
* *
9+
* * https://www.apache.org/licenses/LICENSE-2.0
10+
* *
11+
* * Unless required by applicable law or agreed to in writing, software
12+
* * distributed under the License is distributed on an "AS IS" BASIS,
13+
* * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* * See the License for the specific language governing permissions and
15+
* * limitations under the License.
16+
*
17+
*/
18+
19+
package test.org.springdoc.api.app3
20+
21+
import org.springframework.boot.autoconfigure.SpringBootApplication
22+
import org.springframework.context.annotation.ComponentScan
23+
import test.org.springdoc.api.AbstractKotlinSpringDocTest
24+
25+
@ComponentScan(basePackages = ["org.springdoc", "test.org.springdoc.api.app3"])
26+
class SpringDocApp3Test : AbstractKotlinSpringDocTest() {
27+
28+
@SpringBootApplication
29+
open class DemoApplication
30+
31+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
*
3+
* * Copyright 2019-2020 the original author or authors.
4+
* *
5+
* * Licensed under the Apache License, Version 2.0 (the "License");
6+
* * you may not use this file except in compliance with the License.
7+
* * You may obtain a copy of the License at
8+
* *
9+
* * https://www.apache.org/licenses/LICENSE-2.0
10+
* *
11+
* * Unless required by applicable law or agreed to in writing, software
12+
* * distributed under the License is distributed on an "AS IS" BASIS,
13+
* * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* * See the License for the specific language governing permissions and
15+
* * limitations under the License.
16+
*
17+
*/
18+
19+
package test.org.springdoc.api.app3
20+
21+
import kotlinx.coroutines.reactor.mono
22+
import org.springframework.web.bind.annotation.GetMapping
23+
import org.springframework.web.bind.annotation.RequestMapping
24+
import org.springframework.web.bind.annotation.RestController
25+
26+
enum class SystemStatus(val status: String) {
27+
OK("OK")
28+
}
29+
30+
data class SystemStatusResponse(
31+
val status: SystemStatus
32+
)
33+
34+
@RestController
35+
@RequestMapping("/status")
36+
class SystemStatusController {
37+
@GetMapping
38+
suspend fun index() = SystemStatusResponse(SystemStatus.OK)
39+
40+
@GetMapping("/foo")
41+
@Deprecated("")
42+
fun foo() = mono {
43+
SystemStatusResponse(SystemStatus.OK)
44+
}
45+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
{
2+
"openapi": "3.0.1",
3+
"info": {
4+
"title": "OpenAPI definition",
5+
"version": "v0"
6+
},
7+
"servers": [
8+
{
9+
"url": "",
10+
"description": "Generated server url"
11+
}
12+
],
13+
"paths": {
14+
"/status": {
15+
"get": {
16+
"tags": [
17+
"system-status-controller"
18+
],
19+
"operationId": "index",
20+
"responses": {
21+
"200": {
22+
"description": "default response",
23+
"content": {
24+
"*/*": {
25+
"schema": {
26+
"$ref": "#/components/schemas/SystemStatusResponse"
27+
}
28+
}
29+
}
30+
}
31+
}
32+
}
33+
},
34+
"/status/foo": {
35+
"get": {
36+
"tags": [
37+
"system-status-controller"
38+
],
39+
"operationId": "foo",
40+
"responses": {
41+
"200": {
42+
"description": "default response",
43+
"content": {
44+
"*/*": {
45+
"schema": {
46+
"$ref": "#/components/schemas/SystemStatusResponse"
47+
}
48+
}
49+
}
50+
}
51+
},
52+
"deprecated": true
53+
}
54+
}
55+
},
56+
"components": {
57+
"schemas": {
58+
"SystemStatusResponse": {
59+
"type": "object",
60+
"properties": {
61+
"status": {
62+
"type": "string",
63+
"enum": [
64+
"OK"
65+
]
66+
}
67+
}
68+
}
69+
}
70+
}
71+
}

0 commit comments

Comments
 (0)