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 65a49682025..885449a5135 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 @@ -236,6 +236,11 @@ public class KotlinServerCodegen extends AbstractKotlinCodegen implements BeanVa LOGGER.info("`library` option is empty. Default to {}", DEFAULT_LIBRARY); } + if (isKtor()) { + typeMapping.put("date-time", "kotlin.String"); + typeMapping.put("DateTime", "kotlin.String"); + } + if (additionalProperties.containsKey(Constants.AUTOMATIC_HEAD_REQUESTS)) { setAutoHeadFeatureEnabled(convertPropertyToBooleanAndWriteBack(Constants.AUTOMATIC_HEAD_REQUESTS)); } else { @@ -298,6 +303,8 @@ public class KotlinServerCodegen extends AbstractKotlinCodegen implements BeanVa supportingFiles.add(new SupportingFile("gradle.properties", "", "gradle.properties")); if (isKtor()) { + additionalProperties.put(Constants.IS_KTOR, true); + supportingFiles.add(new SupportingFile("AppMain.kt.mustache", packageFolder, "AppMain.kt")); supportingFiles.add(new SupportingFile("Configuration.kt.mustache", packageFolder, "Configuration.kt")); @@ -365,6 +372,7 @@ public class KotlinServerCodegen extends AbstractKotlinCodegen implements BeanVa public static final String USE_MUTINY_DESC = "Whether to use Mutiny (should not be used with useCoroutines). This option is currently supported only when using jaxrs-spec library."; public static final String OMIT_GRADLE_WRAPPER = "omitGradleWrapper"; public static final String OMIT_GRADLE_WRAPPER_DESC = "Whether to omit Gradle wrapper for creating a sub project."; + public static final String IS_KTOR = "isKtor"; } @Override @@ -386,6 +394,13 @@ public class KotlinServerCodegen extends AbstractKotlinCodegen implements BeanVa if (operations != null && !Objects.equals(library, Constants.JAXRS_SPEC)) { List ops = operations.getOperation(); ops.forEach(operation -> { + if (isKtor()) { + ArrayList params = new ArrayList<>(); + params.addAll(operation.pathParams); + params.addAll(operation.queryParams); + operation.vendorExtensions.put("ktor-params", params); + } + List responses = operation.responses; if (responses != null) { responses.forEach(resp -> { diff --git a/modules/openapi-generator/src/main/resources/kotlin-server/data_class.mustache b/modules/openapi-generator/src/main/resources/kotlin-server/data_class.mustache index ea72ac7c116..d7c41d201e9 100644 --- a/modules/openapi-generator/src/main/resources/kotlin-server/data_class.mustache +++ b/modules/openapi-generator/src/main/resources/kotlin-server/data_class.mustache @@ -1,11 +1,15 @@ -{{#parcelizeModels}} +{{#isKtor}} +import kotlinx.serialization.Serializable +{{/isKtor}} +{{^isKtor}} + {{#parcelizeModels}} import android.os.Parcelable import kotlinx.parcelize.Parcelize - -{{/parcelizeModels}} -{{#serializableModel}} + {{/parcelizeModels}} + {{#serializableModel}} import java.io.Serializable -{{/serializableModel}} + {{/serializableModel}} +{{/isKtor}} /** * {{{description}}} {{#vars}} @@ -15,21 +19,19 @@ import java.io.Serializable {{#parcelizeModels}} @Parcelize {{/parcelizeModels}} +{{#isKtor}} +@Serializable +{{/isKtor}} {{#hasVars}}data {{/hasVars}}class {{classname}}( {{#requiredVars}} {{>data_class_req_var}}{{^-last}}, {{/-last}}{{/requiredVars}}{{#hasRequired}}{{#hasOptional}}, {{/hasOptional}}{{/hasRequired}}{{#optionalVars}}{{>data_class_opt_var}}{{^-last}}, {{/-last}}{{/optionalVars}} -) {{^serializableModel}}{{#parcelizeModels}} : Parcelable{{/parcelizeModels}}{{/serializableModel}}{{^parcelizeModels}}{{#serializableModel}}: Serializable {{/serializableModel}}{{/parcelizeModels}}{{#parcelizeModels}}{{#serializableModel}} : Parcelable, Serializable {{/serializableModel}}{{/parcelizeModels}} +){{^isKtor}}{{^serializableModel}}{{#parcelizeModels}} : Parcelable{{/parcelizeModels}}{{/serializableModel}}{{^parcelizeModels}}{{#serializableModel}}: Serializable {{/serializableModel}}{{/parcelizeModels}}{{#parcelizeModels}}{{#serializableModel}} : Parcelable, Serializable {{/serializableModel}}{{/parcelizeModels}}{{/isKtor}} {{#vendorExtensions.x-has-data-class-body}} { {{/vendorExtensions.x-has-data-class-body}} -{{#serializableModel}} - companion object { - private const val serialVersionUID: Long = 123 - } -{{/serializableModel}} {{#hasEnums}} {{#vars}} {{#isEnum}} diff --git a/modules/openapi-generator/src/main/resources/kotlin-server/libraries/ktor/ApiKeyAuth.kt.mustache b/modules/openapi-generator/src/main/resources/kotlin-server/libraries/ktor/ApiKeyAuth.kt.mustache index c2cad7fe7a7..542744384a7 100644 --- a/modules/openapi-generator/src/main/resources/kotlin-server/libraries/ktor/ApiKeyAuth.kt.mustache +++ b/modules/openapi-generator/src/main/resources/kotlin-server/libraries/ktor/ApiKeyAuth.kt.mustache @@ -1,4 +1,4 @@ -package org.openapitools.server.infrastructure +package {{packageName}}.infrastructure import io.ktor.http.auth.* import io.ktor.server.application.* diff --git a/modules/openapi-generator/src/main/resources/kotlin-server/libraries/ktor/AppMain.kt.mustache b/modules/openapi-generator/src/main/resources/kotlin-server/libraries/ktor/AppMain.kt.mustache index 5ba3775c92c..02f870ac430 100644 --- a/modules/openapi-generator/src/main/resources/kotlin-server/libraries/ktor/AppMain.kt.mustache +++ b/modules/openapi-generator/src/main/resources/kotlin-server/libraries/ktor/AppMain.kt.mustache @@ -1,7 +1,6 @@ package {{packageName}} import io.ktor.server.application.* -import io.ktor.serialization.gson.* import io.ktor.http.* {{#featureResources}} import io.ktor.server.resources.* @@ -30,24 +29,17 @@ import java.util.concurrent.TimeUnit {{/featureMetrics}} import io.ktor.server.routing.* {{#hasAuthMethods}} +import io.ktor.serialization.kotlinx.json.json import com.typesafe.config.ConfigFactory import io.ktor.client.HttpClient import io.ktor.client.engine.apache.Apache import io.ktor.server.config.HoconApplicationConfig import io.ktor.server.auth.* -import org.openapitools.server.infrastructure.* +import {{packageName}}.infrastructure.* {{/hasAuthMethods}} {{#generateApis}}{{#apiInfo}}{{#apis}}import {{apiPackage}}.{{classname}} {{/apis}}{{/apiInfo}}{{/generateApis}} -{{#hasAuthMethods}} -internal val settings = HoconApplicationConfig(ConfigFactory.defaultApplication(HTTP::class.java.classLoader)) - -object HTTP { - val client = HttpClient(Apache) -} -{{/hasAuthMethods}} - fun Application.main() { install(DefaultHeaders) {{#featureMetrics}} @@ -62,7 +54,7 @@ fun Application.main() { {{/featureMetrics}} {{#generateApis}} install(ContentNegotiation) { - register(ContentType.Application.Json, GsonConverter()) + json() } {{#featureAutoHead}} install(AutoHeadResponse) // see https://ktor.io/docs/autoheadresponse.html @@ -125,7 +117,7 @@ fun Application.main() { {{/authMethods}} } {{/hasAuthMethods}} - install(Routing) { + routing { {{#apiInfo}} {{#apis}} {{#operations}} @@ -134,6 +126,5 @@ fun Application.main() { {{/apis}} {{/apiInfo}} } - {{/generateApis}} } diff --git a/modules/openapi-generator/src/main/resources/kotlin-server/libraries/ktor/Paths.kt.mustache b/modules/openapi-generator/src/main/resources/kotlin-server/libraries/ktor/Paths.kt.mustache index a575ea67877..37369e01463 100644 --- a/modules/openapi-generator/src/main/resources/kotlin-server/libraries/ktor/Paths.kt.mustache +++ b/modules/openapi-generator/src/main/resources/kotlin-server/libraries/ktor/Paths.kt.mustache @@ -18,10 +18,10 @@ object Paths { {{#allParams}}* @param {{paramName}} {{description}} {{^required}}(optional{{#defaultValue}}, default to {{{.}}}{{/defaultValue}}){{/required}} {{/allParams}}*/ {{#hasParams}} - @Serializable @Resource("{{{path}}}") class {{operationId}}({{#allParams}}val {{paramName}}: {{{dataType}}}{{^required}}? = null{{/required}}{{#required}}{{#isNullable}}?{{/isNullable}}{{/required}}{{^-last}}, {{/-last}}{{/allParams}}) + @Resource("{{{path}}}") class {{operationId}}({{#vendorExtensions.ktor-params}}val {{paramName}}: {{{dataType}}}{{^required}}? = null{{/required}}{{#required}}{{#isNullable}}?{{/isNullable}}{{/required}}{{^-last}}, {{/-last}}{{/vendorExtensions.ktor-params}}) {{/hasParams}} {{^hasParams}} - @Serializable @Resource("{{{path}}}") class {{operationId}} + @Resource("{{{path}}}") class {{operationId}} {{/hasParams}} {{/operation}} diff --git a/modules/openapi-generator/src/main/resources/kotlin-server/libraries/ktor/_principal.mustache b/modules/openapi-generator/src/main/resources/kotlin-server/libraries/ktor/_principal.mustache index 17c32a4c40a..ad01dd85aa7 100644 --- a/modules/openapi-generator/src/main/resources/kotlin-server/libraries/ktor/_principal.mustache +++ b/modules/openapi-generator/src/main/resources/kotlin-server/libraries/ktor/_principal.mustache @@ -1,10 +1,10 @@ {{#authMethods}} {{#isBasicBasic}} -val principal = call.authentication.principal()!! +val principal = call.authentication.principal() {{/isBasicBasic}}{{^isBasicBasic}}{{#isApiKey}} -val principal = call.authentication.principal()!! +val principal = call.authentication.principal() {{/isApiKey}}{{^isApiKey}}{{#isOAuth}} -val principal = call.authentication.principal()!! +val principal = call.authentication.principal() {{/isOAuth}}{{^isOAuth}} val principal = null!! {{/isOAuth}}{{/isApiKey}}{{/isBasicBasic}} diff --git a/modules/openapi-generator/src/main/resources/kotlin-server/libraries/ktor/_response.mustache b/modules/openapi-generator/src/main/resources/kotlin-server/libraries/ktor/_response.mustache index 931dad98f5e..323f266e825 100644 --- a/modules/openapi-generator/src/main/resources/kotlin-server/libraries/ktor/_response.mustache +++ b/modules/openapi-generator/src/main/resources/kotlin-server/libraries/ktor/_response.mustache @@ -2,7 +2,7 @@ val exampleContentType = "{{{contentType}}}" val exampleContentString = """{{&example}}""" 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) } \ No newline at end of file diff --git a/modules/openapi-generator/src/main/resources/kotlin-server/libraries/ktor/api.mustache b/modules/openapi-generator/src/main/resources/kotlin-server/libraries/ktor/api.mustache index eb1da3bd527..885ba6ae50d 100644 --- a/modules/openapi-generator/src/main/resources/kotlin-server/libraries/ktor/api.mustache +++ b/modules/openapi-generator/src/main/resources/kotlin-server/libraries/ktor/api.mustache @@ -1,7 +1,6 @@ {{>licenseInfo}} package {{apiPackage}} -import com.google.gson.Gson import io.ktor.http.* import io.ktor.server.application.* import io.ktor.server.auth.* @@ -23,7 +22,6 @@ import {{packageName}}.infrastructure.ApiPrincipal {{#operations}} fun Route.{{classname}}() { - val gson = Gson() val empty = mutableMapOf() {{#operation}} diff --git a/modules/openapi-generator/src/main/resources/kotlin-server/libraries/ktor/build.gradle.kts.mustache b/modules/openapi-generator/src/main/resources/kotlin-server/libraries/ktor/build.gradle.kts.mustache index 3dc3dd38f04..1fa61c071ea 100644 --- a/modules/openapi-generator/src/main/resources/kotlin-server/libraries/ktor/build.gradle.kts.mustache +++ b/modules/openapi-generator/src/main/resources/kotlin-server/libraries/ktor/build.gradle.kts.mustache @@ -7,7 +7,8 @@ version = "{{artifactVersion}}" plugins { kotlin("jvm") version "2.0.20" - id("io.ktor.plugin") version "2.3.12" + application + kotlin("plugin.serialization") version "2.0.20" } application { @@ -22,6 +23,7 @@ repositories { } dependencies { + implementation(platform("io.ktor:ktor-bom:3.0.2")) implementation("ch.qos.logback:logback-classic:$logback_version") {{#hasAuthMethods}} implementation("com.typesafe:config:1.4.1") @@ -35,7 +37,7 @@ dependencies { {{/featureAutoHead}} implementation("io.ktor:ktor-server-default-headers") implementation("io.ktor:ktor-server-content-negotiation") - implementation("io.ktor:ktor-serialization-gson") + implementation("io.ktor:ktor-serialization-kotlinx-json") {{#featureResources}} implementation("io.ktor:ktor-server-resources") {{/featureResources}} diff --git a/modules/openapi-generator/src/main/resources/kotlin-server/libraries/ktor/gradle.properties b/modules/openapi-generator/src/main/resources/kotlin-server/libraries/ktor/gradle.properties index d507b58c1c8..fb877a9edd2 100644 --- a/modules/openapi-generator/src/main/resources/kotlin-server/libraries/ktor/gradle.properties +++ b/modules/openapi-generator/src/main/resources/kotlin-server/libraries/ktor/gradle.properties @@ -1,4 +1,4 @@ kotlin.code.style=official -ktor_version=2.3.12 +ktor_version=3.0.2 kotlin_version=2.0.20 logback_version=1.4.14 \ No newline at end of file diff --git a/samples/server/petstore/kotlin-server-modelMutable/build.gradle b/samples/server/petstore/kotlin-server-modelMutable/build.gradle deleted file mode 100644 index bd883dc2291..00000000000 --- a/samples/server/petstore/kotlin-server-modelMutable/build.gradle +++ /dev/null @@ -1,74 +0,0 @@ -group "org.openapitools" -version "1.0.0" - -wrapper { - gradleVersion = "7.4.2" - distributionUrl = "https://services.gradle.org/distributions/gradle-$gradleVersion-all.zip" -} - -buildscript { - ext.kotlin_version = "1.7.20" - ext.ktor_version = "2.2.1" - ext.shadow_version = "6.1.0" - - repositories { - maven { url "https://repo1.maven.org/maven2" } - maven { url "https://plugins.gradle.org/m2/" } - } - dependencies { - classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version") - classpath("com.github.jengelman.gradle.plugins:shadow:$shadow_version") - } -} - -apply plugin: "java" -apply plugin: "kotlin" -apply plugin: "application" - -mainClassName = "io.ktor.server.netty.DevelopmentEngine" - -// Initialization order with shadow 2.0.1 and Gradle 6.9 is weird. -// See https://github.com/johnrengelman/shadow/issues/336#issuecomment-355402508 -apply plugin: "com.github.johnrengelman.shadow" - -sourceCompatibility = 1.8 - -compileKotlin { - kotlinOptions.jvmTarget = "1.8" -} - -compileTestKotlin { - kotlinOptions.jvmTarget = "1.8" -} - -shadowJar { - baseName = "kotlin-server" - classifier = null - version = null -} - -repositories { - maven { setUrl("https://repo1.maven.org/maven2") } - maven { setUrl("https://dl.bintray.com/kotlin/ktor") } - maven { setUrl("https://dl.bintray.com/kotlin/kotlinx") } -} - -dependencies { - implementation("org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version") - implementation("ch.qos.logback:logback-classic:1.2.9") - implementation("com.typesafe:config:1.4.1") - implementation("io.ktor:ktor-server-auth:$ktor_version") - implementation("io.ktor:ktor-client-apache:$ktor_version") - implementation("io.ktor:ktor-server-auto-head-response:$ktor_version") - implementation("io.ktor:ktor-server-default-headers:$ktor_version") - implementation("io.ktor:ktor-server-content-negotiation:$ktor_version") - implementation("io.ktor:ktor-serialization-gson:$ktor_version") - implementation("io.ktor:ktor-server-resources:$ktor_version") - implementation("io.ktor:ktor-server-hsts:$ktor_version") - implementation("io.ktor:ktor-server-compression:$ktor_version") - implementation("io.dropwizard.metrics:metrics-core:4.1.18") - implementation("io.ktor:ktor-server-metrics:$ktor_version") - implementation("io.ktor:ktor-server-netty:$ktor_version") - - testImplementation("junit:junit:4.13.2") -} diff --git a/samples/server/petstore/kotlin-server-modelMutable/build.gradle.kts b/samples/server/petstore/kotlin-server-modelMutable/build.gradle.kts index fb35b77164a..1e91d49feaf 100644 --- a/samples/server/petstore/kotlin-server-modelMutable/build.gradle.kts +++ b/samples/server/petstore/kotlin-server-modelMutable/build.gradle.kts @@ -7,7 +7,8 @@ version = "1.0.0" plugins { kotlin("jvm") version "2.0.20" - id("io.ktor.plugin") version "2.3.12" + application + kotlin("plugin.serialization") version "2.0.20" } application { @@ -22,6 +23,7 @@ repositories { } dependencies { + implementation(platform("io.ktor:ktor-bom:3.0.2")) implementation("ch.qos.logback:logback-classic:$logback_version") implementation("com.typesafe:config:1.4.1") implementation("io.ktor:ktor-server-auth") @@ -29,7 +31,7 @@ dependencies { implementation("io.ktor:ktor-server-auto-head-response") implementation("io.ktor:ktor-server-default-headers") implementation("io.ktor:ktor-server-content-negotiation") - implementation("io.ktor:ktor-serialization-gson") + implementation("io.ktor:ktor-serialization-kotlinx-json") implementation("io.ktor:ktor-server-resources") implementation("io.ktor:ktor-server-hsts") implementation("io.ktor:ktor-server-compression") diff --git a/samples/server/petstore/kotlin-server-modelMutable/gradle.properties b/samples/server/petstore/kotlin-server-modelMutable/gradle.properties index d507b58c1c8..fb877a9edd2 100644 --- a/samples/server/petstore/kotlin-server-modelMutable/gradle.properties +++ b/samples/server/petstore/kotlin-server-modelMutable/gradle.properties @@ -1,4 +1,4 @@ kotlin.code.style=official -ktor_version=2.3.12 +ktor_version=3.0.2 kotlin_version=2.0.20 logback_version=1.4.14 \ No newline at end of file diff --git a/samples/server/petstore/kotlin-server-modelMutable/src/main/kotlin/org/openapitools/server/AppMain.kt b/samples/server/petstore/kotlin-server-modelMutable/src/main/kotlin/org/openapitools/server/AppMain.kt index 2de9d58ce93..4053d223ac9 100644 --- a/samples/server/petstore/kotlin-server-modelMutable/src/main/kotlin/org/openapitools/server/AppMain.kt +++ b/samples/server/petstore/kotlin-server-modelMutable/src/main/kotlin/org/openapitools/server/AppMain.kt @@ -1,7 +1,6 @@ package org.openapitools.server import io.ktor.server.application.* -import io.ktor.serialization.gson.* import io.ktor.http.* import io.ktor.server.resources.* import io.ktor.server.plugins.autohead.* @@ -13,6 +12,7 @@ import com.codahale.metrics.Slf4jReporter import io.ktor.server.metrics.dropwizard.* import java.util.concurrent.TimeUnit import io.ktor.server.routing.* +import io.ktor.serialization.kotlinx.json.json import com.typesafe.config.ConfigFactory import io.ktor.client.HttpClient import io.ktor.client.engine.apache.Apache @@ -24,12 +24,6 @@ import org.openapitools.server.apis.StoreApi import org.openapitools.server.apis.UserApi -internal val settings = HoconApplicationConfig(ConfigFactory.defaultApplication(HTTP::class.java.classLoader)) - -object HTTP { - val client = HttpClient(Apache) -} - fun Application.main() { install(DefaultHeaders) install(DropwizardMetrics) { @@ -41,7 +35,7 @@ fun Application.main() { reporter.start(10, TimeUnit.SECONDS) } install(ContentNegotiation) { - register(ContentType.Application.Json, GsonConverter()) + json() } install(AutoHeadResponse) // see https://ktor.io/docs/autoheadresponse.html install(Compression, ApplicationCompressionConfiguration()) // see https://ktor.io/docs/compression.html @@ -66,10 +60,9 @@ fun Application.main() { } } } - install(Routing) { + routing { PetApi() StoreApi() UserApi() } - } diff --git a/samples/server/petstore/kotlin-server-modelMutable/src/main/kotlin/org/openapitools/server/Paths.kt b/samples/server/petstore/kotlin-server-modelMutable/src/main/kotlin/org/openapitools/server/Paths.kt index effea4faa7a..c9a28c0ace5 100644 --- a/samples/server/petstore/kotlin-server-modelMutable/src/main/kotlin/org/openapitools/server/Paths.kt +++ b/samples/server/petstore/kotlin-server-modelMutable/src/main/kotlin/org/openapitools/server/Paths.kt @@ -21,7 +21,7 @@ object Paths { * * @param body Pet object that needs to be added to the store */ - @Serializable @Resource("/pet") class addPet(val body: Pet) + @Resource("/pet") class addPet() /** * Deletes a pet @@ -29,35 +29,35 @@ object Paths { * @param petId Pet id to delete * @param apiKey (optional) */ - @Serializable @Resource("/pet/{petId}") class deletePet(val petId: kotlin.Long, val apiKey: kotlin.String? = null) + @Resource("/pet/{petId}") class deletePet(val petId: kotlin.Long) /** * Finds Pets by status * Multiple status values can be provided with comma separated strings * @param status Status values that need to be considered for filter */ - @Serializable @Resource("/pet/findByStatus") class findPetsByStatus(val status: kotlin.collections.MutableList) + @Resource("/pet/findByStatus") class findPetsByStatus(val status: kotlin.collections.MutableList) /** * Finds Pets by tags * Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing. * @param tags Tags to filter by */ - @Serializable @Resource("/pet/findByTags") class findPetsByTags(val tags: kotlin.collections.MutableList) + @Resource("/pet/findByTags") class findPetsByTags(val tags: kotlin.collections.MutableList) /** * Find pet by ID * Returns a single pet * @param petId ID of pet to return */ - @Serializable @Resource("/pet/{petId}") class getPetById(val petId: kotlin.Long) + @Resource("/pet/{petId}") class getPetById(val petId: kotlin.Long) /** * Update an existing pet * * @param body Pet object that needs to be added to the store */ - @Serializable @Resource("/pet") class updatePet(val body: Pet) + @Resource("/pet") class updatePet() /** * Updates a pet in the store with form data @@ -66,7 +66,7 @@ object Paths { * @param name Updated name of the pet (optional) * @param status Updated status of the pet (optional) */ - @Serializable @Resource("/pet/{petId}") class updatePetWithForm(val petId: kotlin.Long, val name: kotlin.String? = null, val status: kotlin.String? = null) + @Resource("/pet/{petId}") class updatePetWithForm(val petId: kotlin.Long) /** * uploads an image @@ -75,69 +75,69 @@ object Paths { * @param additionalMetadata Additional data to pass to server (optional) * @param file file to upload (optional) */ - @Serializable @Resource("/pet/{petId}/uploadImage") class uploadFile(val petId: kotlin.Long, val additionalMetadata: kotlin.String? = null, val file: java.io.File? = null) + @Resource("/pet/{petId}/uploadImage") class uploadFile(val petId: kotlin.Long) /** * Delete purchase order by ID * For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors * @param orderId ID of the order that needs to be deleted */ - @Serializable @Resource("/store/order/{orderId}") class deleteOrder(val orderId: kotlin.String) + @Resource("/store/order/{orderId}") class deleteOrder(val orderId: kotlin.String) /** * Returns pet inventories by status * Returns a map of status codes to quantities */ - @Serializable @Resource("/store/inventory") class getInventory + @Resource("/store/inventory") class getInventory /** * Find purchase order by ID * For valid response try integer IDs with value <= 5 or > 10. Other values will generate exceptions * @param orderId ID of pet that needs to be fetched */ - @Serializable @Resource("/store/order/{orderId}") class getOrderById(val orderId: kotlin.Long) + @Resource("/store/order/{orderId}") class getOrderById(val orderId: kotlin.Long) /** * Place an order for a pet * * @param body order placed for purchasing the pet */ - @Serializable @Resource("/store/order") class placeOrder(val body: Order) + @Resource("/store/order") class placeOrder() /** * Create user * This can only be done by the logged in user. * @param body Created user object */ - @Serializable @Resource("/user") class createUser(val body: User) + @Resource("/user") class createUser() /** * Creates list of users with given input array * * @param body List of user object */ - @Serializable @Resource("/user/createWithArray") class createUsersWithArrayInput(val body: kotlin.collections.MutableList) + @Resource("/user/createWithArray") class createUsersWithArrayInput() /** * Creates list of users with given input array * * @param body List of user object */ - @Serializable @Resource("/user/createWithList") class createUsersWithListInput(val body: kotlin.collections.MutableList) + @Resource("/user/createWithList") class createUsersWithListInput() /** * Delete user * This can only be done by the logged in user. * @param username The name that needs to be deleted */ - @Serializable @Resource("/user/{username}") class deleteUser(val username: kotlin.String) + @Resource("/user/{username}") class deleteUser(val username: kotlin.String) /** * Get user by user name * * @param username The name that needs to be fetched. Use user1 for testing. */ - @Serializable @Resource("/user/{username}") class getUserByName(val username: kotlin.String) + @Resource("/user/{username}") class getUserByName(val username: kotlin.String) /** * Logs user into the system @@ -145,13 +145,13 @@ object Paths { * @param username The user name for login * @param password The password for login in clear text */ - @Serializable @Resource("/user/login") class loginUser(val username: kotlin.String, val password: kotlin.String) + @Resource("/user/login") class loginUser(val username: kotlin.String, val password: kotlin.String) /** * Logs out current logged in user session * */ - @Serializable @Resource("/user/logout") class logoutUser + @Resource("/user/logout") class logoutUser /** * Updated user @@ -159,6 +159,6 @@ object Paths { * @param username name that need to be deleted * @param body Updated user object */ - @Serializable @Resource("/user/{username}") class updateUser(val username: kotlin.String, val body: User) + @Resource("/user/{username}") class updateUser(val username: kotlin.String) } diff --git a/samples/server/petstore/kotlin-server-modelMutable/src/main/kotlin/org/openapitools/server/apis/PetApi.kt b/samples/server/petstore/kotlin-server-modelMutable/src/main/kotlin/org/openapitools/server/apis/PetApi.kt index d95a4b4d088..b72ec0d72ce 100644 --- a/samples/server/petstore/kotlin-server-modelMutable/src/main/kotlin/org/openapitools/server/apis/PetApi.kt +++ b/samples/server/petstore/kotlin-server-modelMutable/src/main/kotlin/org/openapitools/server/apis/PetApi.kt @@ -11,7 +11,6 @@ */ package org.openapitools.server.apis -import com.google.gson.Gson import io.ktor.http.* import io.ktor.server.application.* import io.ktor.server.auth.* @@ -30,13 +29,12 @@ import org.openapitools.server.models.ModelApiResponse import org.openapitools.server.models.Pet fun Route.PetApi() { - val gson = Gson() val empty = mutableMapOf() authenticate("petstore_auth") { post { - val principal = call.authentication.principal()!! + val principal = call.authentication.principal() call.respond(HttpStatusCode.NotImplemented) @@ -47,7 +45,7 @@ fun Route.PetApi() { authenticate("petstore_auth") { delete { - val principal = call.authentication.principal()!! + val principal = call.authentication.principal() call.respond(HttpStatusCode.NotImplemented) @@ -58,7 +56,7 @@ fun Route.PetApi() { authenticate("petstore_auth") { get { - val principal = call.authentication.principal()!! + val principal = call.authentication.principal() val exampleContentType = "application/json" @@ -97,7 +95,7 @@ fun Route.PetApi() { } ]""" 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) } @@ -108,7 +106,7 @@ fun Route.PetApi() { authenticate("petstore_auth") { get { - val principal = call.authentication.principal()!! + val principal = call.authentication.principal() val exampleContentType = "application/json" @@ -147,7 +145,7 @@ fun Route.PetApi() { } ]""" 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) } @@ -158,7 +156,7 @@ fun Route.PetApi() { authenticate("api_key") { get { - val principal = call.authentication.principal()!! + val principal = call.authentication.principal() val exampleContentType = "application/json" @@ -181,7 +179,7 @@ fun Route.PetApi() { }""" 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) } @@ -192,7 +190,7 @@ fun Route.PetApi() { authenticate("petstore_auth") { put { - val principal = call.authentication.principal()!! + val principal = call.authentication.principal() call.respond(HttpStatusCode.NotImplemented) @@ -203,7 +201,7 @@ fun Route.PetApi() { authenticate("petstore_auth") { post { - val principal = call.authentication.principal()!! + val principal = call.authentication.principal() call.respond(HttpStatusCode.NotImplemented) @@ -214,7 +212,7 @@ fun Route.PetApi() { authenticate("petstore_auth") { post { - val principal = call.authentication.principal()!! + val principal = call.authentication.principal() val exampleContentType = "application/json" @@ -225,7 +223,7 @@ fun Route.PetApi() { }""" 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-modelMutable/src/main/kotlin/org/openapitools/server/apis/StoreApi.kt b/samples/server/petstore/kotlin-server-modelMutable/src/main/kotlin/org/openapitools/server/apis/StoreApi.kt index fe780f7feb4..4a439577840 100644 --- a/samples/server/petstore/kotlin-server-modelMutable/src/main/kotlin/org/openapitools/server/apis/StoreApi.kt +++ b/samples/server/petstore/kotlin-server-modelMutable/src/main/kotlin/org/openapitools/server/apis/StoreApi.kt @@ -11,7 +11,6 @@ */ package org.openapitools.server.apis -import com.google.gson.Gson import io.ktor.http.* import io.ktor.server.application.* import io.ktor.server.auth.* @@ -29,7 +28,6 @@ import org.openapitools.server.infrastructure.ApiPrincipal import org.openapitools.server.models.Order fun Route.StoreApi() { - val gson = Gson() val empty = mutableMapOf() delete { @@ -40,7 +38,7 @@ fun Route.StoreApi() { authenticate("api_key") { get { - val principal = call.authentication.principal()!! + val principal = call.authentication.principal() call.respond(HttpStatusCode.NotImplemented) @@ -60,7 +58,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 +77,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-modelMutable/src/main/kotlin/org/openapitools/server/apis/UserApi.kt b/samples/server/petstore/kotlin-server-modelMutable/src/main/kotlin/org/openapitools/server/apis/UserApi.kt index ccf0509fca2..299f743e141 100644 --- a/samples/server/petstore/kotlin-server-modelMutable/src/main/kotlin/org/openapitools/server/apis/UserApi.kt +++ b/samples/server/petstore/kotlin-server-modelMutable/src/main/kotlin/org/openapitools/server/apis/UserApi.kt @@ -11,7 +11,6 @@ */ package org.openapitools.server.apis -import com.google.gson.Gson import io.ktor.http.* import io.ktor.server.application.* import io.ktor.server.auth.* @@ -29,7 +28,6 @@ import org.openapitools.server.infrastructure.ApiPrincipal import org.openapitools.server.models.User fun Route.UserApi() { - val gson = Gson() val empty = mutableMapOf() post { @@ -66,7 +64,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) } diff --git a/samples/server/petstore/kotlin-server-modelMutable/src/main/kotlin/org/openapitools/server/models/Category.kt b/samples/server/petstore/kotlin-server-modelMutable/src/main/kotlin/org/openapitools/server/models/Category.kt index 949cf3a7a5a..82813cdbff3 100644 --- a/samples/server/petstore/kotlin-server-modelMutable/src/main/kotlin/org/openapitools/server/models/Category.kt +++ b/samples/server/petstore/kotlin-server-modelMutable/src/main/kotlin/org/openapitools/server/models/Category.kt @@ -12,13 +12,15 @@ package org.openapitools.server.models +import kotlinx.serialization.Serializable /** * A category for a pet * @param id * @param name */ +@Serializable data class Category( var id: kotlin.Long? = null, var name: kotlin.String? = null -) +) diff --git a/samples/server/petstore/kotlin-server-modelMutable/src/main/kotlin/org/openapitools/server/models/ModelApiResponse.kt b/samples/server/petstore/kotlin-server-modelMutable/src/main/kotlin/org/openapitools/server/models/ModelApiResponse.kt index 7a0ac1f246d..dcc1ed13510 100644 --- a/samples/server/petstore/kotlin-server-modelMutable/src/main/kotlin/org/openapitools/server/models/ModelApiResponse.kt +++ b/samples/server/petstore/kotlin-server-modelMutable/src/main/kotlin/org/openapitools/server/models/ModelApiResponse.kt @@ -12,15 +12,17 @@ package org.openapitools.server.models +import kotlinx.serialization.Serializable /** * Describes the result of uploading an image resource * @param code * @param type * @param message */ +@Serializable data class ModelApiResponse( var code: kotlin.Int? = null, var type: kotlin.String? = null, var message: kotlin.String? = null -) +) diff --git a/samples/server/petstore/kotlin-server-modelMutable/src/main/kotlin/org/openapitools/server/models/Order.kt b/samples/server/petstore/kotlin-server-modelMutable/src/main/kotlin/org/openapitools/server/models/Order.kt index c691b645c43..d5a9b56748f 100644 --- a/samples/server/petstore/kotlin-server-modelMutable/src/main/kotlin/org/openapitools/server/models/Order.kt +++ b/samples/server/petstore/kotlin-server-modelMutable/src/main/kotlin/org/openapitools/server/models/Order.kt @@ -12,6 +12,7 @@ package org.openapitools.server.models +import kotlinx.serialization.Serializable /** * An order for a pets from the pet store * @param id @@ -21,15 +22,16 @@ package org.openapitools.server.models * @param status Order Status * @param complete */ +@Serializable data class Order( var id: kotlin.Long? = null, var petId: kotlin.Long? = null, var quantity: kotlin.Int? = null, - var shipDate: java.time.OffsetDateTime? = null, + var shipDate: kotlin.String? = null, /* Order Status */ var status: Order.Status? = null, var complete: kotlin.Boolean? = false -) +) { /** * Order Status diff --git a/samples/server/petstore/kotlin-server-modelMutable/src/main/kotlin/org/openapitools/server/models/Pet.kt b/samples/server/petstore/kotlin-server-modelMutable/src/main/kotlin/org/openapitools/server/models/Pet.kt index e12a818c1b5..e9095e0a7c6 100644 --- a/samples/server/petstore/kotlin-server-modelMutable/src/main/kotlin/org/openapitools/server/models/Pet.kt +++ b/samples/server/petstore/kotlin-server-modelMutable/src/main/kotlin/org/openapitools/server/models/Pet.kt @@ -14,6 +14,7 @@ package org.openapitools.server.models import org.openapitools.server.models.Category import org.openapitools.server.models.Tag +import kotlinx.serialization.Serializable /** * A pet for sale in the pet store * @param name @@ -23,6 +24,7 @@ import org.openapitools.server.models.Tag * @param tags * @param status pet status in the store */ +@Serializable data class Pet( var name: kotlin.String, var photoUrls: kotlin.collections.MutableList, @@ -31,7 +33,7 @@ data class Pet( var tags: kotlin.collections.MutableList? = null, /* pet status in the store */ var status: Pet.Status? = null -) +) { /** * pet status in the store diff --git a/samples/server/petstore/kotlin-server-modelMutable/src/main/kotlin/org/openapitools/server/models/Tag.kt b/samples/server/petstore/kotlin-server-modelMutable/src/main/kotlin/org/openapitools/server/models/Tag.kt index 99e770cd7b9..26a16d0acc3 100644 --- a/samples/server/petstore/kotlin-server-modelMutable/src/main/kotlin/org/openapitools/server/models/Tag.kt +++ b/samples/server/petstore/kotlin-server-modelMutable/src/main/kotlin/org/openapitools/server/models/Tag.kt @@ -12,13 +12,15 @@ package org.openapitools.server.models +import kotlinx.serialization.Serializable /** * A tag for a pet * @param id * @param name */ +@Serializable data class Tag( var id: kotlin.Long? = null, var name: kotlin.String? = null -) +) diff --git a/samples/server/petstore/kotlin-server-modelMutable/src/main/kotlin/org/openapitools/server/models/User.kt b/samples/server/petstore/kotlin-server-modelMutable/src/main/kotlin/org/openapitools/server/models/User.kt index e63e2596d4b..57f4e607386 100644 --- a/samples/server/petstore/kotlin-server-modelMutable/src/main/kotlin/org/openapitools/server/models/User.kt +++ b/samples/server/petstore/kotlin-server-modelMutable/src/main/kotlin/org/openapitools/server/models/User.kt @@ -12,6 +12,7 @@ package org.openapitools.server.models +import kotlinx.serialization.Serializable /** * A User who is purchasing from the pet store * @param id @@ -23,6 +24,7 @@ package org.openapitools.server.models * @param phone * @param userStatus User Status */ +@Serializable data class User( var id: kotlin.Long? = null, var username: kotlin.String? = null, @@ -33,5 +35,5 @@ data class User( var phone: kotlin.String? = null, /* User Status */ var userStatus: kotlin.Int? = null -) +) diff --git a/samples/server/petstore/kotlin-server-required-and-nullable-properties/src/main/kotlin/org/openapitools/server/models/Pet.kt b/samples/server/petstore/kotlin-server-required-and-nullable-properties/src/main/kotlin/org/openapitools/server/models/Pet.kt index 8dddb90062b..072781fb8b9 100644 --- a/samples/server/petstore/kotlin-server-required-and-nullable-properties/src/main/kotlin/org/openapitools/server/models/Pet.kt +++ b/samples/server/petstore/kotlin-server-required-and-nullable-properties/src/main/kotlin/org/openapitools/server/models/Pet.kt @@ -24,5 +24,5 @@ data class Pet( val nullableRequired: kotlin.String?, val nullableNotRequired: kotlin.String? = null, val notNullableNotRequired: kotlin.String? = null -) +) diff --git a/samples/server/petstore/kotlin-server/javalin-6/src/main/kotlin/org/openapitools/server/models/Category.kt b/samples/server/petstore/kotlin-server/javalin-6/src/main/kotlin/org/openapitools/server/models/Category.kt index 71098339bc8..852f443a304 100644 --- a/samples/server/petstore/kotlin-server/javalin-6/src/main/kotlin/org/openapitools/server/models/Category.kt +++ b/samples/server/petstore/kotlin-server/javalin-6/src/main/kotlin/org/openapitools/server/models/Category.kt @@ -20,5 +20,5 @@ package org.openapitools.server.models data class Category( val id: kotlin.Long? = null, val name: kotlin.String? = null -) +) diff --git a/samples/server/petstore/kotlin-server/javalin-6/src/main/kotlin/org/openapitools/server/models/ModelApiResponse.kt b/samples/server/petstore/kotlin-server/javalin-6/src/main/kotlin/org/openapitools/server/models/ModelApiResponse.kt index 9e80c50c660..94b9ddf7b92 100644 --- a/samples/server/petstore/kotlin-server/javalin-6/src/main/kotlin/org/openapitools/server/models/ModelApiResponse.kt +++ b/samples/server/petstore/kotlin-server/javalin-6/src/main/kotlin/org/openapitools/server/models/ModelApiResponse.kt @@ -22,5 +22,5 @@ data class ModelApiResponse( val code: kotlin.Int? = null, val type: kotlin.String? = null, val message: kotlin.String? = null -) +) diff --git a/samples/server/petstore/kotlin-server/javalin-6/src/main/kotlin/org/openapitools/server/models/Order.kt b/samples/server/petstore/kotlin-server/javalin-6/src/main/kotlin/org/openapitools/server/models/Order.kt index be802beb8d8..48c1ef32bd3 100644 --- a/samples/server/petstore/kotlin-server/javalin-6/src/main/kotlin/org/openapitools/server/models/Order.kt +++ b/samples/server/petstore/kotlin-server/javalin-6/src/main/kotlin/org/openapitools/server/models/Order.kt @@ -29,7 +29,7 @@ data class Order( /* Order Status */ val status: Order.Status? = null, val complete: kotlin.Boolean? = false -) +) { /** * Order Status diff --git a/samples/server/petstore/kotlin-server/javalin-6/src/main/kotlin/org/openapitools/server/models/Pet.kt b/samples/server/petstore/kotlin-server/javalin-6/src/main/kotlin/org/openapitools/server/models/Pet.kt index e5723fedd63..0a0c9a01035 100644 --- a/samples/server/petstore/kotlin-server/javalin-6/src/main/kotlin/org/openapitools/server/models/Pet.kt +++ b/samples/server/petstore/kotlin-server/javalin-6/src/main/kotlin/org/openapitools/server/models/Pet.kt @@ -31,7 +31,7 @@ data class Pet( val tags: kotlin.collections.List? = null, /* pet status in the store */ val status: Pet.Status? = null -) +) { /** * pet status in the store diff --git a/samples/server/petstore/kotlin-server/javalin-6/src/main/kotlin/org/openapitools/server/models/Tag.kt b/samples/server/petstore/kotlin-server/javalin-6/src/main/kotlin/org/openapitools/server/models/Tag.kt index 0a975290485..9c0bd1e9aad 100644 --- a/samples/server/petstore/kotlin-server/javalin-6/src/main/kotlin/org/openapitools/server/models/Tag.kt +++ b/samples/server/petstore/kotlin-server/javalin-6/src/main/kotlin/org/openapitools/server/models/Tag.kt @@ -20,5 +20,5 @@ package org.openapitools.server.models data class Tag( val id: kotlin.Long? = null, val name: kotlin.String? = null -) +) diff --git a/samples/server/petstore/kotlin-server/javalin-6/src/main/kotlin/org/openapitools/server/models/User.kt b/samples/server/petstore/kotlin-server/javalin-6/src/main/kotlin/org/openapitools/server/models/User.kt index a4742582f46..b26d40023f9 100644 --- a/samples/server/petstore/kotlin-server/javalin-6/src/main/kotlin/org/openapitools/server/models/User.kt +++ b/samples/server/petstore/kotlin-server/javalin-6/src/main/kotlin/org/openapitools/server/models/User.kt @@ -33,5 +33,5 @@ data class User( val phone: kotlin.String? = null, /* User Status */ val userStatus: kotlin.Int? = null -) +) diff --git a/samples/server/petstore/kotlin-server/javalin/src/main/kotlin/org/openapitools/server/models/Category.kt b/samples/server/petstore/kotlin-server/javalin/src/main/kotlin/org/openapitools/server/models/Category.kt index 71098339bc8..852f443a304 100644 --- a/samples/server/petstore/kotlin-server/javalin/src/main/kotlin/org/openapitools/server/models/Category.kt +++ b/samples/server/petstore/kotlin-server/javalin/src/main/kotlin/org/openapitools/server/models/Category.kt @@ -20,5 +20,5 @@ package org.openapitools.server.models data class Category( val id: kotlin.Long? = null, val name: kotlin.String? = null -) +) diff --git a/samples/server/petstore/kotlin-server/javalin/src/main/kotlin/org/openapitools/server/models/ModelApiResponse.kt b/samples/server/petstore/kotlin-server/javalin/src/main/kotlin/org/openapitools/server/models/ModelApiResponse.kt index 9e80c50c660..94b9ddf7b92 100644 --- a/samples/server/petstore/kotlin-server/javalin/src/main/kotlin/org/openapitools/server/models/ModelApiResponse.kt +++ b/samples/server/petstore/kotlin-server/javalin/src/main/kotlin/org/openapitools/server/models/ModelApiResponse.kt @@ -22,5 +22,5 @@ data class ModelApiResponse( val code: kotlin.Int? = null, val type: kotlin.String? = null, val message: kotlin.String? = null -) +) diff --git a/samples/server/petstore/kotlin-server/javalin/src/main/kotlin/org/openapitools/server/models/Order.kt b/samples/server/petstore/kotlin-server/javalin/src/main/kotlin/org/openapitools/server/models/Order.kt index be802beb8d8..48c1ef32bd3 100644 --- a/samples/server/petstore/kotlin-server/javalin/src/main/kotlin/org/openapitools/server/models/Order.kt +++ b/samples/server/petstore/kotlin-server/javalin/src/main/kotlin/org/openapitools/server/models/Order.kt @@ -29,7 +29,7 @@ data class Order( /* Order Status */ val status: Order.Status? = null, val complete: kotlin.Boolean? = false -) +) { /** * Order Status diff --git a/samples/server/petstore/kotlin-server/javalin/src/main/kotlin/org/openapitools/server/models/Pet.kt b/samples/server/petstore/kotlin-server/javalin/src/main/kotlin/org/openapitools/server/models/Pet.kt index e5723fedd63..0a0c9a01035 100644 --- a/samples/server/petstore/kotlin-server/javalin/src/main/kotlin/org/openapitools/server/models/Pet.kt +++ b/samples/server/petstore/kotlin-server/javalin/src/main/kotlin/org/openapitools/server/models/Pet.kt @@ -31,7 +31,7 @@ data class Pet( val tags: kotlin.collections.List? = null, /* pet status in the store */ val status: Pet.Status? = null -) +) { /** * pet status in the store diff --git a/samples/server/petstore/kotlin-server/javalin/src/main/kotlin/org/openapitools/server/models/Tag.kt b/samples/server/petstore/kotlin-server/javalin/src/main/kotlin/org/openapitools/server/models/Tag.kt index 0a975290485..9c0bd1e9aad 100644 --- a/samples/server/petstore/kotlin-server/javalin/src/main/kotlin/org/openapitools/server/models/Tag.kt +++ b/samples/server/petstore/kotlin-server/javalin/src/main/kotlin/org/openapitools/server/models/Tag.kt @@ -20,5 +20,5 @@ package org.openapitools.server.models data class Tag( val id: kotlin.Long? = null, val name: kotlin.String? = null -) +) diff --git a/samples/server/petstore/kotlin-server/javalin/src/main/kotlin/org/openapitools/server/models/User.kt b/samples/server/petstore/kotlin-server/javalin/src/main/kotlin/org/openapitools/server/models/User.kt index a4742582f46..b26d40023f9 100644 --- a/samples/server/petstore/kotlin-server/javalin/src/main/kotlin/org/openapitools/server/models/User.kt +++ b/samples/server/petstore/kotlin-server/javalin/src/main/kotlin/org/openapitools/server/models/User.kt @@ -33,5 +33,5 @@ data class User( val phone: kotlin.String? = null, /* User Status */ val userStatus: kotlin.Int? = null -) +) diff --git a/samples/server/petstore/kotlin-server/ktor/build.gradle.kts b/samples/server/petstore/kotlin-server/ktor/build.gradle.kts index fb35b77164a..1e91d49feaf 100644 --- a/samples/server/petstore/kotlin-server/ktor/build.gradle.kts +++ b/samples/server/petstore/kotlin-server/ktor/build.gradle.kts @@ -7,7 +7,8 @@ version = "1.0.0" plugins { kotlin("jvm") version "2.0.20" - id("io.ktor.plugin") version "2.3.12" + application + kotlin("plugin.serialization") version "2.0.20" } application { @@ -22,6 +23,7 @@ repositories { } dependencies { + implementation(platform("io.ktor:ktor-bom:3.0.2")) implementation("ch.qos.logback:logback-classic:$logback_version") implementation("com.typesafe:config:1.4.1") implementation("io.ktor:ktor-server-auth") @@ -29,7 +31,7 @@ dependencies { implementation("io.ktor:ktor-server-auto-head-response") implementation("io.ktor:ktor-server-default-headers") implementation("io.ktor:ktor-server-content-negotiation") - implementation("io.ktor:ktor-serialization-gson") + implementation("io.ktor:ktor-serialization-kotlinx-json") implementation("io.ktor:ktor-server-resources") implementation("io.ktor:ktor-server-hsts") implementation("io.ktor:ktor-server-compression") diff --git a/samples/server/petstore/kotlin-server/ktor/gradle.properties b/samples/server/petstore/kotlin-server/ktor/gradle.properties index d507b58c1c8..fb877a9edd2 100644 --- a/samples/server/petstore/kotlin-server/ktor/gradle.properties +++ b/samples/server/petstore/kotlin-server/ktor/gradle.properties @@ -1,4 +1,4 @@ kotlin.code.style=official -ktor_version=2.3.12 +ktor_version=3.0.2 kotlin_version=2.0.20 logback_version=1.4.14 \ No newline at end of file diff --git a/samples/server/petstore/kotlin-server/ktor/src/main/kotlin/org/openapitools/server/AppMain.kt b/samples/server/petstore/kotlin-server/ktor/src/main/kotlin/org/openapitools/server/AppMain.kt index 2de9d58ce93..4053d223ac9 100644 --- a/samples/server/petstore/kotlin-server/ktor/src/main/kotlin/org/openapitools/server/AppMain.kt +++ b/samples/server/petstore/kotlin-server/ktor/src/main/kotlin/org/openapitools/server/AppMain.kt @@ -1,7 +1,6 @@ package org.openapitools.server import io.ktor.server.application.* -import io.ktor.serialization.gson.* import io.ktor.http.* import io.ktor.server.resources.* import io.ktor.server.plugins.autohead.* @@ -13,6 +12,7 @@ import com.codahale.metrics.Slf4jReporter import io.ktor.server.metrics.dropwizard.* import java.util.concurrent.TimeUnit import io.ktor.server.routing.* +import io.ktor.serialization.kotlinx.json.json import com.typesafe.config.ConfigFactory import io.ktor.client.HttpClient import io.ktor.client.engine.apache.Apache @@ -24,12 +24,6 @@ import org.openapitools.server.apis.StoreApi import org.openapitools.server.apis.UserApi -internal val settings = HoconApplicationConfig(ConfigFactory.defaultApplication(HTTP::class.java.classLoader)) - -object HTTP { - val client = HttpClient(Apache) -} - fun Application.main() { install(DefaultHeaders) install(DropwizardMetrics) { @@ -41,7 +35,7 @@ fun Application.main() { reporter.start(10, TimeUnit.SECONDS) } install(ContentNegotiation) { - register(ContentType.Application.Json, GsonConverter()) + json() } install(AutoHeadResponse) // see https://ktor.io/docs/autoheadresponse.html install(Compression, ApplicationCompressionConfiguration()) // see https://ktor.io/docs/compression.html @@ -66,10 +60,9 @@ fun Application.main() { } } } - install(Routing) { + routing { PetApi() StoreApi() UserApi() } - } diff --git a/samples/server/petstore/kotlin-server/ktor/src/main/kotlin/org/openapitools/server/Paths.kt b/samples/server/petstore/kotlin-server/ktor/src/main/kotlin/org/openapitools/server/Paths.kt index 4a9c3bb0194..0dc3888eb30 100644 --- a/samples/server/petstore/kotlin-server/ktor/src/main/kotlin/org/openapitools/server/Paths.kt +++ b/samples/server/petstore/kotlin-server/ktor/src/main/kotlin/org/openapitools/server/Paths.kt @@ -21,7 +21,7 @@ object Paths { * * @param body Pet object that needs to be added to the store */ - @Serializable @Resource("/pet") class addPet(val body: Pet) + @Resource("/pet") class addPet() /** * Deletes a pet @@ -29,35 +29,35 @@ object Paths { * @param petId Pet id to delete * @param apiKey (optional) */ - @Serializable @Resource("/pet/{petId}") class deletePet(val petId: kotlin.Long, val apiKey: kotlin.String? = null) + @Resource("/pet/{petId}") class deletePet(val petId: kotlin.Long) /** * Finds Pets by status * Multiple status values can be provided with comma separated strings * @param status Status values that need to be considered for filter */ - @Serializable @Resource("/pet/findByStatus") class findPetsByStatus(val status: kotlin.collections.List) + @Resource("/pet/findByStatus") class findPetsByStatus(val status: kotlin.collections.List) /** * Finds Pets by tags * Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing. * @param tags Tags to filter by */ - @Serializable @Resource("/pet/findByTags") class findPetsByTags(val tags: kotlin.collections.List) + @Resource("/pet/findByTags") class findPetsByTags(val tags: kotlin.collections.List) /** * Find pet by ID * Returns a single pet * @param petId ID of pet to return */ - @Serializable @Resource("/pet/{petId}") class getPetById(val petId: kotlin.Long) + @Resource("/pet/{petId}") class getPetById(val petId: kotlin.Long) /** * Update an existing pet * * @param body Pet object that needs to be added to the store */ - @Serializable @Resource("/pet") class updatePet(val body: Pet) + @Resource("/pet") class updatePet() /** * Updates a pet in the store with form data @@ -66,7 +66,7 @@ object Paths { * @param name Updated name of the pet (optional) * @param status Updated status of the pet (optional) */ - @Serializable @Resource("/pet/{petId}") class updatePetWithForm(val petId: kotlin.Long, val name: kotlin.String? = null, val status: kotlin.String? = null) + @Resource("/pet/{petId}") class updatePetWithForm(val petId: kotlin.Long) /** * uploads an image @@ -75,69 +75,69 @@ object Paths { * @param additionalMetadata Additional data to pass to server (optional) * @param file file to upload (optional) */ - @Serializable @Resource("/pet/{petId}/uploadImage") class uploadFile(val petId: kotlin.Long, val additionalMetadata: kotlin.String? = null, val file: java.io.File? = null) + @Resource("/pet/{petId}/uploadImage") class uploadFile(val petId: kotlin.Long) /** * Delete purchase order by ID * For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors * @param orderId ID of the order that needs to be deleted */ - @Serializable @Resource("/store/order/{orderId}") class deleteOrder(val orderId: kotlin.String) + @Resource("/store/order/{orderId}") class deleteOrder(val orderId: kotlin.String) /** * Returns pet inventories by status * Returns a map of status codes to quantities */ - @Serializable @Resource("/store/inventory") class getInventory + @Resource("/store/inventory") class getInventory /** * Find purchase order by ID * For valid response try integer IDs with value <= 5 or > 10. Other values will generate exceptions * @param orderId ID of pet that needs to be fetched */ - @Serializable @Resource("/store/order/{orderId}") class getOrderById(val orderId: kotlin.Long) + @Resource("/store/order/{orderId}") class getOrderById(val orderId: kotlin.Long) /** * Place an order for a pet * * @param body order placed for purchasing the pet */ - @Serializable @Resource("/store/order") class placeOrder(val body: Order) + @Resource("/store/order") class placeOrder() /** * Create user * This can only be done by the logged in user. * @param body Created user object */ - @Serializable @Resource("/user") class createUser(val body: User) + @Resource("/user") class createUser() /** * Creates list of users with given input array * * @param body List of user object */ - @Serializable @Resource("/user/createWithArray") class createUsersWithArrayInput(val body: kotlin.collections.List) + @Resource("/user/createWithArray") class createUsersWithArrayInput() /** * Creates list of users with given input array * * @param body List of user object */ - @Serializable @Resource("/user/createWithList") class createUsersWithListInput(val body: kotlin.collections.List) + @Resource("/user/createWithList") class createUsersWithListInput() /** * Delete user * This can only be done by the logged in user. * @param username The name that needs to be deleted */ - @Serializable @Resource("/user/{username}") class deleteUser(val username: kotlin.String) + @Resource("/user/{username}") class deleteUser(val username: kotlin.String) /** * Get user by user name * * @param username The name that needs to be fetched. Use user1 for testing. */ - @Serializable @Resource("/user/{username}") class getUserByName(val username: kotlin.String) + @Resource("/user/{username}") class getUserByName(val username: kotlin.String) /** * Logs user into the system @@ -145,13 +145,13 @@ object Paths { * @param username The user name for login * @param password The password for login in clear text */ - @Serializable @Resource("/user/login") class loginUser(val username: kotlin.String, val password: kotlin.String) + @Resource("/user/login") class loginUser(val username: kotlin.String, val password: kotlin.String) /** * Logs out current logged in user session * */ - @Serializable @Resource("/user/logout") class logoutUser + @Resource("/user/logout") class logoutUser /** * Updated user @@ -159,6 +159,6 @@ object Paths { * @param username name that need to be deleted * @param body Updated user object */ - @Serializable @Resource("/user/{username}") class updateUser(val username: kotlin.String, val body: User) + @Resource("/user/{username}") class updateUser(val username: kotlin.String) } diff --git a/samples/server/petstore/kotlin-server/ktor/src/main/kotlin/org/openapitools/server/apis/PetApi.kt b/samples/server/petstore/kotlin-server/ktor/src/main/kotlin/org/openapitools/server/apis/PetApi.kt index d95a4b4d088..b72ec0d72ce 100644 --- a/samples/server/petstore/kotlin-server/ktor/src/main/kotlin/org/openapitools/server/apis/PetApi.kt +++ b/samples/server/petstore/kotlin-server/ktor/src/main/kotlin/org/openapitools/server/apis/PetApi.kt @@ -11,7 +11,6 @@ */ package org.openapitools.server.apis -import com.google.gson.Gson import io.ktor.http.* import io.ktor.server.application.* import io.ktor.server.auth.* @@ -30,13 +29,12 @@ import org.openapitools.server.models.ModelApiResponse import org.openapitools.server.models.Pet fun Route.PetApi() { - val gson = Gson() val empty = mutableMapOf() authenticate("petstore_auth") { post { - val principal = call.authentication.principal()!! + val principal = call.authentication.principal() call.respond(HttpStatusCode.NotImplemented) @@ -47,7 +45,7 @@ fun Route.PetApi() { authenticate("petstore_auth") { delete { - val principal = call.authentication.principal()!! + val principal = call.authentication.principal() call.respond(HttpStatusCode.NotImplemented) @@ -58,7 +56,7 @@ fun Route.PetApi() { authenticate("petstore_auth") { get { - val principal = call.authentication.principal()!! + val principal = call.authentication.principal() val exampleContentType = "application/json" @@ -97,7 +95,7 @@ fun Route.PetApi() { } ]""" 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) } @@ -108,7 +106,7 @@ fun Route.PetApi() { authenticate("petstore_auth") { get { - val principal = call.authentication.principal()!! + val principal = call.authentication.principal() val exampleContentType = "application/json" @@ -147,7 +145,7 @@ fun Route.PetApi() { } ]""" 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) } @@ -158,7 +156,7 @@ fun Route.PetApi() { authenticate("api_key") { get { - val principal = call.authentication.principal()!! + val principal = call.authentication.principal() val exampleContentType = "application/json" @@ -181,7 +179,7 @@ fun Route.PetApi() { }""" 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) } @@ -192,7 +190,7 @@ fun Route.PetApi() { authenticate("petstore_auth") { put { - val principal = call.authentication.principal()!! + val principal = call.authentication.principal() call.respond(HttpStatusCode.NotImplemented) @@ -203,7 +201,7 @@ fun Route.PetApi() { authenticate("petstore_auth") { post { - val principal = call.authentication.principal()!! + val principal = call.authentication.principal() call.respond(HttpStatusCode.NotImplemented) @@ -214,7 +212,7 @@ fun Route.PetApi() { authenticate("petstore_auth") { post { - val principal = call.authentication.principal()!! + val principal = call.authentication.principal() val exampleContentType = "application/json" @@ -225,7 +223,7 @@ fun Route.PetApi() { }""" 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/ktor/src/main/kotlin/org/openapitools/server/apis/StoreApi.kt b/samples/server/petstore/kotlin-server/ktor/src/main/kotlin/org/openapitools/server/apis/StoreApi.kt index fe780f7feb4..4a439577840 100644 --- a/samples/server/petstore/kotlin-server/ktor/src/main/kotlin/org/openapitools/server/apis/StoreApi.kt +++ b/samples/server/petstore/kotlin-server/ktor/src/main/kotlin/org/openapitools/server/apis/StoreApi.kt @@ -11,7 +11,6 @@ */ package org.openapitools.server.apis -import com.google.gson.Gson import io.ktor.http.* import io.ktor.server.application.* import io.ktor.server.auth.* @@ -29,7 +28,6 @@ import org.openapitools.server.infrastructure.ApiPrincipal import org.openapitools.server.models.Order fun Route.StoreApi() { - val gson = Gson() val empty = mutableMapOf() delete { @@ -40,7 +38,7 @@ fun Route.StoreApi() { authenticate("api_key") { get { - val principal = call.authentication.principal()!! + val principal = call.authentication.principal() call.respond(HttpStatusCode.NotImplemented) @@ -60,7 +58,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 +77,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/ktor/src/main/kotlin/org/openapitools/server/apis/UserApi.kt b/samples/server/petstore/kotlin-server/ktor/src/main/kotlin/org/openapitools/server/apis/UserApi.kt index ccf0509fca2..299f743e141 100644 --- a/samples/server/petstore/kotlin-server/ktor/src/main/kotlin/org/openapitools/server/apis/UserApi.kt +++ b/samples/server/petstore/kotlin-server/ktor/src/main/kotlin/org/openapitools/server/apis/UserApi.kt @@ -11,7 +11,6 @@ */ package org.openapitools.server.apis -import com.google.gson.Gson import io.ktor.http.* import io.ktor.server.application.* import io.ktor.server.auth.* @@ -29,7 +28,6 @@ import org.openapitools.server.infrastructure.ApiPrincipal import org.openapitools.server.models.User fun Route.UserApi() { - val gson = Gson() val empty = mutableMapOf() post { @@ -66,7 +64,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) } diff --git a/samples/server/petstore/kotlin-server/ktor/src/main/kotlin/org/openapitools/server/models/Category.kt b/samples/server/petstore/kotlin-server/ktor/src/main/kotlin/org/openapitools/server/models/Category.kt index 9d857192138..7647c2d227e 100644 --- a/samples/server/petstore/kotlin-server/ktor/src/main/kotlin/org/openapitools/server/models/Category.kt +++ b/samples/server/petstore/kotlin-server/ktor/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/ktor/src/main/kotlin/org/openapitools/server/models/ModelApiResponse.kt b/samples/server/petstore/kotlin-server/ktor/src/main/kotlin/org/openapitools/server/models/ModelApiResponse.kt index 5548175d904..e16d42e86a4 100644 --- a/samples/server/petstore/kotlin-server/ktor/src/main/kotlin/org/openapitools/server/models/ModelApiResponse.kt +++ b/samples/server/petstore/kotlin-server/ktor/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/ktor/src/main/kotlin/org/openapitools/server/models/Order.kt b/samples/server/petstore/kotlin-server/ktor/src/main/kotlin/org/openapitools/server/models/Order.kt index 79dce95e1e4..b1a711510fc 100644 --- a/samples/server/petstore/kotlin-server/ktor/src/main/kotlin/org/openapitools/server/models/Order.kt +++ b/samples/server/petstore/kotlin-server/ktor/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,19 +22,17 @@ import java.io.Serializable * @param status Order Status * @param complete */ +@Serializable data class Order( val id: kotlin.Long? = null, val petId: kotlin.Long? = null, val quantity: kotlin.Int? = null, - val shipDate: java.time.OffsetDateTime? = null, + val shipDate: kotlin.String? = null, /* 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/ktor/src/main/kotlin/org/openapitools/server/models/Pet.kt b/samples/server/petstore/kotlin-server/ktor/src/main/kotlin/org/openapitools/server/models/Pet.kt index 8b98ce0469c..8fe934cc3ff 100644 --- a/samples/server/petstore/kotlin-server/ktor/src/main/kotlin/org/openapitools/server/models/Pet.kt +++ b/samples/server/petstore/kotlin-server/ktor/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/ktor/src/main/kotlin/org/openapitools/server/models/Tag.kt b/samples/server/petstore/kotlin-server/ktor/src/main/kotlin/org/openapitools/server/models/Tag.kt index e9626b25c6d..fae4d9d0ba3 100644 --- a/samples/server/petstore/kotlin-server/ktor/src/main/kotlin/org/openapitools/server/models/Tag.kt +++ b/samples/server/petstore/kotlin-server/ktor/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/ktor/src/main/kotlin/org/openapitools/server/models/User.kt b/samples/server/petstore/kotlin-server/ktor/src/main/kotlin/org/openapitools/server/models/User.kt index fdbdb4e1cff..af04fd61c1c 100644 --- a/samples/server/petstore/kotlin-server/ktor/src/main/kotlin/org/openapitools/server/models/User.kt +++ b/samples/server/petstore/kotlin-server/ktor/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 - } }