Skip to content

Commit 571af8f

Browse files
author
bnasslahsen
committed
Added support for non-nullable types in Kotlin. Fixes #443
1 parent 104c681 commit 571af8f

File tree

7 files changed

+146
-1
lines changed

7 files changed

+146
-1
lines changed

Diff for: springdoc-openapi-kotlin/pom.xml

+4
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414
<artifactId>springdoc-openapi-common</artifactId>
1515
<version>${project.version}</version>
1616
</dependency>
17+
<dependency>
18+
<groupId>com.fasterxml.jackson.module</groupId>
19+
<artifactId>jackson-module-kotlin</artifactId>
20+
</dependency>
1721
<dependency>
1822
<groupId>org.jetbrains.kotlin</groupId>
1923
<artifactId>kotlin-stdlib-jdk8</artifactId>

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

+3
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919
package org.springdoc.core;
2020

21+
import com.fasterxml.jackson.module.kotlin.KotlinModule;
22+
import io.swagger.v3.core.util.Json;
2123
import kotlin.Deprecated;
2224
import kotlin.coroutines.Continuation;
2325

@@ -36,6 +38,7 @@ public class SpringDocKotlinConfiguration {
3638
static {
3739
getConfig().addRequestWrapperToIgnore(Continuation.class)
3840
.addDeprecatedType(Deprecated.class);
41+
Json.mapper().registerModule(new KotlinModule());
3942
}
4043

4144
@Bean
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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.app4
20+
21+
import org.springframework.web.bind.annotation.GetMapping
22+
import org.springframework.web.bind.annotation.RequestMapping
23+
import org.springframework.web.bind.annotation.RestController
24+
25+
26+
data class Person(
27+
val name: String,
28+
val nickname: String?
29+
)
30+
31+
@RestController
32+
@RequestMapping("/test")
33+
class HelloController {
34+
@GetMapping
35+
suspend fun index(s:Person) = Person("name","nickname")
36+
37+
38+
}
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.app4
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.app4"])
26+
class SpringDocApp4Test : AbstractKotlinSpringDocTest() {
27+
28+
@SpringBootApplication
29+
open class DemoApplication
30+
31+
}

Diff for: springdoc-openapi-kotlin/src/test/resources/results/app2.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@
5555
"components": {
5656
"schemas": {
5757
"SystemStatusResponse": {
58+
"required": [
59+
"status"
60+
],
5861
"type": "object",
5962
"properties": {
6063
"status": {
@@ -67,4 +70,4 @@
6770
}
6871
}
6972
}
70-
}
73+
}

Diff for: springdoc-openapi-kotlin/src/test/resources/results/app3.json

+3
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@
5656
"components": {
5757
"schemas": {
5858
"SystemStatusResponse": {
59+
"required": [
60+
"status"
61+
],
5962
"type": "object",
6063
"properties": {
6164
"status": {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
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+
"/test": {
15+
"get": {
16+
"tags": [
17+
"hello-controller"
18+
],
19+
"operationId": "index",
20+
"parameters": [
21+
{
22+
"name": "s",
23+
"in": "query",
24+
"required": true,
25+
"schema": {
26+
"$ref": "#/components/schemas/Person"
27+
}
28+
}
29+
],
30+
"responses": {
31+
"200": {
32+
"description": "default response",
33+
"content": {
34+
"*/*": {
35+
"schema": {
36+
"$ref": "#/components/schemas/Person"
37+
}
38+
}
39+
}
40+
}
41+
}
42+
}
43+
}
44+
},
45+
"components": {
46+
"schemas": {
47+
"Person": {
48+
"required": [
49+
"name"
50+
],
51+
"type": "object",
52+
"properties": {
53+
"name": {
54+
"type": "string"
55+
},
56+
"nickname": {
57+
"type": "string"
58+
}
59+
}
60+
}
61+
}
62+
}
63+
}

0 commit comments

Comments
 (0)