mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-05-12 20:50:55 +00:00
Improving Misk Kotlin Server Generator (#20973)
* first pass * fixing types * fixing action * updating samples * updating files * adding guido * fixing misk * removing old files * cleaning generated files * cleaning generated files * adding back in license
This commit is contained in:
parent
04169ec29b
commit
9bac31859c
@ -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
|
||||
|
@ -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() {
|
||||
@ -122,7 +121,7 @@ public class KotlinMiskServerCodegen extends AbstractKotlinCodegen implements Be
|
||||
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");
|
||||
@ -199,30 +198,38 @@ public class KotlinMiskServerCodegen extends AbstractKotlinCodegen implements Be
|
||||
}
|
||||
|
||||
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("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/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");
|
||||
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");
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
@ -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}}
|
@ -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}}`() {
|
||||
|
@ -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")
|
||||
|
@ -6,7 +6,7 @@ import {{javaxPackage}}.inject.Singleton
|
||||
{{#apiInfo}}
|
||||
{{#apis}}
|
||||
{{#operations}}
|
||||
import {{apiPackage}}.{{classname}}Controller
|
||||
import {{apiPackage}}.{{classname}}Action
|
||||
{{/operations}}
|
||||
{{/apis}}
|
||||
{{/apiInfo}}
|
||||
@ -17,7 +17,7 @@ class {{moduleClassName}} : KAbstractModule() {
|
||||
{{#apiInfo}}
|
||||
{{#apis}}
|
||||
{{#operations}}
|
||||
install(WebActionModule.create<{{classname}}Controller>())
|
||||
install(WebActionModule.create<{{classname}}Action>())
|
||||
{{/operations}}
|
||||
{{/apis}}
|
||||
{{/apiInfo}}
|
||||
|
@ -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
|
||||
|
@ -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")
|
||||
|
@ -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
|
||||
|
||||
|
@ -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 {
|
||||
|
||||
@ -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 {
|
@ -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>())
|
||||
}
|
||||
}
|
@ -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 {
|
||||
|
@ -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 {
|
||||
|
@ -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`() {
|
||||
@ -28,7 +28,7 @@ internal class PetApiTest {
|
||||
}
|
||||
|
||||
/**
|
||||
* To test PetApiController.deletePet
|
||||
* To test PetApiAction.deletePet
|
||||
*/
|
||||
@Test
|
||||
fun `should handle deletePet`() {
|
||||
@ -38,7 +38,7 @@ internal class PetApiTest {
|
||||
}
|
||||
|
||||
/**
|
||||
* To test PetApiController.findPetsByStatus
|
||||
* To test PetApiAction.findPetsByStatus
|
||||
*/
|
||||
@Test
|
||||
fun `should handle findPetsByStatus`() {
|
||||
@ -47,7 +47,7 @@ internal class PetApiTest {
|
||||
}
|
||||
|
||||
/**
|
||||
* To test PetApiController.findPetsByTags
|
||||
* To test PetApiAction.findPetsByTags
|
||||
*/
|
||||
@Test
|
||||
fun `should handle findPetsByTags`() {
|
||||
@ -56,7 +56,7 @@ internal class PetApiTest {
|
||||
}
|
||||
|
||||
/**
|
||||
* To test PetApiController.getPetById
|
||||
* To test PetApiAction.getPetById
|
||||
*/
|
||||
@Test
|
||||
fun `should handle getPetById`() {
|
||||
@ -65,7 +65,7 @@ internal class PetApiTest {
|
||||
}
|
||||
|
||||
/**
|
||||
* To test PetApiController.updatePet
|
||||
* To test PetApiAction.updatePet
|
||||
*/
|
||||
@Test
|
||||
fun `should handle updatePet`() {
|
||||
@ -74,7 +74,7 @@ internal class PetApiTest {
|
||||
}
|
||||
|
||||
/**
|
||||
* To test PetApiController.updatePetWithForm
|
||||
* To test PetApiAction.updatePetWithForm
|
||||
*/
|
||||
@Test
|
||||
fun `should handle updatePetWithForm`() {
|
||||
@ -85,7 +85,7 @@ internal class PetApiTest {
|
||||
}
|
||||
|
||||
/**
|
||||
* To test PetApiController.uploadFile
|
||||
* To test PetApiAction.uploadFile
|
||||
*/
|
||||
@Test
|
||||
fun `should handle uploadFile`() {
|
||||
|
@ -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`() {
|
||||
@ -27,7 +27,7 @@ internal class StoreApiTest {
|
||||
}
|
||||
|
||||
/**
|
||||
* To test StoreApiController.getInventory
|
||||
* To test StoreApiAction.getInventory
|
||||
*/
|
||||
@Test
|
||||
fun `should handle getInventory`() {
|
||||
@ -35,7 +35,7 @@ internal class StoreApiTest {
|
||||
}
|
||||
|
||||
/**
|
||||
* To test StoreApiController.getOrderById
|
||||
* To test StoreApiAction.getOrderById
|
||||
*/
|
||||
@Test
|
||||
fun `should handle getOrderById`() {
|
||||
@ -44,7 +44,7 @@ internal class StoreApiTest {
|
||||
}
|
||||
|
||||
/**
|
||||
* To test StoreApiController.placeOrder
|
||||
* To test StoreApiAction.placeOrder
|
||||
*/
|
||||
@Test
|
||||
fun `should handle placeOrder`() {
|
||||
|
@ -18,7 +18,7 @@ internal class UserApiTest {
|
||||
@Inject private lateinit var userApi: UserApi
|
||||
|
||||
/**
|
||||
* To test UserApiController.createUser
|
||||
* To test UserApiAction.createUser
|
||||
*/
|
||||
@Test
|
||||
fun `should handle createUser`() {
|
||||
@ -27,7 +27,7 @@ internal class UserApiTest {
|
||||
}
|
||||
|
||||
/**
|
||||
* To test UserApiController.createUsersWithArrayInput
|
||||
* To test UserApiAction.createUsersWithArrayInput
|
||||
*/
|
||||
@Test
|
||||
fun `should handle createUsersWithArrayInput`() {
|
||||
@ -36,7 +36,7 @@ internal class UserApiTest {
|
||||
}
|
||||
|
||||
/**
|
||||
* To test UserApiController.createUsersWithListInput
|
||||
* To test UserApiAction.createUsersWithListInput
|
||||
*/
|
||||
@Test
|
||||
fun `should handle createUsersWithListInput`() {
|
||||
@ -45,7 +45,7 @@ internal class UserApiTest {
|
||||
}
|
||||
|
||||
/**
|
||||
* To test UserApiController.deleteUser
|
||||
* To test UserApiAction.deleteUser
|
||||
*/
|
||||
@Test
|
||||
fun `should handle deleteUser`() {
|
||||
@ -54,7 +54,7 @@ internal class UserApiTest {
|
||||
}
|
||||
|
||||
/**
|
||||
* To test UserApiController.getUserByName
|
||||
* To test UserApiAction.getUserByName
|
||||
*/
|
||||
@Test
|
||||
fun `should handle getUserByName`() {
|
||||
@ -63,7 +63,7 @@ internal class UserApiTest {
|
||||
}
|
||||
|
||||
/**
|
||||
* To test UserApiController.loginUser
|
||||
* To test UserApiAction.loginUser
|
||||
*/
|
||||
@Test
|
||||
fun `should handle loginUser`() {
|
||||
@ -73,7 +73,7 @@ internal class UserApiTest {
|
||||
}
|
||||
|
||||
/**
|
||||
* To test UserApiController.logoutUser
|
||||
* To test UserApiAction.logoutUser
|
||||
*/
|
||||
@Test
|
||||
fun `should handle logoutUser`() {
|
||||
@ -81,7 +81,7 @@ internal class UserApiTest {
|
||||
}
|
||||
|
||||
/**
|
||||
* To test UserApiController.updateUser
|
||||
* To test UserApiAction.updateUser
|
||||
*/
|
||||
@Test
|
||||
fun `should handle updateUser`() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user