Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1139,7 +1139,7 @@ Here is a list of template creators:
* Kotlin (Spring Boot): @dr4ke616
* Kotlin (Vertx): @Wooyme
* Kotlin (JAX-RS): @anttileppa
* Kotlin Misk: @andrewwilsonnew
* Kotlin Misk: @andrewwilsonnew @guiarn
* Kotlin WireMock: @stefankoppier
* NodeJS Express: @YishTish
* PHP Flight: @daniel-sc
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,7 @@ public class KotlinMiskServerCodegen extends AbstractKotlinCodegen implements Be
protected String rootPackage = "org.openapitools.server.api";
protected String apiVersion = "1.0.0-SNAPSHOT";

@Setter
protected String moduleClassName = "OpenApiModule";
@Setter protected String moduleClassName = "OpenApiModule";

@Override
public CodegenType getTag() {
Expand Down Expand Up @@ -122,7 +121,7 @@ public KotlinMiskServerCodegen() {
supportingFiles.clear();

apiTemplateFiles.clear();
apiTemplateFiles.put("apiController.mustache", "Controller.kt");
apiTemplateFiles.put("apiAction.mustache", "Action.kt");
apiTemplateFiles.put("apiImpl.mustache", "Impl.kt");
apiTemplateFiles.put("apiInterface.mustache", ".kt");
modelTemplateFiles.put("model.mustache", ".kt");
Expand Down Expand Up @@ -199,30 +198,38 @@ public boolean getUseBeanValidation() {
}

private String mapMediaType(String mediaType) {
return MEDIA_MAPPING.getOrDefault(mediaType, "MediaTypes.APPLICATION_OCTETSTREAM /* unknown -> " + mediaType + " */ ");
return MEDIA_MAPPING.getOrDefault(mediaType, "MediaTypes.APPLICATION_OCTETSTREAM /* @todo(unknown) -> " + mediaType + " */ ");
}

private final static Map<String, String> MEDIA_MAPPING = getMappings();

private static Map<String, String> getMappings() {
// add new values in order
Map<String, String> result = new HashMap<>();
result.put("application/json", "MediaTypes.APPLICATION_JSON");
result.put("application/xml", "MediaTypes.APPLICATION_XML");
result.put("application/javascript", "MediaTypes.APPLICATION_JAVASCRIPT");
result.put("*/*", "MediaTypes.ALL");
result.put("application/x-www-form-urlencoded", "MediaTypes.APPLICATION_FORM_URLENCODED");

result.put("application/grpc", "MediaTypes.APPLICATION_GRPC");
result.put("application/javascript", "MediaTypes.APPLICATION_JAVASCRIPT");
result.put("application/json", "MediaTypes.APPLICATION_JSON");
result.put("application/octetstream", "MediaTypes.APPLICATION_OCTETSTREAM");
result.put("application/pdf", "MediaTypes.APPLICATION_OCTETSTREAM");
result.put("application/x-protobuf", "MediaTypes.APPLICATION_PROTOBUF");
result.put("application/grpc", "MediaTypes.APPLICATION_GRPC");
result.put("text/css", "MediaTypes.TEXT_CSS");
result.put("text/html", "MediaTypes.TEXT_HTML");
result.put("text/plain", "MediaTypes.TEXT_PLAIN_UTF8");
result.put("application/x-www-form-urlencoded", "MediaTypes.APPLICATION_FORM_URLENCODED");
result.put("application/xml", "MediaTypes.APPLICATION_XML");
result.put("application/zip", "MediaTypes.APPLICATION_ZIP");

result.put("image/gif", "MediaTypes.IMAGE_GIF");
result.put("image/jpeg", "MediaTypes.IMAGE_JPEG");
result.put("image/png", "MediaTypes.IMAGE_PNG");
result.put("image/svg+xml", "MediaTypes.IMAGE_SVG");
result.put("image/jpeg", "MediaTypes.IMAGE_JPEG");
result.put("image/gif", "MediaTypes.IMAGE_GIF");
result.put("image/x-icon", "MediaTypes.IMAGE_ICO");

result.put("multipart/form-data", "MediaTypes.FORM_DATA");

result.put("text/css", "MediaTypes.TEXT_CSS");
result.put("text/html", "MediaTypes.TEXT_HTML");
result.put("text/plain", "MediaTypes.TEXT_PLAIN_UTF8");

return result;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ import misk.web.mediatype.MediaTypes

{{#operations}}
/**
* Generated file, please change {{classname}}Controller.
* Generated file, please change {{classname}}Impl.
*/
@Singleton
class {{classname}}Controller @Inject constructor(
class {{classname}}Action @Inject constructor(
private val {{#lambda.camelcase}}{{classname}}{{/lambda.camelcase}}: {{classname}}
) : WebAction, {{classname}} {
{{#operation}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ internal class {{classname}}Test {
{{#operations}}
{{#operation}}
/**
* To test {{classname}}Controller.{{operationId}}
* To test {{classname}}Action.{{operationId}}
*/
@Test
fun `should handle {{operationId}}`() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ version = "{{artifactVersion}}"

dependencies {
implementation("jakarta.validation:jakarta.validation-api:3.1.1")
implementation("com.squareup.misk:misk:2025.03.17.160337-2c6953c")
implementation("com.squareup.misk:misk:2025.04.02.195630-a61d550")
//implementation("com.squareup.wire:wire-runtime:5.2.1")

testImplementation("com.squareup.misk:misk-testing:2025.02.11.123913-8a41324")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {{javaxPackage}}.inject.Singleton
{{#apiInfo}}
{{#apis}}
{{#operations}}
import {{apiPackage}}.{{classname}}Controller
import {{apiPackage}}.{{classname}}Action
{{/operations}}
{{/apis}}
{{/apiInfo}}
Expand All @@ -17,7 +17,7 @@ class {{moduleClassName}} : KAbstractModule() {
{{#apiInfo}}
{{#apis}}
{{#operations}}
install(WebActionModule.create<{{classname}}Controller>())
install(WebActionModule.create<{{classname}}Action>())
{{/operations}}
{{/apis}}
{{/apiInfo}}
Expand Down
6 changes: 3 additions & 3 deletions samples/server/petstore/kotlin-misk/.openapi-generator/FILES
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ docs/User.md
docs/UserApi.md
settings.gradle.kts
src/main/kotlin/org/openapitools/server/api/api/PetApi.kt
src/main/kotlin/org/openapitools/server/api/api/PetApiController.kt
src/main/kotlin/org/openapitools/server/api/api/PetApiAction.kt
src/main/kotlin/org/openapitools/server/api/api/PetApiImpl.kt
src/main/kotlin/org/openapitools/server/api/api/PetStoreModule.kt
src/main/kotlin/org/openapitools/server/api/api/StoreApi.kt
src/main/kotlin/org/openapitools/server/api/api/StoreApiController.kt
src/main/kotlin/org/openapitools/server/api/api/StoreApiAction.kt
src/main/kotlin/org/openapitools/server/api/api/StoreApiImpl.kt
src/main/kotlin/org/openapitools/server/api/api/UserApi.kt
src/main/kotlin/org/openapitools/server/api/api/UserApiController.kt
src/main/kotlin/org/openapitools/server/api/api/UserApiAction.kt
src/main/kotlin/org/openapitools/server/api/api/UserApiImpl.kt
src/main/kotlin/org/openapitools/server/api/model/Category.kt
src/main/kotlin/org/openapitools/server/api/model/ModelApiResponse.kt
Expand Down
2 changes: 1 addition & 1 deletion samples/server/petstore/kotlin-misk/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ version = "1.0.0-SNAPSHOT"

dependencies {
implementation("jakarta.validation:jakarta.validation-api:3.1.1")
implementation("com.squareup.misk:misk:2025.03.17.160337-2c6953c")
implementation("com.squareup.misk:misk:2025.04.02.195630-a61d550")
//implementation("com.squareup.wire:wire-runtime:5.2.1")

testImplementation("com.squareup.misk:misk-testing:2025.02.11.123913-8a41324")
Expand Down
2 changes: 1 addition & 1 deletion samples/server/petstore/kotlin-misk/docs/PetApi.md
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,6 @@ Name | Type | Description | Notes

### HTTP request headers

- **Content-Type**: MediaTypes.APPLICATION_OCTETSTREAM /* unknown -> multipart/form-data */
- **Content-Type**: MediaTypes.FORM_DATA
- **Accept**: MediaTypes.APPLICATION_JSON

Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ import org.openapitools.server.api.model.ModelApiResponse
import org.openapitools.server.api.model.Pet

/**
* Generated file, please change PetApiController.
* Generated file, please change PetApiImpl.
*/
@Singleton
class PetApiController @Inject constructor(
class PetApiAction @Inject constructor(
private val petApi: PetApi
) : WebAction, PetApi {

Expand Down Expand Up @@ -97,7 +97,7 @@ class PetApiController @Inject constructor(

@Post("/pet/{petId}/uploadImage")
@Description("uploads an image")
@RequestContentType(MediaTypes.APPLICATION_OCTETSTREAM /* unknown -> multipart/form-data */ )
@RequestContentType(MediaTypes.FORM_DATA)
@ResponseContentType(MediaTypes.APPLICATION_JSON)
@LogRequestResponse(bodySampling = 1.0, errorBodySampling = 1.0)
override fun uploadFile(@PathParam("petId") petId: kotlin.Long, @QueryParam(value = "additionalMetadata") additionalMetadata: kotlin.String? , @Valid file: HttpCall): ModelApiResponse {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ package org.openapitools.server.api.api
import misk.inject.KAbstractModule
import misk.web.WebActionModule
import jakarta.inject.Singleton
import org.openapitools.server.api.api.PetApiController
import org.openapitools.server.api.api.StoreApiController
import org.openapitools.server.api.api.UserApiController
import org.openapitools.server.api.api.PetApiAction
import org.openapitools.server.api.api.StoreApiAction
import org.openapitools.server.api.api.UserApiAction

@Singleton
class PetStoreModule : KAbstractModule() {
override fun configure() {
install(WebActionModule.create<PetApiController>())
install(WebActionModule.create<StoreApiController>())
install(WebActionModule.create<UserApiController>())
install(WebActionModule.create<PetApiAction>())
install(WebActionModule.create<StoreApiAction>())
install(WebActionModule.create<UserApiAction>())
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ import misk.web.mediatype.MediaTypes
import org.openapitools.server.api.model.Order

/**
* Generated file, please change StoreApiController.
* Generated file, please change StoreApiImpl.
*/
@Singleton
class StoreApiController @Inject constructor(
class StoreApiAction @Inject constructor(
private val storeApi: StoreApi
) : WebAction, StoreApi {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ import misk.web.mediatype.MediaTypes
import org.openapitools.server.api.model.User

/**
* Generated file, please change UserApiController.
* Generated file, please change UserApiImpl.
*/
@Singleton
class UserApiController @Inject constructor(
class UserApiAction @Inject constructor(
private val userApi: UserApi
) : WebAction, UserApi {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ internal class PetApiTest {
@Inject private lateinit var petApi: PetApi

/**
* To test PetApiController.addPet
* To test PetApiAction.addPet
*/
@Test
fun `should handle addPet`() {
Expand All @@ -28,7 +28,7 @@ internal class PetApiTest {
}

/**
* To test PetApiController.deletePet
* To test PetApiAction.deletePet
*/
@Test
fun `should handle deletePet`() {
Expand All @@ -38,7 +38,7 @@ internal class PetApiTest {
}

/**
* To test PetApiController.findPetsByStatus
* To test PetApiAction.findPetsByStatus
*/
@Test
fun `should handle findPetsByStatus`() {
Expand All @@ -47,7 +47,7 @@ internal class PetApiTest {
}

/**
* To test PetApiController.findPetsByTags
* To test PetApiAction.findPetsByTags
*/
@Test
fun `should handle findPetsByTags`() {
Expand All @@ -56,7 +56,7 @@ internal class PetApiTest {
}

/**
* To test PetApiController.getPetById
* To test PetApiAction.getPetById
*/
@Test
fun `should handle getPetById`() {
Expand All @@ -65,7 +65,7 @@ internal class PetApiTest {
}

/**
* To test PetApiController.updatePet
* To test PetApiAction.updatePet
*/
@Test
fun `should handle updatePet`() {
Expand All @@ -74,7 +74,7 @@ internal class PetApiTest {
}

/**
* To test PetApiController.updatePetWithForm
* To test PetApiAction.updatePetWithForm
*/
@Test
fun `should handle updatePetWithForm`() {
Expand All @@ -85,7 +85,7 @@ internal class PetApiTest {
}

/**
* To test PetApiController.uploadFile
* To test PetApiAction.uploadFile
*/
@Test
fun `should handle uploadFile`() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ internal class StoreApiTest {
@Inject private lateinit var storeApi: StoreApi

/**
* To test StoreApiController.deleteOrder
* To test StoreApiAction.deleteOrder
*/
@Test
fun `should handle deleteOrder`() {
Expand All @@ -27,15 +27,15 @@ internal class StoreApiTest {
}

/**
* To test StoreApiController.getInventory
* To test StoreApiAction.getInventory
*/
@Test
fun `should handle getInventory`() {
val response: kotlin.collections.Map<kotlin.String, kotlin.Int> = storeApi.getInventory()
}

/**
* To test StoreApiController.getOrderById
* To test StoreApiAction.getOrderById
*/
@Test
fun `should handle getOrderById`() {
Expand All @@ -44,7 +44,7 @@ internal class StoreApiTest {
}

/**
* To test StoreApiController.placeOrder
* To test StoreApiAction.placeOrder
*/
@Test
fun `should handle placeOrder`() {
Expand Down
Loading
Loading