Skip to content

Commit afdc831

Browse files
committed
fix isKtor, update samples
1 parent f766f44 commit afdc831

File tree

12 files changed

+52
-73
lines changed

12 files changed

+52
-73
lines changed

modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/KotlinServerCodegen.java

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -294,15 +294,15 @@ public void processOpts() {
294294

295295
String gradleBuildFile = "build.gradle";
296296

297-
if (isJavalin() || isKtor()) {
297+
if (isJavalin() || isKtor2Or3()) {
298298
gradleBuildFile = "build.gradle.kts";
299299
}
300300

301301
supportingFiles.add(new SupportingFile(gradleBuildFile + ".mustache", "", gradleBuildFile));
302302
supportingFiles.add(new SupportingFile("settings.gradle.mustache", "", "settings.gradle"));
303303
supportingFiles.add(new SupportingFile("gradle.properties", "", "gradle.properties"));
304304

305-
if (isKtor()) {
305+
if (isKtor2Or3()) {
306306
additionalProperties.put(Constants.IS_KTOR, true);
307307

308308
supportingFiles.add(new SupportingFile("AppMain.kt.mustache", packageFolder, "AppMain.kt"));
@@ -445,7 +445,20 @@ private boolean isJavalin() {
445445
return Constants.JAVALIN5.equals(library) || Constants.JAVALIN6.equals(library);
446446
}
447447

448-
private boolean isKtor() {
448+
private boolean isKtor2Or3() {
449449
return Constants.KTOR.equals(library) || Constants.KTOR2.equals(library);
450450
}
451+
452+
/**
453+
* Returns true if latest version of ktor is used.
454+
*
455+
* @return true if latest veresion of ktor is used.
456+
*/
457+
private boolean isKtor() {
458+
return Constants.KTOR.equals(library);
459+
}
460+
461+
private boolean isKtor2() {
462+
return Constants.KTOR2.equals(library);
463+
}
451464
}
Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +0,0 @@
1-
package org.openapitools.client.infrastructure
2-
3-
import com.squareup.moshi.Moshi
4-
5-
object Serializer {
6-
@JvmStatic
7-
val moshiBuilder: Moshi.Builder = Moshi.Builder()
8-
.add(OffsetDateTimeAdapter())
9-
.add(LocalDateTimeAdapter())
10-
.add(LocalDateAdapter())
11-
.add(UUIDAdapter())
12-
.add(ByteArrayAdapter())
13-
.add(URIAdapter())
14-
.add(BigDecimalAdapter())
15-
.add(BigIntegerAdapter())
16-
17-
@JvmStatic
18-
val moshi: Moshi by lazy {
19-
moshiBuilder.build()
20-
}
21-
}

samples/server/petstore/kotlin-server/ktor2/.openapi-generator/FILES

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
Dockerfile
21
README.md
32
build.gradle.kts
43
gradle.properties

samples/server/petstore/kotlin-server/ktor2/src/main/kotlin/org/openapitools/server/apis/PetApi.kt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ fun Route.PetApi() {
3636
authenticate("petstore_auth") {
3737
post<Paths.addPet> {
3838

39-
val principal = call.authentication.principal<OAuthAccessTokenResponse>()!!
39+
val principal = call.authentication.principal<OAuthAccessTokenResponse>()
4040

4141

4242
val exampleContentType = "application/json"
@@ -70,7 +70,7 @@ fun Route.PetApi() {
7070
authenticate("petstore_auth") {
7171
delete<Paths.deletePet> {
7272

73-
val principal = call.authentication.principal<OAuthAccessTokenResponse>()!!
73+
val principal = call.authentication.principal<OAuthAccessTokenResponse>()
7474

7575

7676
call.respond(HttpStatusCode.NotImplemented)
@@ -81,7 +81,7 @@ fun Route.PetApi() {
8181
authenticate("petstore_auth") {
8282
get<Paths.findPetsByStatus> {
8383

84-
val principal = call.authentication.principal<OAuthAccessTokenResponse>()!!
84+
val principal = call.authentication.principal<OAuthAccessTokenResponse>()
8585

8686

8787
val exampleContentType = "application/json"
@@ -131,7 +131,7 @@ fun Route.PetApi() {
131131
authenticate("petstore_auth") {
132132
get<Paths.findPetsByTags> {
133133

134-
val principal = call.authentication.principal<OAuthAccessTokenResponse>()!!
134+
val principal = call.authentication.principal<OAuthAccessTokenResponse>()
135135

136136

137137
val exampleContentType = "application/json"
@@ -181,7 +181,7 @@ fun Route.PetApi() {
181181
authenticate("api_key") {
182182
get<Paths.getPetById> {
183183

184-
val principal = call.authentication.principal<ApiPrincipal>()!!
184+
val principal = call.authentication.principal<ApiPrincipal>()
185185

186186

187187
val exampleContentType = "application/json"
@@ -215,7 +215,7 @@ fun Route.PetApi() {
215215
authenticate("petstore_auth") {
216216
put<Paths.updatePet> {
217217

218-
val principal = call.authentication.principal<OAuthAccessTokenResponse>()!!
218+
val principal = call.authentication.principal<OAuthAccessTokenResponse>()
219219

220220

221221
val exampleContentType = "application/json"
@@ -249,7 +249,7 @@ fun Route.PetApi() {
249249
authenticate("petstore_auth") {
250250
post<Paths.updatePetWithForm> {
251251

252-
val principal = call.authentication.principal<OAuthAccessTokenResponse>()!!
252+
val principal = call.authentication.principal<OAuthAccessTokenResponse>()
253253

254254

255255
call.respond(HttpStatusCode.NotImplemented)
@@ -260,7 +260,7 @@ fun Route.PetApi() {
260260
authenticate("petstore_auth") {
261261
post<Paths.uploadFile> {
262262

263-
val principal = call.authentication.principal<OAuthAccessTokenResponse>()!!
263+
val principal = call.authentication.principal<OAuthAccessTokenResponse>()
264264

265265

266266
val exampleContentType = "application/json"

samples/server/petstore/kotlin-server/ktor2/src/main/kotlin/org/openapitools/server/apis/StoreApi.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ fun Route.StoreApi() {
4040
authenticate("api_key") {
4141
get<Paths.getInventory> {
4242

43-
val principal = call.authentication.principal<ApiPrincipal>()!!
43+
val principal = call.authentication.principal<ApiPrincipal>()
4444

4545

4646
call.respond(HttpStatusCode.NotImplemented)
@@ -60,7 +60,7 @@ fun Route.StoreApi() {
6060
}"""
6161

6262
when (exampleContentType) {
63-
"application/json" -> call.respond(gson.fromJson(exampleContentString, empty::class.java))
63+
"application/json" -> call.respondText(exampleContentType, ContentType.Application.Json)
6464
"application/xml" -> call.respondText(exampleContentString, ContentType.Text.Xml)
6565
else -> call.respondText(exampleContentString)
6666
}
@@ -79,7 +79,7 @@ fun Route.StoreApi() {
7979
}"""
8080

8181
when (exampleContentType) {
82-
"application/json" -> call.respond(gson.fromJson(exampleContentString, empty::class.java))
82+
"application/json" -> call.respondText(exampleContentType, ContentType.Application.Json)
8383
"application/xml" -> call.respondText(exampleContentString, ContentType.Text.Xml)
8484
else -> call.respondText(exampleContentString)
8585
}

samples/server/petstore/kotlin-server/ktor2/src/main/kotlin/org/openapitools/server/apis/UserApi.kt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ fun Route.UserApi() {
3535
authenticate("api_key") {
3636
post<Paths.createUser> {
3737

38-
val principal = call.authentication.principal<ApiPrincipal>()!!
38+
val principal = call.authentication.principal<ApiPrincipal>()
3939

4040

4141
call.respond(HttpStatusCode.NotImplemented)
@@ -46,7 +46,7 @@ fun Route.UserApi() {
4646
authenticate("api_key") {
4747
post<Paths.createUsersWithArrayInput> {
4848

49-
val principal = call.authentication.principal<ApiPrincipal>()!!
49+
val principal = call.authentication.principal<ApiPrincipal>()
5050

5151

5252
call.respond(HttpStatusCode.NotImplemented)
@@ -57,7 +57,7 @@ fun Route.UserApi() {
5757
authenticate("api_key") {
5858
post<Paths.createUsersWithListInput> {
5959

60-
val principal = call.authentication.principal<ApiPrincipal>()!!
60+
val principal = call.authentication.principal<ApiPrincipal>()
6161

6262

6363
call.respond(HttpStatusCode.NotImplemented)
@@ -68,7 +68,7 @@ fun Route.UserApi() {
6868
authenticate("api_key") {
6969
delete<Paths.deleteUser> {
7070

71-
val principal = call.authentication.principal<ApiPrincipal>()!!
71+
val principal = call.authentication.principal<ApiPrincipal>()
7272

7373

7474
call.respond(HttpStatusCode.NotImplemented)
@@ -90,7 +90,7 @@ fun Route.UserApi() {
9090
}"""
9191

9292
when (exampleContentType) {
93-
"application/json" -> call.respond(gson.fromJson(exampleContentString, empty::class.java))
93+
"application/json" -> call.respondText(exampleContentType, ContentType.Application.Json)
9494
"application/xml" -> call.respondText(exampleContentString, ContentType.Text.Xml)
9595
else -> call.respondText(exampleContentString)
9696
}
@@ -105,7 +105,7 @@ fun Route.UserApi() {
105105
authenticate("api_key") {
106106
get<Paths.logoutUser> {
107107

108-
val principal = call.authentication.principal<ApiPrincipal>()!!
108+
val principal = call.authentication.principal<ApiPrincipal>()
109109

110110

111111
call.respond(HttpStatusCode.NotImplemented)
@@ -116,7 +116,7 @@ fun Route.UserApi() {
116116
authenticate("api_key") {
117117
put<Paths.updateUser> {
118118

119-
val principal = call.authentication.principal<ApiPrincipal>()!!
119+
val principal = call.authentication.principal<ApiPrincipal>()
120120

121121

122122
call.respond(HttpStatusCode.NotImplemented)

samples/server/petstore/kotlin-server/ktor2/src/main/kotlin/org/openapitools/server/models/Category.kt

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,17 @@
1212
package org.openapitools.server.models
1313

1414

15-
import java.io.Serializable
15+
import kotlinx.serialization.Serializable
1616
/**
1717
* A category for a pet
1818
* @param id
1919
* @param name
2020
*/
21+
@Serializable
2122
data class Category(
2223
val id: kotlin.Long? = null,
2324
val name: kotlin.String? = null
24-
) : Serializable
25+
)
2526
{
26-
companion object {
27-
private const val serialVersionUID: Long = 123
28-
}
2927
}
3028

samples/server/petstore/kotlin-server/ktor2/src/main/kotlin/org/openapitools/server/models/ModelApiResponse.kt

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,19 @@
1212
package org.openapitools.server.models
1313

1414

15-
import java.io.Serializable
15+
import kotlinx.serialization.Serializable
1616
/**
1717
* Describes the result of uploading an image resource
1818
* @param code
1919
* @param type
2020
* @param message
2121
*/
22+
@Serializable
2223
data class ModelApiResponse(
2324
val code: kotlin.Int? = null,
2425
val type: kotlin.String? = null,
2526
val message: kotlin.String? = null
26-
) : Serializable
27+
)
2728
{
28-
companion object {
29-
private const val serialVersionUID: Long = 123
30-
}
3129
}
3230

samples/server/petstore/kotlin-server/ktor2/src/main/kotlin/org/openapitools/server/models/Order.kt

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
package org.openapitools.server.models
1313

1414

15-
import java.io.Serializable
15+
import kotlinx.serialization.Serializable
1616
/**
1717
* An order for a pets from the pet store
1818
* @param id
@@ -22,6 +22,7 @@ import java.io.Serializable
2222
* @param status Order Status
2323
* @param complete
2424
*/
25+
@Serializable
2526
data class Order(
2627
val id: kotlin.Long? = null,
2728
val petId: kotlin.Long? = null,
@@ -30,11 +31,8 @@ data class Order(
3031
/* Order Status */
3132
val status: Order.Status? = null,
3233
val complete: kotlin.Boolean? = false
33-
) : Serializable
34+
)
3435
{
35-
companion object {
36-
private const val serialVersionUID: Long = 123
37-
}
3836
/**
3937
* Order Status
4038
* Values: placed,approved,delivered

samples/server/petstore/kotlin-server/ktor2/src/main/kotlin/org/openapitools/server/models/Pet.kt

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ package org.openapitools.server.models
1414
import org.openapitools.server.models.Category
1515
import org.openapitools.server.models.Tag
1616

17-
import java.io.Serializable
17+
import kotlinx.serialization.Serializable
1818
/**
1919
* A pet for sale in the pet store
2020
* @param name
@@ -24,6 +24,7 @@ import java.io.Serializable
2424
* @param tags
2525
* @param status pet status in the store
2626
*/
27+
@Serializable
2728
data class Pet(
2829
val name: kotlin.String,
2930
val photoUrls: kotlin.collections.List<kotlin.String>,
@@ -32,11 +33,8 @@ data class Pet(
3233
val tags: kotlin.collections.List<Tag>? = null,
3334
/* pet status in the store */
3435
val status: Pet.Status? = null
35-
) : Serializable
36+
)
3637
{
37-
companion object {
38-
private const val serialVersionUID: Long = 123
39-
}
4038
/**
4139
* pet status in the store
4240
* Values: available,pending,sold

0 commit comments

Comments
 (0)