Skip to content

Commit

Permalink
[Kotlin Server] Update Ktor to latest version; move config to kts
Browse files Browse the repository at this point in the history
  • Loading branch information
e5l committed Sep 30, 2024
1 parent 849b3e8 commit 2ab59fa
Show file tree
Hide file tree
Showing 17 changed files with 188 additions and 185 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -272,21 +272,21 @@ public void processOpts() {

supportingFiles.add(new SupportingFile("README.mustache", "", "README.md"));

if (library.equals(Constants.KTOR)) {
if (isKtor()) {
supportingFiles.add(new SupportingFile("Dockerfile.mustache", "", "Dockerfile"));
}

String gradleBuildFile = "build.gradle";

if (isJavalin()) {
if (isJavalin() || isKtor()) {
gradleBuildFile = "build.gradle.kts";
}

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

if (library.equals(Constants.KTOR)) {
if (isKtor()) {
supportingFiles.add(new SupportingFile("AppMain.kt.mustache", packageFolder, "AppMain.kt"));
supportingFiles.add(new SupportingFile("Configuration.kt.mustache", packageFolder, "Configuration.kt"));

Expand All @@ -300,6 +300,11 @@ public void processOpts() {
final String infrastructureFolder = (sourceFolder + File.separator + packageName + File.separator + "infrastructure").replace(".", File.separator);

supportingFiles.add(new SupportingFile("ApiKeyAuth.kt.mustache", infrastructureFolder, "ApiKeyAuth.kt"));

if (!getOmitGradleWrapper()) {
supportingFiles.add(new SupportingFile("gradle-wrapper.properties", "gradle" + File.separator + "wrapper", "gradle-wrapper.properties"));
}

} else if (isJavalin()) {
supportingFiles.add(new SupportingFile("Main.kt.mustache", packageFolder, "Main.kt"));
apiTemplateFiles.put("service.mustache", "Service.kt");
Expand Down Expand Up @@ -412,4 +417,8 @@ public void setReturnContainer(final String returnContainer) {
private boolean isJavalin() {
return Constants.JAVALIN5.equals(library) || Constants.JAVALIN6.equals(library);
}

private boolean isKtor() {
return Constants.KTOR.equals(library);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ Generated by OpenAPI Generator {{generatorVersion}}{{^hideGenerationTimestamp}}

## Requires

* Kotlin 1.7.20
* Gradle 7.4.2
* Kotlin 2.0.20
* Gradle 8.10.2

## Build

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@

val kotlin_version: String by project
val logback_version: String by project

group = "{{groupId}}"
version = "{{artifactVersion}}"

plugins {
kotlin("jvm") version "2.0.20"
id("io.ktor.plugin") version "2.3.12"
}

application {
mainClass.set("io.ktor.server.netty.EngineMain")
val isDevelopment: Boolean = project.ext.has("development")
applicationDefaultJvmArgs = listOf("-Dio.ktor.development=$isDevelopment")
}

repositories {
mavenCentral()
}

dependencies {
implementation("ch.qos.logback:logback-classic:$logback_version")
{{#hasAuthMethods}}
implementation("com.typesafe:config:1.4.1")
{{/hasAuthMethods}}
implementation("io.ktor:ktor-server-auth")
{{#hasAuthMethods}}
implementation("io.ktor:ktor-client-apache")
{{/hasAuthMethods}}
{{#featureAutoHead}}
implementation("io.ktor:ktor-server-auto-head-response")
{{/featureAutoHead}}
implementation("io.ktor:ktor-server-default-headers")
implementation("io.ktor:ktor-server-content-negotiation")
implementation("io.ktor:ktor-serialization-gson")
{{#featureResources}}
implementation("io.ktor:ktor-server-resources")
{{/featureResources}}
{{#featureHSTS}}
implementation("io.ktor:ktor-server-hsts")
{{/featureHSTS}}
{{#featureCORS}}
implementation("io.ktor:ktor-server-cors")
{{/featureCORS}}
{{#featureConditionalHeaders}}
implementation("io.ktor:ktor-server-conditional-headers")
{{/featureConditionalHeaders}}
{{#featureCompression}}
implementation("io.ktor:ktor-server-compression")
{{/featureCompression}}
{{#featureMetrics}}
implementation("io.dropwizard.metrics:metrics-core:4.1.18")
implementation("io.ktor:ktor-server-metrics")
{{/featureMetrics}}
implementation("io.ktor:ktor-server-netty")

testImplementation("org.jetbrains.kotlin:kotlin-test-junit:$kotlin_version")
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
org.gradle.caching=true
kotlin.code.style=official
ktor_version=2.3.12
kotlin_version=2.0.20
logback_version=1.4.14
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
Dockerfile
README.md
build.gradle
build.gradle.kts
gradle.properties
gradle/wrapper/gradle-wrapper.properties
settings.gradle
src/main/kotlin/org/openapitools/server/AppMain.kt
src/main/kotlin/org/openapitools/server/Configuration.kt
Expand Down
4 changes: 2 additions & 2 deletions samples/server/petstore/kotlin-server-modelMutable/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ Generated by OpenAPI Generator 7.9.0-SNAPSHOT.

## Requires

* Kotlin 1.7.20
* Gradle 7.4.2
* Kotlin 2.0.20
* Gradle 8.10.2

## Build

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@

val kotlin_version: String by project
val logback_version: String by project

group = "org.openapitools"
version = "1.0.0"

plugins {
kotlin("jvm") version "2.0.20"
id("io.ktor.plugin") version "2.3.12"
}

application {
mainClass.set("io.ktor.server.netty.EngineMain")

val isDevelopment: Boolean = project.ext.has("development")
applicationDefaultJvmArgs = listOf("-Dio.ktor.development=$isDevelopment")
}

repositories {
mavenCentral()
}

dependencies {
implementation("ch.qos.logback:logback-classic:$logback_version")
implementation("com.typesafe:config:1.4.1")
implementation("io.ktor:ktor-server-auth")
implementation("io.ktor:ktor-client-apache")
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-server-resources")
implementation("io.ktor:ktor-server-hsts")
implementation("io.ktor:ktor-server-compression")
implementation("io.dropwizard.metrics:metrics-core:4.1.18")
implementation("io.ktor:ktor-server-metrics")
implementation("io.ktor:ktor-server-netty")

testImplementation("org.jetbrains.kotlin:kotlin-test-junit:$kotlin_version")
}
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
org.gradle.caching=true
kotlin.code.style=official
ktor_version=2.3.12
kotlin_version=2.0.20
logback_version=1.4.14
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
Dockerfile
README.md
build.gradle
build.gradle.kts
gradle.properties
gradle/wrapper/gradle-wrapper.properties
settings.gradle
src/main/kotlin/org/openapitools/server/AppMain.kt
src/main/kotlin/org/openapitools/server/Configuration.kt
Expand Down
4 changes: 2 additions & 2 deletions samples/server/petstore/kotlin-server/ktor/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ Generated by OpenAPI Generator 7.9.0-SNAPSHOT.

## Requires

* Kotlin 1.7.20
* Gradle 7.4.2
* Kotlin 2.0.20
* Gradle 8.10.2

## Build

Expand Down
Loading

0 comments on commit 2ab59fa

Please sign in to comment.