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
Original file line number Diff line number Diff line change
Expand Up @@ -95,48 +95,19 @@ public KotlinSpringServerCodegen() {
updateOption(CodegenConstants.ARTIFACT_ID, this.artifactId);

// Use lists instead of arrays
typeMapping.put("array", "List");
typeMapping.put("string", "String");
typeMapping.put("boolean", "Boolean");
typeMapping.put("integer", "Int");
typeMapping.put("float", "Float");
typeMapping.put("long", "Long");
typeMapping.put("double", "Double");
typeMapping.put("ByteArray", "ByteArray");
typeMapping.put("list", "List");
typeMapping.put("map", "Map");
typeMapping.put("object", "Any");
typeMapping.put("binary", "Array<kotlin.Byte>");
typeMapping.put("array", "kotlin.collections.List");
typeMapping.put("list", "kotlin.collections.List");

typeMapping.put("date", "java.time.LocalDate");
typeMapping.put("date-time", "java.time.OffsetDateTime");
typeMapping.put("Date", "java.time.LocalDate");
typeMapping.put("DateTime", "java.time.OffsetDateTime");

importMapping.put("Date", "java.time.LocalDate");
importMapping.put("DateTime", "java.time.OffsetDateTime");

// use resource for file handling
typeMapping.put("file", "org.springframework.core.io.Resource");


languageSpecificPrimitives.addAll(Arrays.asList(
"Any",
"Byte",
"ByteArray",
"Short",
"Int",
"Long",
"Float",
"Double",
"Boolean",
"Char",
"String",
"Array",
"List",
"Map",
"Set"
));
importMapping.put("Date", "java.time.LocalDate");
importMapping.put("DateTime", "java.time.OffsetDateTime");

addOption(TITLE, "server title name or client service name", title);
addOption(BASE_PACKAGE, "base package (invokerPackage) for generated code", basePackage);
Expand Down Expand Up @@ -543,16 +514,16 @@ private interface DataTypeAssigner {
private void doDataTypeAssignment(final String returnType, DataTypeAssigner dataTypeAssigner) {
if (returnType == null) {
dataTypeAssigner.setReturnType("Unit");
} else if (returnType.startsWith("List")) {
} else if (returnType.startsWith("kotlin.collections.List")) {
int end = returnType.lastIndexOf(">");
if (end > 0) {
dataTypeAssigner.setReturnType(returnType.substring("List<".length(), end).trim());
dataTypeAssigner.setReturnType(returnType.substring("kotlin.collections.List<".length(), end).trim());
dataTypeAssigner.setReturnContainer("List");
}
} else if (returnType.startsWith("Map")) {
} else if (returnType.startsWith("kotlin.collections.Map")) {
int end = returnType.lastIndexOf(">");
if (end > 0) {
dataTypeAssigner.setReturnType(returnType.substring("Map<".length(), end).split(",")[1].trim());
dataTypeAssigner.setReturnType(returnType.substring("kotlin.collections.Map<".length(), end).split(",")[1].trim());
dataTypeAssigner.setReturnContainer("Map");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ dependencies {
compile("com.fasterxml.jackson.dataformat:jackson-dataformat-xml")
compile("com.fasterxml.jackson.module:jackson-module-kotlin")

testCompile("org.jetbrains.kotlin:kotlin-test-junit5")
testCompile("org.springframework.boot:spring-boot-starter-test") {
exclude(module = "junit")
}
Expand Down
6 changes: 6 additions & 0 deletions samples/server/openapi3/petstore/kotlin-springboot/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,12 @@
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-test-junit5</artifactId>
<version>1.3.31</version>
<scope>test</scope>
</dependency>
</dependencies>
<repositories>
<repository>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ class PetApiController(@Autowired(required = true) val service: PetApiService) {
@RequestMapping(
value = ["/pet/{petId}"],
method = [RequestMethod.DELETE])
fun deletePet(@ApiParam(value = "Pet id to delete", required=true) @PathVariable("petId") petId: Long
,@ApiParam(value = "" ) @RequestHeader(value="api_key", required=false) apiKey: String?
fun deletePet(@ApiParam(value = "Pet id to delete", required=true) @PathVariable("petId") petId: kotlin.Long
,@ApiParam(value = "" ) @RequestHeader(value="api_key", required=false) apiKey: kotlin.String?
): ResponseEntity<Unit> {
return ResponseEntity(service.deletePet(petId, apiKey), HttpStatus.OK)
}
Expand All @@ -88,7 +88,7 @@ class PetApiController(@Autowired(required = true) val service: PetApiService) {
value = ["/pet/findByStatus"],
produces = ["application/xml", "application/json"],
method = [RequestMethod.GET])
fun findPetsByStatus(@NotNull @ApiParam(value = "Status values that need to be considered for filter", required = true, allowableValues = "available, pending, sold") @Valid @RequestParam(value = "status", required = true) status: List<String>
fun findPetsByStatus(@NotNull @ApiParam(value = "Status values that need to be considered for filter", required = true, allowableValues = "available, pending, sold") @Valid @RequestParam(value = "status", required = true) status: kotlin.collections.List<kotlin.String>
): ResponseEntity<List<Pet>> {
return ResponseEntity(service.findPetsByStatus(status), HttpStatus.OK)
}
Expand All @@ -106,8 +106,8 @@ class PetApiController(@Autowired(required = true) val service: PetApiService) {
value = ["/pet/findByTags"],
produces = ["application/xml", "application/json"],
method = [RequestMethod.GET])
fun findPetsByTags(@NotNull @ApiParam(value = "Tags to filter by", required = true) @Valid @RequestParam(value = "tags", required = true) tags: List<String>
,@ApiParam(value = "Maximum number of items to return") @Valid @RequestParam(value = "maxCount", required = false) maxCount: Int?
fun findPetsByTags(@NotNull @ApiParam(value = "Tags to filter by", required = true) @Valid @RequestParam(value = "tags", required = true) tags: kotlin.collections.List<kotlin.String>
,@ApiParam(value = "Maximum number of items to return") @Valid @RequestParam(value = "maxCount", required = false) maxCount: kotlin.Int?
): ResponseEntity<List<Pet>> {
return ResponseEntity(service.findPetsByTags(tags, maxCount), HttpStatus.OK)
}
Expand All @@ -124,7 +124,7 @@ class PetApiController(@Autowired(required = true) val service: PetApiService) {
value = ["/pet/{petId}"],
produces = ["application/xml", "application/json"],
method = [RequestMethod.GET])
fun getPetById(@ApiParam(value = "ID of pet to return", required=true) @PathVariable("petId") petId: Long
fun getPetById(@ApiParam(value = "ID of pet to return", required=true) @PathVariable("petId") petId: kotlin.Long
): ResponseEntity<Pet> {
return ResponseEntity(service.getPetById(petId), HttpStatus.OK)
}
Expand Down Expand Up @@ -156,9 +156,9 @@ class PetApiController(@Autowired(required = true) val service: PetApiService) {
value = ["/pet/{petId}"],
consumes = ["application/x-www-form-urlencoded"],
method = [RequestMethod.POST])
fun updatePetWithForm(@ApiParam(value = "ID of pet that needs to be updated", required=true) @PathVariable("petId") petId: Long
,@ApiParam(value = "Updated name of the pet") @RequestParam(value="name", required=false) name: String?
,@ApiParam(value = "Updated status of the pet") @RequestParam(value="status", required=false) status: String?
fun updatePetWithForm(@ApiParam(value = "ID of pet that needs to be updated", required=true) @PathVariable("petId") petId: kotlin.Long
,@ApiParam(value = "Updated name of the pet") @RequestParam(value="name", required=false) name: kotlin.String?
,@ApiParam(value = "Updated status of the pet") @RequestParam(value="status", required=false) status: kotlin.String?
): ResponseEntity<Unit> {
return ResponseEntity(service.updatePetWithForm(petId, name, status), HttpStatus.OK)
}
Expand All @@ -176,8 +176,8 @@ class PetApiController(@Autowired(required = true) val service: PetApiService) {
produces = ["application/json"],
consumes = ["multipart/form-data"],
method = [RequestMethod.POST])
fun uploadFile(@ApiParam(value = "ID of pet to update", required=true) @PathVariable("petId") petId: Long
,@ApiParam(value = "Additional data to pass to server") @RequestParam(value="additionalMetadata", required=false) additionalMetadata: String?
fun uploadFile(@ApiParam(value = "ID of pet to update", required=true) @PathVariable("petId") petId: kotlin.Long
,@ApiParam(value = "Additional data to pass to server") @RequestParam(value="additionalMetadata", required=false) additionalMetadata: kotlin.String?
,@ApiParam(value = "file detail") @Valid @RequestPart("file") file: org.springframework.core.io.Resource?
): ResponseEntity<ModelApiResponse> {
return ResponseEntity(service.uploadFile(petId, additionalMetadata, file), HttpStatus.OK)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@ interface PetApiService {

fun addPet(pet: Pet): Unit

fun deletePet(petId: Long, apiKey: String?): Unit
fun deletePet(petId: kotlin.Long, apiKey: kotlin.String?): Unit

fun findPetsByStatus(status: List<String>): List<Pet>
fun findPetsByStatus(status: kotlin.collections.List<kotlin.String>): List<Pet>

fun findPetsByTags(tags: List<String>, maxCount: Int?): List<Pet>
fun findPetsByTags(tags: kotlin.collections.List<kotlin.String>, maxCount: kotlin.Int?): List<Pet>

fun getPetById(petId: Long): Pet
fun getPetById(petId: kotlin.Long): Pet

fun updatePet(pet: Pet): Unit

fun updatePetWithForm(petId: Long, name: String?, status: String?): Unit
fun updatePetWithForm(petId: kotlin.Long, name: kotlin.String?, status: kotlin.String?): Unit

fun uploadFile(petId: Long, additionalMetadata: String?, file: org.springframework.core.io.Resource?): ModelApiResponse
fun uploadFile(petId: kotlin.Long, additionalMetadata: kotlin.String?, file: org.springframework.core.io.Resource?): ModelApiResponse
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,31 +10,31 @@ class PetApiServiceImpl : PetApiService {
TODO("Implement me")
}

override fun deletePet(petId: Long, apiKey: String?): Unit {
override fun deletePet(petId: kotlin.Long, apiKey: kotlin.String?): Unit {
TODO("Implement me")
}

override fun findPetsByStatus(status: List<String>): List<Pet> {
override fun findPetsByStatus(status: kotlin.collections.List<kotlin.String>): List<Pet> {
TODO("Implement me")
}

override fun findPetsByTags(tags: List<String>, maxCount: Int?): List<Pet> {
override fun findPetsByTags(tags: kotlin.collections.List<kotlin.String>, maxCount: kotlin.Int?): List<Pet> {
TODO("Implement me")
}

override fun getPetById(petId: Long): Pet {
override fun getPetById(petId: kotlin.Long): Pet {
TODO("Implement me")
}

override fun updatePet(pet: Pet): Unit {
TODO("Implement me")
}

override fun updatePetWithForm(petId: Long, name: String?, status: String?): Unit {
override fun updatePetWithForm(petId: kotlin.Long, name: kotlin.String?, status: kotlin.String?): Unit {
TODO("Implement me")
}

override fun uploadFile(petId: Long, additionalMetadata: String?, file: org.springframework.core.io.Resource?): ModelApiResponse {
override fun uploadFile(petId: kotlin.Long, additionalMetadata: kotlin.String?, file: org.springframework.core.io.Resource?): ModelApiResponse {
TODO("Implement me")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class StoreApiController(@Autowired(required = true) val service: StoreApiServic
@RequestMapping(
value = ["/store/order/{orderId}"],
method = [RequestMethod.DELETE])
fun deleteOrder(@ApiParam(value = "ID of the order that needs to be deleted", required=true) @PathVariable("orderId") orderId: String
fun deleteOrder(@ApiParam(value = "ID of the order that needs to be deleted", required=true) @PathVariable("orderId") orderId: kotlin.String
): ResponseEntity<Unit> {
return ResponseEntity(service.deleteOrder(orderId), HttpStatus.OK)
}
Expand All @@ -60,16 +60,16 @@ class StoreApiController(@Autowired(required = true) val service: StoreApiServic
value = "Returns pet inventories by status",
nickname = "getInventory",
notes = "Returns a map of status codes to quantities",
response = Int::class,
response = kotlin.Int::class,
responseContainer = "Map",
authorizations = [Authorization(value = "api_key")])
@ApiResponses(
value = [ApiResponse(code = 200, message = "successful operation", response = Map::class, responseContainer = "Map")])
value = [ApiResponse(code = 200, message = "successful operation", response = kotlin.collections.Map::class, responseContainer = "Map")])
@RequestMapping(
value = ["/store/inventory"],
produces = ["application/json"],
method = [RequestMethod.GET])
fun getInventory(): ResponseEntity<Map<String, Int>> {
fun getInventory(): ResponseEntity<Map<String, kotlin.Int>> {
return ResponseEntity(service.getInventory(), HttpStatus.OK)
}

Expand All @@ -84,7 +84,7 @@ class StoreApiController(@Autowired(required = true) val service: StoreApiServic
value = ["/store/order/{orderId}"],
produces = ["application/xml", "application/json"],
method = [RequestMethod.GET])
fun getOrderById(@Min(1L) @Max(5L) @ApiParam(value = "ID of pet that needs to be fetched", required=true) @PathVariable("orderId") orderId: Long
fun getOrderById(@Min(1L) @Max(5L) @ApiParam(value = "ID of pet that needs to be fetched", required=true) @PathVariable("orderId") orderId: kotlin.Long
): ResponseEntity<Order> {
return ResponseEntity(service.getOrderById(orderId), HttpStatus.OK)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ package org.openapitools.api
import org.openapitools.model.Order
interface StoreApiService {

fun deleteOrder(orderId: String): Unit
fun deleteOrder(orderId: kotlin.String): Unit

fun getInventory(): Map<String, Int>
fun getInventory(): Map<String, kotlin.Int>

fun getOrderById(orderId: Long): Order
fun getOrderById(orderId: kotlin.Long): Order

fun placeOrder(order: Order): Order
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ import org.springframework.stereotype.Service
@Service
class StoreApiServiceImpl : StoreApiService {

override fun deleteOrder(orderId: String): Unit {
override fun deleteOrder(orderId: kotlin.String): Unit {
TODO("Implement me")
}

override fun getInventory(): Map<String, Int> {
override fun getInventory(): Map<String, kotlin.Int> {
TODO("Implement me")
}

override fun getOrderById(orderId: Long): Order {
override fun getOrderById(orderId: kotlin.Long): Order {
TODO("Implement me")
}

Expand Down
Loading