Skip to content

Commit 88cdbbc

Browse files
macjohnnywing328
authored andcommitted
[Kotlin SpringBoot Server] alternative: fix optional parameter not correctly declared in service (#2539)
* fix kotlin optional parameters * ensure kotlin samples up to date
1 parent 3a0d520 commit 88cdbbc

File tree

8 files changed

+23
-22
lines changed

8 files changed

+23
-22
lines changed

bin/utils/ensure-up-to-date

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ declare -a scripts=(
2424
"./bin/kotlin-client-string.sh"
2525
"./bin/kotlin-client-threetenbp.sh"
2626
"./bin/kotlin-server-petstore.sh"
27+
"./bin/kotlin-springboot-petstore-server.sh"
2728
"./bin/mysql-schema-petstore.sh"
2829
"./bin/python-petstore-all.sh"
2930
"./bin/openapi3/python-petstore.sh"
Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
set executable=.\modules\openapi-generator-cli\target\openapi-generator-cli.jar
2-
3-
If Not Exist %executable% (
4-
mvn clean package
5-
)
6-
7-
REM set JAVA_OPTS=%JAVA_OPTS% -Xmx1024M
8-
set ags=generate -i modules\openapi-generator\src\test\resources\2_0\petstore.yaml -g kotlin-spring -o samples\server\petstore\kotlin-springboot --additional-properties=library=spring-boot
9-
10-
java %JAVA_OPTS% -jar %executable% %ags%
1+
set executable=.\modules\openapi-generator-cli\target\openapi-generator-cli.jar
2+
3+
If Not Exist %executable% (
4+
mvn clean package
5+
)
6+
7+
REM set JAVA_OPTS=%JAVA_OPTS% -Xmx1024M
8+
set ags=generate -i modules\openapi-generator\src\test\resources\2_0\petstore.yaml -g kotlin-spring -o samples\server\petstore\kotlin-springboot --additional-properties=library=spring-boot,beanValidations=true,swaggerAnnotations=true,serviceImplementation=true
9+
10+
java %JAVA_OPTS% -jar %executable% %ags%

modules/openapi-generator/src/main/resources/kotlin-spring/service.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ package {{package}}
77
interface {{classname}}Service {
88
{{#operation}}
99

10-
fun {{operationId}}({{#allParams}}{{paramName}}: {{{dataType}}}{{#hasMore}},{{/hasMore}}{{/allParams}}): {{>returnTypes}}
10+
fun {{operationId}}({{#allParams}}{{paramName}}: {{>optionalDataType}}{{#hasMore}}, {{/hasMore}}{{/allParams}}): {{>returnTypes}}
1111
{{/operation}}
1212
}
1313
{{/operations}}

modules/openapi-generator/src/main/resources/kotlin-spring/serviceImpl.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import org.springframework.stereotype.Service
88
class {{classname}}ServiceImpl : {{classname}}Service {
99
{{#operation}}
1010

11-
override fun {{operationId}}({{#allParams}}{{paramName}}: {{{dataType}}}{{#hasMore}},{{/hasMore}}{{/allParams}}): {{>returnTypes}} {
11+
override fun {{operationId}}({{#allParams}}{{paramName}}: {{>optionalDataType}}{{#hasMore}}, {{/hasMore}}{{/allParams}}): {{>returnTypes}} {
1212
TODO("Implement me")
1313
}
1414
{{/operation}}

samples/server/petstore/kotlin-springboot/src/main/kotlin/org/openapitools/api/PetApiService.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ interface PetApiService {
77

88
fun addPet(body: Pet): Unit
99

10-
fun deletePet(petId: Long,apiKey: String): Unit
10+
fun deletePet(petId: Long, apiKey: String?): Unit
1111

1212
fun findPetsByStatus(status: List<String>): List<Pet>
1313

@@ -17,7 +17,7 @@ interface PetApiService {
1717

1818
fun updatePet(body: Pet): Unit
1919

20-
fun updatePetWithForm(petId: Long,name: String,status: String): Unit
20+
fun updatePetWithForm(petId: Long, name: String?, status: String?): Unit
2121

22-
fun uploadFile(petId: Long,additionalMetadata: String,file: org.springframework.core.io.Resource): ModelApiResponse
22+
fun uploadFile(petId: Long, additionalMetadata: String?, file: org.springframework.core.io.Resource?): ModelApiResponse
2323
}

samples/server/petstore/kotlin-springboot/src/main/kotlin/org/openapitools/api/PetApiServiceImpl.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class PetApiServiceImpl : PetApiService {
1010
TODO("Implement me")
1111
}
1212

13-
override fun deletePet(petId: Long,apiKey: String): Unit {
13+
override fun deletePet(petId: Long, apiKey: String?): Unit {
1414
TODO("Implement me")
1515
}
1616

@@ -30,11 +30,11 @@ class PetApiServiceImpl : PetApiService {
3030
TODO("Implement me")
3131
}
3232

33-
override fun updatePetWithForm(petId: Long,name: String,status: String): Unit {
33+
override fun updatePetWithForm(petId: Long, name: String?, status: String?): Unit {
3434
TODO("Implement me")
3535
}
3636

37-
override fun uploadFile(petId: Long,additionalMetadata: String,file: org.springframework.core.io.Resource): ModelApiResponse {
37+
override fun uploadFile(petId: Long, additionalMetadata: String?, file: org.springframework.core.io.Resource?): ModelApiResponse {
3838
TODO("Implement me")
3939
}
4040
}

samples/server/petstore/kotlin-springboot/src/main/kotlin/org/openapitools/api/UserApiService.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ interface UserApiService {
1414

1515
fun getUserByName(username: String): User
1616

17-
fun loginUser(username: String,password: String): String
17+
fun loginUser(username: String, password: String): String
1818

1919
fun logoutUser(): Unit
2020

21-
fun updateUser(username: String,body: User): Unit
21+
fun updateUser(username: String, body: User): Unit
2222
}

samples/server/petstore/kotlin-springboot/src/main/kotlin/org/openapitools/api/UserApiServiceImpl.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,15 @@ class UserApiServiceImpl : UserApiService {
2525
TODO("Implement me")
2626
}
2727

28-
override fun loginUser(username: String,password: String): String {
28+
override fun loginUser(username: String, password: String): String {
2929
TODO("Implement me")
3030
}
3131

3232
override fun logoutUser(): Unit {
3333
TODO("Implement me")
3434
}
3535

36-
override fun updateUser(username: String,body: User): Unit {
36+
override fun updateUser(username: String, body: User): Unit {
3737
TODO("Implement me")
3838
}
3939
}

0 commit comments

Comments
 (0)