Skip to content

Commit 283f9d0

Browse files
committed
updated kotlin-server templates
1 parent c822fd5 commit 283f9d0

File tree

9 files changed

+54
-49
lines changed

9 files changed

+54
-49
lines changed

src/main/java/io/swagger/codegen/v3/generators/kotlin/AbstractKotlinCodegen.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package io.swagger.codegen.v3.generators.kotlin;
22

3+
import com.github.jknack.handlebars.helper.ConditionalHelpers;
34
import io.swagger.codegen.v3.CliOption;
45
import io.swagger.codegen.v3.CodegenConstants;
56
import io.swagger.codegen.v3.CodegenModel;
@@ -519,6 +520,7 @@ public String toEnumName(CodegenProperty property) {
519520
public void addHandlebarHelpers(Handlebars handlebars) {
520521
super.addHandlebarHelpers(handlebars);
521522
handlebars.registerHelpers(StringHelpers.class);
523+
handlebars.registerHelpers(ConditionalHelpers.class);
522524
}
523525

524526
/**

src/main/java/io/swagger/codegen/v3/generators/kotlin/KotlinClientCodegen.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,6 @@ public KotlinClientCodegen() {
5757
cliOptions.add(dateLibrary);
5858
}
5959

60-
@Override
61-
public void addHandlebarHelpers(Handlebars handlebars) {
62-
super.addHandlebarHelpers(handlebars);
63-
handlebars.registerHelpers(ConditionalHelpers.class);
64-
}
65-
6660
@Override
6761
public String getDefaultTemplateDir() {
6862
return "kotlin-client";
Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,33 @@
11
/**
22
* {{{description}}}
3-
{{~#vars}}
3+
{{#vars}}
44
* @param {{name}} {{{description}}}
5-
{{~/vars~}}
5+
{{/vars}}
66
*/
7-
data class {{classname}} (
8-
{{~#requiredVars~}}
9-
{{>data_class_req_var}}{{^@last}},{{/@last}}
10-
{{~/requiredVars~}}
11-
{{#has this 'required'}}{{#has this 'optional'}},{{/has}}{{/has}}
12-
{{~#optionalVars}}{{>data_class_opt_var}}{{^@last}},{{/@last}}{{/optionalVars}}
7+
{{#hasVars}}data {{/hasVars}}class {{classname}} (
8+
9+
{{#vars}}
10+
{{#required}}
11+
{{>data_class_req_var}}{{^@last}},{{/@last}}
12+
{{/required}}
13+
{{^required}}
14+
{{>data_class_opt_var}}{{^@last}},{{/@last}}
15+
{{/required}}
16+
{{/vars}}
1317
) {
14-
{{#has this 'enums'}}{{#vars}}{{#is this 'enum'}}
18+
{{#vars}}
19+
{{#baseItems this}}
20+
{{#isEnum}}
1521
/**
1622
* {{{description}}}
1723
* Values: {{#allowableValues}}{{#enumVars}}{{&name}}{{^@last}},{{/@last}}{{/enumVars}}{{/allowableValues}}
1824
*/
19-
enum class {{nameInCamelCase}}(val value: {{datatype}}){
25+
enum class {{{datatypeWithEnum}}}(val value: {{{datatype}}}{{#isNullable}}?{{/isNullable}}){
2026
{{#allowableValues}}{{#enumVars}}
21-
{{&name}}({{{value}}}){{^@last}},{{/@last}}{{#@last}};{{/@last}}
27+
{{&name}}({{#value}}{{{value}}}{{/value}}{{^value}}null{{/value}}){{^@last}},{{/@last}}{{#@last}};{{/@last}}
2228
{{/enumVars}}{{/allowableValues}}
2329
}
24-
{{/is}}{{/vars}}{{/has}}
30+
{{/isEnum}}
31+
{{/baseItems}}
32+
{{/vars}}
2533
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{{#description}}
22
/* {{{description}}} */
3-
{{~/description}}
4-
val {{{name}}}: {{#is this 'enum'}}{{classname}}.{{nameInCamelCase}}{{/is}}{{#isNot this 'enum'}}{{{datatype}}}{{/isNot}}? = {{#defaultvalue}}{{defaultvalue}}{{/defaultvalue}}{{^defaultvalue}}null{{/defaultvalue}}
3+
{{/description}}
4+
val {{{name}}}: {{#isEnum}}{{{datatypeWithEnum}}}{{/isEnum}}{{^isEnum}}{{{datatype}}}{{/isEnum}}? = {{#defaultvalue}}{{defaultvalue}}{{/defaultvalue}}{{^defaultvalue}}null{{/defaultvalue}}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{{#description}}
22
/* {{{description}}} */
33
{{/description}}
4-
val {{{name}}}: {{#is this 'enum'}}{{classname}}.{{nameInCamelCase}}{{/is}}{{#isNot this 'enum'}}{{{datatype}}}{{/isNot}}
4+
val {{{name}}}: {{#isEnum}}{{{datatypeWithEnum}}}{{/isEnum}}{{^isEnum}}{{{datatype}}}{{/isEnum}}

src/main/resources/handlebars/kotlin-server/libraries/ktor/AppMain.kt.mustache

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ import io.ktor.util.KtorExperimentalAPI
3636
{{#hasAuthMethods}}
3737
import io.ktor.auth.Authentication
3838
import io.ktor.auth.oauth
39+
import io.ktor.auth.basic
40+
import io.ktor.auth.UserIdPrincipal
3941
import io.ktor.metrics.dropwizard.DropwizardMetrics
4042
import io.swagger.server.infrastructure.ApiKeyCredential
4143
import io.swagger.server.infrastructure.ApiPrincipal
@@ -88,13 +90,14 @@ fun Application.main() {
8890
{{#authMethods}}
8991
{{#isBasic}}
9092
basic("{{{name}}}") {
91-
validate { credentials ->
92-
// TODO: "Apply your basic authentication functionality."
93-
// Accessible in-method via call.principal<UserIdPrincipal>()
94-
if (credentials.name == "Swagger" && "Codegen" == credentials.password) {
95-
UserIdPrincipal(credentials.name)
96-
} else {
97-
null
93+
validate { credentials ->
94+
// TODO: "Apply your basic authentication functionality."
95+
// Accessible in-method via call.principal<UserIdPrincipal>()
96+
if (credentials.name == "Swagger" && "Codegen" == credentials.password) {
97+
UserIdPrincipal(credentials.name)
98+
} else {
99+
null
100+
}
98101
}
99102
}
100103
{{/isBasic}}

src/main/resources/handlebars/kotlin-server/libraries/ktor/_principal.mustache

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{{#authMethods}}
22
{{#@first}}
3-
{{#isBasic}}
3+
{{#or isBasic isBearer}}
44
val principal = call.authentication.principal<UserIdPrincipal>()
5-
{{/isBasic}}
5+
{{/or}}
66
{{#isApiKey}}
77
val principal = call.authentication.principal<ApiPrincipal>()
88
{{/isApiKey}}

src/main/resources/handlebars/kotlin-server/libraries/ktor/api.mustache

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import io.ktor.locations.delete
1515
import io.ktor.locations.get
1616
import io.ktor.locations.post
1717
import io.ktor.locations.put
18+
import io.ktor.locations.patch
1819
import io.ktor.response.respond
1920
import io.ktor.response.respondText
2021
import io.ktor.routing.Route

src/main/resources/handlebars/kotlin-server/libraries/ktor/build.gradle.mustache

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,19 @@ group '{{groupId}}'
22
version '{{artifactVersion}}'
33

44
wrapper {
5-
gradleVersion = '5.3'
5+
gradleVersion = '7.5'
66
distributionUrl = "https://services.gradle.org/distributions/gradle-$gradleVersion-all.zip"
77
}
88

99
buildscript {
10-
ext.kotlin_version = '1.4.30'
11-
ext.ktor_version = '1.5.1'
12-
ext.shadow_version = '5.2.0'
10+
ext.kotlin_version = '1.8.0'
11+
ext.ktor_version = "1.5.4"
12+
ext.shadow_version = "6.1.0"
1313
1414
repositories {
15+
maven {
16+
url "https://repo1.maven.org/maven2"
17+
}
1518
maven {
1619
url "https://plugins.gradle.org/m2/"
1720
}
@@ -40,12 +43,6 @@ compileTestKotlin {
4043
kotlinOptions.jvmTarget = "1.8"
4144
}
4245

43-
kotlin {
44-
experimental {
45-
coroutines "enable"
46-
}
47-
}
48-
4946
shadowJar {
5047
baseName = '{{artifactId}}'
5148
classifier = null
@@ -59,13 +56,13 @@ repositories {
5956
}
6057

6158
dependencies {
62-
compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
63-
compile "io.ktor:ktor-server-netty:$ktor_version"
64-
compile "io.ktor:ktor-metrics:$ktor_version"
65-
compile "io.ktor:ktor-locations:$ktor_version"
66-
compile "io.ktor:ktor-gson:$ktor_version"
67-
compile "io.ktor:ktor-client-core:$ktor_version"
68-
compile "io.ktor:ktor-client-apache:$ktor_version"
69-
compile "ch.qos.logback:logback-classic:1.2.9"
70-
testCompile group: 'junit', name: 'junit', version: '4.12'
59+
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
60+
implementation "io.ktor:ktor-server-netty:$ktor_version"
61+
implementation "io.ktor:ktor-metrics:$ktor_version"
62+
implementation "io.ktor:ktor-locations:$ktor_version"
63+
implementation "io.ktor:ktor-gson:$ktor_version"
64+
implementation "io.ktor:ktor-client-core:$ktor_version"
65+
implementation "io.ktor:ktor-client-apache:$ktor_version"
66+
implementation "ch.qos.logback:logback-classic:1.2.9"
67+
testImplementation group: 'junit', name: 'junit', version: '4.12'
7168
}

0 commit comments

Comments
 (0)