Skip to content

Commit 9a25d7e

Browse files
author
andrewwilsonnew
committed
fixing impl
1 parent d4974b7 commit 9a25d7e

18 files changed

Lines changed: 94 additions & 89 deletions

File tree

modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/KotlinMiskServerCodegen.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,8 @@ public KotlinMiskServerCodegen() {
106106

107107
apiTemplateFiles.clear();
108108
apiTemplateFiles.put("apiController.mustache", "Controller.kt");
109-
//apiTemplateFiles.put("apiImpl.mustache", "Impl.kt");
110-
//apiTemplateFiles.put("apiInterface.mustache", ".kt");
109+
apiTemplateFiles.put("apiImpl.mustache", "Impl.kt");
110+
apiTemplateFiles.put("apiInterface.mustache", ".kt");
111111
modelTemplateFiles.put("model.mustache", ".kt");
112112

113113
apiPackage = rootPackage + ".api";

modules/openapi-generator/src/main/resources/kotlin-misk/apiController.mustache

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,16 @@ import okhttp3.Headers
3939
{{#operations}}
4040
@Singleton
4141
class {{classname}}Controller @Inject constructor(
42-
//private val {{#lambda.camelcase}}{{classname}}{{/lambda.camelcase}}: {{classname}}
43-
) : WebAction {
42+
private val {{#lambda.camelcase}}{{classname}}{{/lambda.camelcase}}: {{classname}}
43+
) : WebAction, {{classname}} {
4444
{{#operation}}
4545

4646
@{{httpMethod}}("{{path}}")
4747
@Description("{{{summary}}}"){{#hasConsumes}}
4848
@RequestContentType({{#consumes}}{{{mediaType}}}{{^-last}}, {{/-last}}{{/consumes}}){{/hasConsumes}}{{#hasProduces}}
4949
@ResponseContentType({{#produces}}{{{mediaType}}}{{^-last}}, {{/-last}}{{/produces}}){{/hasProduces}}
5050
@LogRequestResponse(bodySampling = 1.0, errorBodySampling = 1.0)
51-
fun {{operationId}}({{#allParams}}{{>queryParams}}{{>pathParams}}{{>headerParams}}{{>cookieParams}}{{>bodyParams}}{{>formParams}}{{^-last}}, {{/-last}}{{/allParams}}){{#returnType}}: {{{returnType}}}{{/returnType}} {
51+
override fun {{operationId}}({{#allParams}}{{>queryParams}}{{>pathParams}}{{>headerParams}}{{>cookieParams}}{{>bodyParams}}{{>formParams}}{{^-last}}, {{/-last}}{{/allParams}}){{#returnType}}: {{{returnType}}}{{/returnType}} {
5252
TODO()
5353
}
5454
{{/operation}}

modules/openapi-generator/src/main/resources/kotlin-misk/apiImpl.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class {{classname}}Impl @Inject constructor(
1616
): {{classname}} {
1717
{{#operation}}
1818

19-
override fun {{operationId}}({{#allParams}}{{#isQueryParam}}{{{paramName}}}: {{>optionalDataType}}{{/isQueryParam}}{{#isPathParam}}{{{paramName}}}: {{>optionalDataType}}{{/isPathParam}}{{#isHeaderParam}}headers: Headers{{/isHeaderParam}}{{#isCookieParam}}{{{paramName}}}: HttpCall{{/isCookieParam}}{{#isBodyParam}}{{{paramName}}}: {{>optionalDataType}}{{/isBodyParam}}{{^-last}}, {{/-last}}{{/allParams}}){{#returnType}}: {{{returnType}}}{{/returnType}} {
19+
override fun {{operationId}}({{#allParams}}{{>queryParams}}{{>pathParams}}{{>headerParams}}{{>cookieParams}}{{>bodyParams}}{{>formParams}}{{^-last}}, {{/-last}}{{/allParams}}){{#returnType}}: {{{returnType}}}{{/returnType}} {
2020
TODO()
2121
}
2222
{{/operation}}

modules/openapi-generator/src/main/resources/kotlin-misk/apiInterface.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import okhttp3.Headers
88
interface {{classname}} {
99
{{#operation}}
1010

11-
fun {{operationId}}({{#allParams}}{{#isQueryParam}}{{{paramName}}}: {{>optionalDataType}}{{/isQueryParam}}{{#isPathParam}}{{{paramName}}}: {{>optionalDataType}}{{/isPathParam}}{{#isHeaderParam}}headers: Headers{{/isHeaderParam}}{{#isCookieParam}}{{{paramName}}}: HttpCall{{/isCookieParam}}{{#isBodyParam}}{{{paramName}}}: {{>optionalDataType}}{{/isBodyParam}}{{^-last}}, {{/-last}}{{/allParams}}){{#returnType}}: {{{returnType}}}{{/returnType}}
11+
fun {{operationId}}({{#allParams}}{{>queryParams}}{{>pathParams}}{{>headerParams}}{{>cookieParams}}{{>bodyParams}}{{>formParams}}{{^-last}}, {{/-last}}{{/allParams}}){{#returnType}}: {{{returnType}}}{{/returnType}} {
1212
{{/operation}}
1313
}
1414
{{/operations}}

modules/openapi-generator/src/main/resources/kotlin-misk/api_test.mustache

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
package {{package}}
22

3-
{{#imports}}import {{import}}
4-
{{/imports}}
53
import jakarta.inject.Inject
64
import misk.testing.MiskTest
7-
import okhttp3.Headers
8-
95
import org.junit.jupiter.api.Test
6+
{{#imports}}import {{import}}
7+
{{/imports}}
8+
import okhttp3.Headers
109

1110
@MiskTest(startService = true)
1211
internal class {{classname}}Test {
1312
14-
@Inject private lateinit var {{#lambda.camelcase}}{{classname}}{{/lambda.camelcase}}: {{classname}}Controller
13+
@Inject private lateinit var {{#lambda.camelcase}}{{classname}}{{/lambda.camelcase}}: {{classname}}
1514

1615
{{#operations}}
1716
{{#operation}}

samples/server/petstore/kotlin-misk/.openapi-generator/FILES

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,22 @@ docs/Tag.md
1010
docs/User.md
1111
docs/UserApi.md
1212
settings.gradle.kts
13+
src/main/kotlin/org/openapitools/server/api/api/PetApi.kt
1314
src/main/kotlin/org/openapitools/server/api/api/PetApiController.kt
15+
src/main/kotlin/org/openapitools/server/api/api/PetApiImpl.kt
1416
src/main/kotlin/org/openapitools/server/api/api/PetStoreModule.kt
17+
src/main/kotlin/org/openapitools/server/api/api/StoreApi.kt
1518
src/main/kotlin/org/openapitools/server/api/api/StoreApiController.kt
19+
src/main/kotlin/org/openapitools/server/api/api/StoreApiImpl.kt
20+
src/main/kotlin/org/openapitools/server/api/api/UserApi.kt
1621
src/main/kotlin/org/openapitools/server/api/api/UserApiController.kt
22+
src/main/kotlin/org/openapitools/server/api/api/UserApiImpl.kt
1723
src/main/kotlin/org/openapitools/server/api/model/Category.kt
1824
src/main/kotlin/org/openapitools/server/api/model/ModelApiResponse.kt
1925
src/main/kotlin/org/openapitools/server/api/model/Order.kt
2026
src/main/kotlin/org/openapitools/server/api/model/Pet.kt
2127
src/main/kotlin/org/openapitools/server/api/model/Tag.kt
2228
src/main/kotlin/org/openapitools/server/api/model/User.kt
29+
src/test/kotlin/org/openapitools/server/api/api/PetApiTest.kt
30+
src/test/kotlin/org/openapitools/server/api/api/StoreApiTest.kt
31+
src/test/kotlin/org/openapitools/server/api/api/UserApiTest.kt

samples/server/petstore/kotlin-misk/src/main/kotlin/org/openapitools/server/api/api/PetApi.kt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,19 @@ import okhttp3.Headers
66

77
interface PetApi {
88

9-
fun addPet(pet: Pet): Pet
9+
fun addPet(@Valid @RequestBody pet: Pet): Pet {
1010

11-
fun deletePet(petId: kotlin.Long, headers: Headers)
11+
fun deletePet(@PathParam("petId") petId: kotlin.Long, apiKey: Headers) {
1212

13-
fun findPetsByStatus(status: kotlin.Array<kotlin.String>): kotlin.Array<Pet>
13+
fun findPetsByStatus( @QueryParam(value = "status") status: kotlin.Array<kotlin.String>): kotlin.Array<Pet> {
1414

15-
fun findPetsByTags(tags: kotlin.Array<kotlin.String>): kotlin.Array<Pet>
15+
fun findPetsByTags( @QueryParam(value = "tags") tags: kotlin.Array<kotlin.String>): kotlin.Array<Pet> {
1616

17-
fun getPetById(petId: kotlin.Long): Pet
17+
fun getPetById(@PathParam("petId") petId: kotlin.Long): Pet {
1818

19-
fun updatePet(pet: Pet): Pet
19+
fun updatePet(@Valid @RequestBody pet: Pet): Pet {
2020

21-
fun updatePetWithForm(petId: kotlin.Long, , )
21+
fun updatePetWithForm(@PathParam("petId") petId: kotlin.Long, @QueryParam(value = "name") name: kotlin.String? , @QueryParam(value = "status") status: kotlin.String? ) {
2222

23-
fun uploadFile(petId: kotlin.Long, , ): ModelApiResponse
23+
fun uploadFile(@PathParam("petId") petId: kotlin.Long, @QueryParam(value = "additionalMetadata") additionalMetadata: kotlin.String? , @Valid file: HttpCall): ModelApiResponse {
2424
}

samples/server/petstore/kotlin-misk/src/main/kotlin/org/openapitools/server/api/api/PetApiController.kt

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,46 +36,46 @@ import okhttp3.Headers
3636

3737
@Singleton
3838
class PetApiController @Inject constructor(
39-
//private val petApi: PetApi
40-
) : WebAction {
39+
private val petApi: PetApi
40+
) : WebAction, PetApi {
4141

4242
@Post("/pet")
4343
@Description("Add a new pet to the store")
4444
@RequestContentType(MediaTypes.APPLICATION_JSON, MediaTypes.APPLICATION_XML)
4545
@ResponseContentType(MediaTypes.APPLICATION_XML, MediaTypes.APPLICATION_JSON)
4646
@LogRequestResponse(bodySampling = 1.0, errorBodySampling = 1.0)
47-
fun addPet(@Valid @RequestBody pet: Pet): Pet {
47+
override fun addPet(@Valid @RequestBody pet: Pet): Pet {
4848
TODO()
4949
}
5050

5151
@Delete("/pet/{petId}")
5252
@Description("Deletes a pet")
5353
@LogRequestResponse(bodySampling = 1.0, errorBodySampling = 1.0)
54-
fun deletePet(@PathParam("petId") petId: kotlin.Long, apiKey: Headers) {
54+
override fun deletePet(@PathParam("petId") petId: kotlin.Long, apiKey: Headers) {
5555
TODO()
5656
}
5757

5858
@Get("/pet/findByStatus")
5959
@Description("Finds Pets by status")
6060
@ResponseContentType(MediaTypes.APPLICATION_XML, MediaTypes.APPLICATION_JSON)
6161
@LogRequestResponse(bodySampling = 1.0, errorBodySampling = 1.0)
62-
fun findPetsByStatus( @QueryParam(value = "status") status: kotlin.Array<kotlin.String>): kotlin.Array<Pet> {
62+
override fun findPetsByStatus( @QueryParam(value = "status") status: kotlin.Array<kotlin.String>): kotlin.Array<Pet> {
6363
TODO()
6464
}
6565

6666
@Get("/pet/findByTags")
6767
@Description("Finds Pets by tags")
6868
@ResponseContentType(MediaTypes.APPLICATION_XML, MediaTypes.APPLICATION_JSON)
6969
@LogRequestResponse(bodySampling = 1.0, errorBodySampling = 1.0)
70-
fun findPetsByTags( @QueryParam(value = "tags") tags: kotlin.Array<kotlin.String>): kotlin.Array<Pet> {
70+
override fun findPetsByTags( @QueryParam(value = "tags") tags: kotlin.Array<kotlin.String>): kotlin.Array<Pet> {
7171
TODO()
7272
}
7373

7474
@Get("/pet/{petId}")
7575
@Description("Find pet by ID")
7676
@ResponseContentType(MediaTypes.APPLICATION_XML, MediaTypes.APPLICATION_JSON)
7777
@LogRequestResponse(bodySampling = 1.0, errorBodySampling = 1.0)
78-
fun getPetById(@PathParam("petId") petId: kotlin.Long): Pet {
78+
override fun getPetById(@PathParam("petId") petId: kotlin.Long): Pet {
7979
TODO()
8080
}
8181

@@ -84,15 +84,15 @@ import okhttp3.Headers
8484
@RequestContentType(MediaTypes.APPLICATION_JSON, MediaTypes.APPLICATION_XML)
8585
@ResponseContentType(MediaTypes.APPLICATION_XML, MediaTypes.APPLICATION_JSON)
8686
@LogRequestResponse(bodySampling = 1.0, errorBodySampling = 1.0)
87-
fun updatePet(@Valid @RequestBody pet: Pet): Pet {
87+
override fun updatePet(@Valid @RequestBody pet: Pet): Pet {
8888
TODO()
8989
}
9090

9191
@Post("/pet/{petId}")
9292
@Description("Updates a pet in the store with form data")
9393
@RequestContentType(MediaTypes.APPLICATION_FORM_URLENCODED)
9494
@LogRequestResponse(bodySampling = 1.0, errorBodySampling = 1.0)
95-
fun updatePetWithForm(@PathParam("petId") petId: kotlin.Long, @QueryParam(value = "name") name: kotlin.String? , @QueryParam(value = "status") status: kotlin.String? ) {
95+
override fun updatePetWithForm(@PathParam("petId") petId: kotlin.Long, @QueryParam(value = "name") name: kotlin.String? , @QueryParam(value = "status") status: kotlin.String? ) {
9696
TODO()
9797
}
9898

@@ -101,7 +101,7 @@ import okhttp3.Headers
101101
@RequestContentType(MediaTypes.APPLICATION_OCTETSTREAM /* unknown -> multipart/form-data */ )
102102
@ResponseContentType(MediaTypes.APPLICATION_JSON)
103103
@LogRequestResponse(bodySampling = 1.0, errorBodySampling = 1.0)
104-
fun uploadFile(@PathParam("petId") petId: kotlin.Long, @QueryParam(value = "additionalMetadata") additionalMetadata: kotlin.String? , @Valid file: HttpCall): ModelApiResponse {
104+
override fun uploadFile(@PathParam("petId") petId: kotlin.Long, @QueryParam(value = "additionalMetadata") additionalMetadata: kotlin.String? , @Valid file: HttpCall): ModelApiResponse {
105105
TODO()
106106
}
107107
}

samples/server/petstore/kotlin-misk/src/main/kotlin/org/openapitools/server/api/api/PetApiImpl.kt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,35 +14,35 @@ import okhttp3.Headers
1414
class PetApiImpl @Inject constructor(
1515
): PetApi {
1616

17-
override fun addPet(pet: Pet): Pet {
17+
override fun addPet(@Valid @RequestBody pet: Pet): Pet {
1818
TODO()
1919
}
2020

21-
override fun deletePet(petId: kotlin.Long, headers: Headers) {
21+
override fun deletePet(@PathParam("petId") petId: kotlin.Long, apiKey: Headers) {
2222
TODO()
2323
}
2424

25-
override fun findPetsByStatus(status: kotlin.Array<kotlin.String>): kotlin.Array<Pet> {
25+
override fun findPetsByStatus( @QueryParam(value = "status") status: kotlin.Array<kotlin.String>): kotlin.Array<Pet> {
2626
TODO()
2727
}
2828

29-
override fun findPetsByTags(tags: kotlin.Array<kotlin.String>): kotlin.Array<Pet> {
29+
override fun findPetsByTags( @QueryParam(value = "tags") tags: kotlin.Array<kotlin.String>): kotlin.Array<Pet> {
3030
TODO()
3131
}
3232

33-
override fun getPetById(petId: kotlin.Long): Pet {
33+
override fun getPetById(@PathParam("petId") petId: kotlin.Long): Pet {
3434
TODO()
3535
}
3636

37-
override fun updatePet(pet: Pet): Pet {
37+
override fun updatePet(@Valid @RequestBody pet: Pet): Pet {
3838
TODO()
3939
}
4040

41-
override fun updatePetWithForm(petId: kotlin.Long, , ) {
41+
override fun updatePetWithForm(@PathParam("petId") petId: kotlin.Long, @QueryParam(value = "name") name: kotlin.String? , @QueryParam(value = "status") status: kotlin.String? ) {
4242
TODO()
4343
}
4444

45-
override fun uploadFile(petId: kotlin.Long, , ): ModelApiResponse {
45+
override fun uploadFile(@PathParam("petId") petId: kotlin.Long, @QueryParam(value = "additionalMetadata") additionalMetadata: kotlin.String? , @Valid file: HttpCall): ModelApiResponse {
4646
TODO()
4747
}
4848
}

samples/server/petstore/kotlin-misk/src/main/kotlin/org/openapitools/server/api/api/StoreApi.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ import okhttp3.Headers
55

66
interface StoreApi {
77

8-
fun deleteOrder(orderId: kotlin.String)
8+
fun deleteOrder(@PathParam("orderId") orderId: kotlin.String) {
99

10-
fun getInventory(): kotlin.collections.Map<kotlin.String, kotlin.Int>
10+
fun getInventory(): kotlin.collections.Map<kotlin.String, kotlin.Int> {
1111

12-
fun getOrderById(orderId: kotlin.Long): Order
12+
fun getOrderById(@Min(1L) @Max(5L) @PathParam("orderId") orderId: kotlin.Long): Order {
1313

14-
fun placeOrder(order: Order): Order
14+
fun placeOrder(@Valid @RequestBody order: Order): Order {
1515
}

0 commit comments

Comments
 (0)