diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/KotlinServerCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/KotlinServerCodegen.java index 885449a51354..6473308d2164 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/KotlinServerCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/KotlinServerCodegen.java @@ -294,7 +294,7 @@ public void processOpts() { String gradleBuildFile = "build.gradle"; - if (isJavalin() || isKtor()) { + if (isJavalin() || isKtor2Or3()) { gradleBuildFile = "build.gradle.kts"; } @@ -302,7 +302,7 @@ public void processOpts() { supportingFiles.add(new SupportingFile("settings.gradle.mustache", "", "settings.gradle")); supportingFiles.add(new SupportingFile("gradle.properties", "", "gradle.properties")); - if (isKtor()) { + if (isKtor2Or3()) { additionalProperties.put(Constants.IS_KTOR, true); supportingFiles.add(new SupportingFile("AppMain.kt.mustache", packageFolder, "AppMain.kt")); @@ -445,7 +445,20 @@ private boolean isJavalin() { return Constants.JAVALIN5.equals(library) || Constants.JAVALIN6.equals(library); } - private boolean isKtor() { + private boolean isKtor2Or3() { return Constants.KTOR.equals(library) || Constants.KTOR2.equals(library); } + + /** + * Returns true if latest version of ktor is used. + * + * @return true if latest veresion of ktor is used. + */ + private boolean isKtor() { + return Constants.KTOR.equals(library); + } + + private boolean isKtor2() { + return Constants.KTOR2.equals(library); + } } diff --git a/samples/client/petstore/kotlin-moshi-codegen/src/main/kotlin/org/openapitools/client/infrastructure/Serializer.kt b/samples/client/petstore/kotlin-moshi-codegen/src/main/kotlin/org/openapitools/client/infrastructure/Serializer.kt index 4b9802b38741..e69de29bb2d1 100644 --- a/samples/client/petstore/kotlin-moshi-codegen/src/main/kotlin/org/openapitools/client/infrastructure/Serializer.kt +++ b/samples/client/petstore/kotlin-moshi-codegen/src/main/kotlin/org/openapitools/client/infrastructure/Serializer.kt @@ -1,21 +0,0 @@ -package org.openapitools.client.infrastructure - -import com.squareup.moshi.Moshi - -object Serializer { - @JvmStatic - val moshiBuilder: Moshi.Builder = Moshi.Builder() - .add(OffsetDateTimeAdapter()) - .add(LocalDateTimeAdapter()) - .add(LocalDateAdapter()) - .add(UUIDAdapter()) - .add(ByteArrayAdapter()) - .add(URIAdapter()) - .add(BigDecimalAdapter()) - .add(BigIntegerAdapter()) - - @JvmStatic - val moshi: Moshi by lazy { - moshiBuilder.build() - } -} diff --git a/samples/server/petstore/kotlin-server/ktor2/.openapi-generator/FILES b/samples/server/petstore/kotlin-server/ktor2/.openapi-generator/FILES index 52c6d592e8f2..e574509f97d7 100644 --- a/samples/server/petstore/kotlin-server/ktor2/.openapi-generator/FILES +++ b/samples/server/petstore/kotlin-server/ktor2/.openapi-generator/FILES @@ -1,4 +1,3 @@ -Dockerfile README.md build.gradle.kts gradle.properties diff --git a/samples/server/petstore/kotlin-server/ktor2/src/main/kotlin/org/openapitools/server/apis/PetApi.kt b/samples/server/petstore/kotlin-server/ktor2/src/main/kotlin/org/openapitools/server/apis/PetApi.kt index 7b0482f3d322..fdb4e1552d9d 100644 --- a/samples/server/petstore/kotlin-server/ktor2/src/main/kotlin/org/openapitools/server/apis/PetApi.kt +++ b/samples/server/petstore/kotlin-server/ktor2/src/main/kotlin/org/openapitools/server/apis/PetApi.kt @@ -36,7 +36,7 @@ fun Route.PetApi() { authenticate("petstore_auth") { post { - val principal = call.authentication.principal()!! + val principal = call.authentication.principal() val exampleContentType = "application/json" @@ -70,7 +70,7 @@ fun Route.PetApi() { authenticate("petstore_auth") { delete { - val principal = call.authentication.principal()!! + val principal = call.authentication.principal() call.respond(HttpStatusCode.NotImplemented) @@ -81,7 +81,7 @@ fun Route.PetApi() { authenticate("petstore_auth") { get { - val principal = call.authentication.principal()!! + val principal = call.authentication.principal() val exampleContentType = "application/json" @@ -131,7 +131,7 @@ fun Route.PetApi() { authenticate("petstore_auth") { get { - val principal = call.authentication.principal()!! + val principal = call.authentication.principal() val exampleContentType = "application/json" @@ -181,7 +181,7 @@ fun Route.PetApi() { authenticate("api_key") { get { - val principal = call.authentication.principal()!! + val principal = call.authentication.principal() val exampleContentType = "application/json" @@ -215,7 +215,7 @@ fun Route.PetApi() { authenticate("petstore_auth") { put { - val principal = call.authentication.principal()!! + val principal = call.authentication.principal() val exampleContentType = "application/json" @@ -249,7 +249,7 @@ fun Route.PetApi() { authenticate("petstore_auth") { post { - val principal = call.authentication.principal()!! + val principal = call.authentication.principal() call.respond(HttpStatusCode.NotImplemented) @@ -260,7 +260,7 @@ fun Route.PetApi() { authenticate("petstore_auth") { post { - val principal = call.authentication.principal()!! + val principal = call.authentication.principal() val exampleContentType = "application/json" diff --git a/samples/server/petstore/kotlin-server/ktor2/src/main/kotlin/org/openapitools/server/apis/StoreApi.kt b/samples/server/petstore/kotlin-server/ktor2/src/main/kotlin/org/openapitools/server/apis/StoreApi.kt index fe780f7feb46..baaf8adce0f4 100644 --- a/samples/server/petstore/kotlin-server/ktor2/src/main/kotlin/org/openapitools/server/apis/StoreApi.kt +++ b/samples/server/petstore/kotlin-server/ktor2/src/main/kotlin/org/openapitools/server/apis/StoreApi.kt @@ -40,7 +40,7 @@ fun Route.StoreApi() { authenticate("api_key") { get { - val principal = call.authentication.principal()!! + val principal = call.authentication.principal() call.respond(HttpStatusCode.NotImplemented) @@ -60,7 +60,7 @@ fun Route.StoreApi() { }""" when (exampleContentType) { - "application/json" -> call.respond(gson.fromJson(exampleContentString, empty::class.java)) + "application/json" -> call.respondText(exampleContentType, ContentType.Application.Json) "application/xml" -> call.respondText(exampleContentString, ContentType.Text.Xml) else -> call.respondText(exampleContentString) } @@ -79,7 +79,7 @@ fun Route.StoreApi() { }""" when (exampleContentType) { - "application/json" -> call.respond(gson.fromJson(exampleContentString, empty::class.java)) + "application/json" -> call.respondText(exampleContentType, ContentType.Application.Json) "application/xml" -> call.respondText(exampleContentString, ContentType.Text.Xml) else -> call.respondText(exampleContentString) } diff --git a/samples/server/petstore/kotlin-server/ktor2/src/main/kotlin/org/openapitools/server/apis/UserApi.kt b/samples/server/petstore/kotlin-server/ktor2/src/main/kotlin/org/openapitools/server/apis/UserApi.kt index f3b7a76c39a0..7a62e6dab1c5 100644 --- a/samples/server/petstore/kotlin-server/ktor2/src/main/kotlin/org/openapitools/server/apis/UserApi.kt +++ b/samples/server/petstore/kotlin-server/ktor2/src/main/kotlin/org/openapitools/server/apis/UserApi.kt @@ -35,7 +35,7 @@ fun Route.UserApi() { authenticate("api_key") { post { - val principal = call.authentication.principal()!! + val principal = call.authentication.principal() call.respond(HttpStatusCode.NotImplemented) @@ -46,7 +46,7 @@ fun Route.UserApi() { authenticate("api_key") { post { - val principal = call.authentication.principal()!! + val principal = call.authentication.principal() call.respond(HttpStatusCode.NotImplemented) @@ -57,7 +57,7 @@ fun Route.UserApi() { authenticate("api_key") { post { - val principal = call.authentication.principal()!! + val principal = call.authentication.principal() call.respond(HttpStatusCode.NotImplemented) @@ -68,7 +68,7 @@ fun Route.UserApi() { authenticate("api_key") { delete { - val principal = call.authentication.principal()!! + val principal = call.authentication.principal() call.respond(HttpStatusCode.NotImplemented) @@ -90,7 +90,7 @@ fun Route.UserApi() { }""" when (exampleContentType) { - "application/json" -> call.respond(gson.fromJson(exampleContentString, empty::class.java)) + "application/json" -> call.respondText(exampleContentType, ContentType.Application.Json) "application/xml" -> call.respondText(exampleContentString, ContentType.Text.Xml) else -> call.respondText(exampleContentString) } @@ -105,7 +105,7 @@ fun Route.UserApi() { authenticate("api_key") { get { - val principal = call.authentication.principal()!! + val principal = call.authentication.principal() call.respond(HttpStatusCode.NotImplemented) @@ -116,7 +116,7 @@ fun Route.UserApi() { authenticate("api_key") { put { - val principal = call.authentication.principal()!! + val principal = call.authentication.principal() call.respond(HttpStatusCode.NotImplemented) diff --git a/samples/server/petstore/kotlin-server/ktor2/src/main/kotlin/org/openapitools/server/models/Category.kt b/samples/server/petstore/kotlin-server/ktor2/src/main/kotlin/org/openapitools/server/models/Category.kt index 9d8571921384..7647c2d227e0 100644 --- a/samples/server/petstore/kotlin-server/ktor2/src/main/kotlin/org/openapitools/server/models/Category.kt +++ b/samples/server/petstore/kotlin-server/ktor2/src/main/kotlin/org/openapitools/server/models/Category.kt @@ -12,19 +12,17 @@ package org.openapitools.server.models -import java.io.Serializable +import kotlinx.serialization.Serializable /** * A category for a pet * @param id * @param name */ +@Serializable data class Category( val id: kotlin.Long? = null, val name: kotlin.String? = null -) : Serializable +) { - companion object { - private const val serialVersionUID: Long = 123 - } } diff --git a/samples/server/petstore/kotlin-server/ktor2/src/main/kotlin/org/openapitools/server/models/ModelApiResponse.kt b/samples/server/petstore/kotlin-server/ktor2/src/main/kotlin/org/openapitools/server/models/ModelApiResponse.kt index 5548175d9048..e16d42e86a4e 100644 --- a/samples/server/petstore/kotlin-server/ktor2/src/main/kotlin/org/openapitools/server/models/ModelApiResponse.kt +++ b/samples/server/petstore/kotlin-server/ktor2/src/main/kotlin/org/openapitools/server/models/ModelApiResponse.kt @@ -12,21 +12,19 @@ package org.openapitools.server.models -import java.io.Serializable +import kotlinx.serialization.Serializable /** * Describes the result of uploading an image resource * @param code * @param type * @param message */ +@Serializable data class ModelApiResponse( val code: kotlin.Int? = null, val type: kotlin.String? = null, val message: kotlin.String? = null -) : Serializable +) { - companion object { - private const val serialVersionUID: Long = 123 - } } diff --git a/samples/server/petstore/kotlin-server/ktor2/src/main/kotlin/org/openapitools/server/models/Order.kt b/samples/server/petstore/kotlin-server/ktor2/src/main/kotlin/org/openapitools/server/models/Order.kt index 79dce95e1e47..a75a759f7a93 100644 --- a/samples/server/petstore/kotlin-server/ktor2/src/main/kotlin/org/openapitools/server/models/Order.kt +++ b/samples/server/petstore/kotlin-server/ktor2/src/main/kotlin/org/openapitools/server/models/Order.kt @@ -12,7 +12,7 @@ package org.openapitools.server.models -import java.io.Serializable +import kotlinx.serialization.Serializable /** * An order for a pets from the pet store * @param id @@ -22,6 +22,7 @@ import java.io.Serializable * @param status Order Status * @param complete */ +@Serializable data class Order( val id: kotlin.Long? = null, val petId: kotlin.Long? = null, @@ -30,11 +31,8 @@ data class Order( /* Order Status */ val status: Order.Status? = null, val complete: kotlin.Boolean? = false -) : Serializable +) { - companion object { - private const val serialVersionUID: Long = 123 - } /** * Order Status * Values: placed,approved,delivered diff --git a/samples/server/petstore/kotlin-server/ktor2/src/main/kotlin/org/openapitools/server/models/Pet.kt b/samples/server/petstore/kotlin-server/ktor2/src/main/kotlin/org/openapitools/server/models/Pet.kt index 8b98ce0469c5..8fe934cc3ff3 100644 --- a/samples/server/petstore/kotlin-server/ktor2/src/main/kotlin/org/openapitools/server/models/Pet.kt +++ b/samples/server/petstore/kotlin-server/ktor2/src/main/kotlin/org/openapitools/server/models/Pet.kt @@ -14,7 +14,7 @@ package org.openapitools.server.models import org.openapitools.server.models.Category import org.openapitools.server.models.Tag -import java.io.Serializable +import kotlinx.serialization.Serializable /** * A pet for sale in the pet store * @param name @@ -24,6 +24,7 @@ import java.io.Serializable * @param tags * @param status pet status in the store */ +@Serializable data class Pet( val name: kotlin.String, val photoUrls: kotlin.collections.List, @@ -32,11 +33,8 @@ data class Pet( val tags: kotlin.collections.List? = null, /* pet status in the store */ val status: Pet.Status? = null -) : Serializable +) { - companion object { - private const val serialVersionUID: Long = 123 - } /** * pet status in the store * Values: available,pending,sold diff --git a/samples/server/petstore/kotlin-server/ktor2/src/main/kotlin/org/openapitools/server/models/Tag.kt b/samples/server/petstore/kotlin-server/ktor2/src/main/kotlin/org/openapitools/server/models/Tag.kt index e9626b25c6d1..fae4d9d0ba3c 100644 --- a/samples/server/petstore/kotlin-server/ktor2/src/main/kotlin/org/openapitools/server/models/Tag.kt +++ b/samples/server/petstore/kotlin-server/ktor2/src/main/kotlin/org/openapitools/server/models/Tag.kt @@ -12,19 +12,17 @@ package org.openapitools.server.models -import java.io.Serializable +import kotlinx.serialization.Serializable /** * A tag for a pet * @param id * @param name */ +@Serializable data class Tag( val id: kotlin.Long? = null, val name: kotlin.String? = null -) : Serializable +) { - companion object { - private const val serialVersionUID: Long = 123 - } } diff --git a/samples/server/petstore/kotlin-server/ktor2/src/main/kotlin/org/openapitools/server/models/User.kt b/samples/server/petstore/kotlin-server/ktor2/src/main/kotlin/org/openapitools/server/models/User.kt index fdbdb4e1cff4..af04fd61c1cf 100644 --- a/samples/server/petstore/kotlin-server/ktor2/src/main/kotlin/org/openapitools/server/models/User.kt +++ b/samples/server/petstore/kotlin-server/ktor2/src/main/kotlin/org/openapitools/server/models/User.kt @@ -12,7 +12,7 @@ package org.openapitools.server.models -import java.io.Serializable +import kotlinx.serialization.Serializable /** * A User who is purchasing from the pet store * @param id @@ -24,6 +24,7 @@ import java.io.Serializable * @param phone * @param userStatus User Status */ +@Serializable data class User( val id: kotlin.Long? = null, val username: kotlin.String? = null, @@ -34,10 +35,7 @@ data class User( val phone: kotlin.String? = null, /* User Status */ val userStatus: kotlin.Int? = null -) : Serializable +) { - companion object { - private const val serialVersionUID: Long = 123 - } }