From 1313cff93a73cdbcb9e8d9b34a19326f395f696b Mon Sep 17 00:00:00 2001 From: William Cheng Date: Wed, 27 Mar 2019 22:16:28 +0800 Subject: [PATCH] update kotlin spring samples --- .../kotlin/org/openapitools/api/PetApi.kt | 37 +++++++++++++------ .../org/openapitools/api/PetApiService.kt | 4 +- .../org/openapitools/api/PetApiServiceImpl.kt | 4 +- .../kotlin/org/openapitools/api/StoreApi.kt | 15 +++++--- .../kotlin/org/openapitools/api/UserApi.kt | 27 +++++++++----- 5 files changed, 56 insertions(+), 31 deletions(-) diff --git a/samples/server/petstore/kotlin-springboot/src/main/kotlin/org/openapitools/api/PetApi.kt b/samples/server/petstore/kotlin-springboot/src/main/kotlin/org/openapitools/api/PetApi.kt index 12fa10fb81..8249b82a63 100644 --- a/samples/server/petstore/kotlin-springboot/src/main/kotlin/org/openapitools/api/PetApi.kt +++ b/samples/server/petstore/kotlin-springboot/src/main/kotlin/org/openapitools/api/PetApi.kt @@ -41,7 +41,8 @@ class PetApiController(@Autowired(required = true) val service: PetApiService) { value = ["/pet"], consumes = ["application/json", "application/xml"], method = [RequestMethod.POST]) - fun addPet(@ApiParam(value = "Pet object that needs to be added to the store" ,required=true ) @Valid @RequestBody body: Pet): ResponseEntity { + fun addPet(@ApiParam(value = "Pet object that needs to be added to the store" ,required=true ) @Valid @RequestBody body: Pet +): ResponseEntity { return ResponseEntity(service.addPet(body), HttpStatus.OK) } @@ -55,7 +56,9 @@ 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?): ResponseEntity { + fun deletePet(@ApiParam(value = "Pet id to delete", required=true) @PathVariable("petId") petId: Long +,@ApiParam(value = "" ) @RequestHeader(value="api_key", required=false) apiKey: String? +): ResponseEntity { return ResponseEntity(service.deletePet(petId, apiKey), HttpStatus.OK) } @@ -70,9 +73,10 @@ class PetApiController(@Autowired(required = true) val service: PetApiService) { value = [ApiResponse(code = 200, message = "successful operation", response = Pet::class, responseContainer = "List"),ApiResponse(code = 400, message = "Invalid status value")]) @RequestMapping( value = ["/pet/findByStatus"], - produces = ["application/xml", "application/json"], + 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): ResponseEntity> { + 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 +): ResponseEntity> { return ResponseEntity(service.findPetsByStatus(status), HttpStatus.OK) } @@ -87,9 +91,10 @@ class PetApiController(@Autowired(required = true) val service: PetApiService) { value = [ApiResponse(code = 200, message = "successful operation", response = Pet::class, responseContainer = "List"),ApiResponse(code = 400, message = "Invalid tag value")]) @RequestMapping( value = ["/pet/findByTags"], - produces = ["application/xml", "application/json"], + 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): ResponseEntity> { + fun findPetsByTags(@NotNull @ApiParam(value = "Tags to filter by", required = true) @Valid @RequestParam(value = "tags", required = true) tags: List +): ResponseEntity> { return ResponseEntity(service.findPetsByTags(tags), HttpStatus.OK) } @@ -103,9 +108,10 @@ class PetApiController(@Autowired(required = true) val service: PetApiService) { value = [ApiResponse(code = 200, message = "successful operation", response = Pet::class),ApiResponse(code = 400, message = "Invalid ID supplied"),ApiResponse(code = 404, message = "Pet not found")]) @RequestMapping( value = ["/pet/{petId}"], - produces = ["application/xml", "application/json"], + produces = ["application/xml", "application/json"], method = [RequestMethod.GET]) - fun getPetById(@ApiParam(value = "ID of pet to return", required=true) @PathVariable("petId") petId: Long): ResponseEntity { + fun getPetById(@ApiParam(value = "ID of pet to return", required=true) @PathVariable("petId") petId: Long +): ResponseEntity { return ResponseEntity(service.getPetById(petId), HttpStatus.OK) } @@ -120,7 +126,8 @@ class PetApiController(@Autowired(required = true) val service: PetApiService) { value = ["/pet"], consumes = ["application/json", "application/xml"], method = [RequestMethod.PUT]) - fun updatePet(@ApiParam(value = "Pet object that needs to be added to the store" ,required=true ) @Valid @RequestBody body: Pet): ResponseEntity { + fun updatePet(@ApiParam(value = "Pet object that needs to be added to the store" ,required=true ) @Valid @RequestBody body: Pet +): ResponseEntity { return ResponseEntity(service.updatePet(body), HttpStatus.OK) } @@ -135,7 +142,10 @@ 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, defaultValue="null") @PathVariable("petId") petId: Long,@ApiParam(value = "Updated name of the pet", defaultValue="null") @RequestParam(value="name", required=false) name: String,@ApiParam(value = "Updated status of the pet", defaultValue="null") @RequestParam(value="status", required=false) status: String): ResponseEntity { + 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? +): ResponseEntity { return ResponseEntity(service.updatePetWithForm(petId, name, status), HttpStatus.OK) } @@ -149,10 +159,13 @@ class PetApiController(@Autowired(required = true) val service: PetApiService) { value = [ApiResponse(code = 200, message = "successful operation", response = ModelApiResponse::class)]) @RequestMapping( value = ["/pet/{petId}/uploadImage"], - produces = ["application/json"], + produces = ["application/json"], consumes = ["multipart/form-data"], method = [RequestMethod.POST]) - fun uploadFile(@ApiParam(value = "ID of pet to update", required=true, defaultValue="null") @PathVariable("petId") petId: Long,@ApiParam(value = "Additional data to pass to server", defaultValue="null") @RequestParam(value="additionalMetadata", required=false) additionalMetadata: String,@ApiParam(value = "file detail") @Valid @RequestPart("file") file: org.springframework.core.io.Resource): ResponseEntity { + 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? +,@ApiParam(value = "file detail") @Valid @RequestPart("file") file: org.springframework.core.io.Resource? +): ResponseEntity { return ResponseEntity(service.uploadFile(petId, additionalMetadata, file), HttpStatus.OK) } } diff --git a/samples/server/petstore/kotlin-springboot/src/main/kotlin/org/openapitools/api/PetApiService.kt b/samples/server/petstore/kotlin-springboot/src/main/kotlin/org/openapitools/api/PetApiService.kt index 0bfa0e3717..5218a25b63 100644 --- a/samples/server/petstore/kotlin-springboot/src/main/kotlin/org/openapitools/api/PetApiService.kt +++ b/samples/server/petstore/kotlin-springboot/src/main/kotlin/org/openapitools/api/PetApiService.kt @@ -7,7 +7,7 @@ interface PetApiService { fun addPet(body: Pet): Unit - fun deletePet(petId: Long,apiKey: String?): Unit + fun deletePet(petId: Long,apiKey: String): Unit fun findPetsByStatus(status: List): List @@ -17,7 +17,7 @@ interface PetApiService { fun updatePet(body: Pet): Unit - fun updatePetWithForm(petId: Long,name: String?,status: String?): Unit + fun updatePetWithForm(petId: Long,name: String,status: String): Unit fun uploadFile(petId: Long,additionalMetadata: String,file: org.springframework.core.io.Resource): ModelApiResponse } diff --git a/samples/server/petstore/kotlin-springboot/src/main/kotlin/org/openapitools/api/PetApiServiceImpl.kt b/samples/server/petstore/kotlin-springboot/src/main/kotlin/org/openapitools/api/PetApiServiceImpl.kt index e481c6b86b..8de49b91da 100644 --- a/samples/server/petstore/kotlin-springboot/src/main/kotlin/org/openapitools/api/PetApiServiceImpl.kt +++ b/samples/server/petstore/kotlin-springboot/src/main/kotlin/org/openapitools/api/PetApiServiceImpl.kt @@ -10,7 +10,7 @@ class PetApiServiceImpl : PetApiService { TODO("Implement me") } - override fun deletePet(petId: Long,apiKey: String?): Unit { + override fun deletePet(petId: Long,apiKey: String): Unit { TODO("Implement me") } @@ -30,7 +30,7 @@ class PetApiServiceImpl : PetApiService { TODO("Implement me") } - override fun updatePetWithForm(petId: Long,name: String?,status: String?): Unit { + override fun updatePetWithForm(petId: Long,name: String,status: String): Unit { TODO("Implement me") } diff --git a/samples/server/petstore/kotlin-springboot/src/main/kotlin/org/openapitools/api/StoreApi.kt b/samples/server/petstore/kotlin-springboot/src/main/kotlin/org/openapitools/api/StoreApi.kt index 19e94e499b..30a3ab439d 100644 --- a/samples/server/petstore/kotlin-springboot/src/main/kotlin/org/openapitools/api/StoreApi.kt +++ b/samples/server/petstore/kotlin-springboot/src/main/kotlin/org/openapitools/api/StoreApi.kt @@ -38,7 +38,8 @@ 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): ResponseEntity { + fun deleteOrder(@ApiParam(value = "ID of the order that needs to be deleted", required=true) @PathVariable("orderId") orderId: String +): ResponseEntity { return ResponseEntity(service.deleteOrder(orderId), HttpStatus.OK) } @@ -53,7 +54,7 @@ class StoreApiController(@Autowired(required = true) val service: StoreApiServic value = [ApiResponse(code = 200, message = "successful operation", response = Map::class, responseContainer = "Map")]) @RequestMapping( value = ["/store/inventory"], - produces = ["application/json"], + produces = ["application/json"], method = [RequestMethod.GET]) fun getInventory(): ResponseEntity> { return ResponseEntity(service.getInventory(), HttpStatus.OK) @@ -68,9 +69,10 @@ class StoreApiController(@Autowired(required = true) val service: StoreApiServic value = [ApiResponse(code = 200, message = "successful operation", response = Order::class),ApiResponse(code = 400, message = "Invalid ID supplied"),ApiResponse(code = 404, message = "Order not found")]) @RequestMapping( value = ["/store/order/{orderId}"], - produces = ["application/xml", "application/json"], + 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): ResponseEntity { + fun getOrderById(@Min(1L) @Max(5L) @ApiParam(value = "ID of pet that needs to be fetched", required=true) @PathVariable("orderId") orderId: Long +): ResponseEntity { return ResponseEntity(service.getOrderById(orderId), HttpStatus.OK) } @@ -83,9 +85,10 @@ class StoreApiController(@Autowired(required = true) val service: StoreApiServic value = [ApiResponse(code = 200, message = "successful operation", response = Order::class),ApiResponse(code = 400, message = "Invalid Order")]) @RequestMapping( value = ["/store/order"], - produces = ["application/xml", "application/json"], + produces = ["application/xml", "application/json"], method = [RequestMethod.POST]) - fun placeOrder(@ApiParam(value = "order placed for purchasing the pet" ,required=true ) @Valid @RequestBody body: Order): ResponseEntity { + fun placeOrder(@ApiParam(value = "order placed for purchasing the pet" ,required=true ) @Valid @RequestBody body: Order +): ResponseEntity { return ResponseEntity(service.placeOrder(body), HttpStatus.OK) } } diff --git a/samples/server/petstore/kotlin-springboot/src/main/kotlin/org/openapitools/api/UserApi.kt b/samples/server/petstore/kotlin-springboot/src/main/kotlin/org/openapitools/api/UserApi.kt index 05a6dce1ef..6eb0626a89 100644 --- a/samples/server/petstore/kotlin-springboot/src/main/kotlin/org/openapitools/api/UserApi.kt +++ b/samples/server/petstore/kotlin-springboot/src/main/kotlin/org/openapitools/api/UserApi.kt @@ -38,7 +38,8 @@ class UserApiController(@Autowired(required = true) val service: UserApiService) @RequestMapping( value = ["/user"], method = [RequestMethod.POST]) - fun createUser(@ApiParam(value = "Created user object" ,required=true ) @Valid @RequestBody body: User): ResponseEntity { + fun createUser(@ApiParam(value = "Created user object" ,required=true ) @Valid @RequestBody body: User +): ResponseEntity { return ResponseEntity(service.createUser(body), HttpStatus.OK) } @@ -51,7 +52,8 @@ class UserApiController(@Autowired(required = true) val service: UserApiService) @RequestMapping( value = ["/user/createWithArray"], method = [RequestMethod.POST]) - fun createUsersWithArrayInput(@ApiParam(value = "List of user object" ,required=true ) @Valid @RequestBody body: List): ResponseEntity { + fun createUsersWithArrayInput(@ApiParam(value = "List of user object" ,required=true ) @Valid @RequestBody body: List +): ResponseEntity { return ResponseEntity(service.createUsersWithArrayInput(body), HttpStatus.OK) } @@ -64,7 +66,8 @@ class UserApiController(@Autowired(required = true) val service: UserApiService) @RequestMapping( value = ["/user/createWithList"], method = [RequestMethod.POST]) - fun createUsersWithListInput(@ApiParam(value = "List of user object" ,required=true ) @Valid @RequestBody body: List): ResponseEntity { + fun createUsersWithListInput(@ApiParam(value = "List of user object" ,required=true ) @Valid @RequestBody body: List +): ResponseEntity { return ResponseEntity(service.createUsersWithListInput(body), HttpStatus.OK) } @@ -77,7 +80,8 @@ class UserApiController(@Autowired(required = true) val service: UserApiService) @RequestMapping( value = ["/user/{username}"], method = [RequestMethod.DELETE]) - fun deleteUser(@ApiParam(value = "The name that needs to be deleted", required=true) @PathVariable("username") username: String): ResponseEntity { + fun deleteUser(@ApiParam(value = "The name that needs to be deleted", required=true) @PathVariable("username") username: String +): ResponseEntity { return ResponseEntity(service.deleteUser(username), HttpStatus.OK) } @@ -90,9 +94,10 @@ class UserApiController(@Autowired(required = true) val service: UserApiService) value = [ApiResponse(code = 200, message = "successful operation", response = User::class),ApiResponse(code = 400, message = "Invalid username supplied"),ApiResponse(code = 404, message = "User not found")]) @RequestMapping( value = ["/user/{username}"], - produces = ["application/xml", "application/json"], + produces = ["application/xml", "application/json"], method = [RequestMethod.GET]) - fun getUserByName(@ApiParam(value = "The name that needs to be fetched. Use user1 for testing.", required=true) @PathVariable("username") username: String): ResponseEntity { + fun getUserByName(@ApiParam(value = "The name that needs to be fetched. Use user1 for testing.", required=true) @PathVariable("username") username: String +): ResponseEntity { return ResponseEntity(service.getUserByName(username), HttpStatus.OK) } @@ -105,9 +110,11 @@ class UserApiController(@Autowired(required = true) val service: UserApiService) value = [ApiResponse(code = 200, message = "successful operation", response = String::class),ApiResponse(code = 400, message = "Invalid username/password supplied")]) @RequestMapping( value = ["/user/login"], - produces = ["application/xml", "application/json"], + produces = ["application/xml", "application/json"], method = [RequestMethod.GET]) - fun loginUser(@NotNull @ApiParam(value = "The user name for login", required = true) @Valid @RequestParam(value = "username", required = true) username: String,@NotNull @ApiParam(value = "The password for login in clear text", required = true) @Valid @RequestParam(value = "password", required = true) password: String): ResponseEntity { + fun loginUser(@NotNull @ApiParam(value = "The user name for login", required = true) @Valid @RequestParam(value = "username", required = true) username: String +,@NotNull @ApiParam(value = "The password for login in clear text", required = true) @Valid @RequestParam(value = "password", required = true) password: String +): ResponseEntity { return ResponseEntity(service.loginUser(username, password), HttpStatus.OK) } @@ -133,7 +140,9 @@ class UserApiController(@Autowired(required = true) val service: UserApiService) @RequestMapping( value = ["/user/{username}"], method = [RequestMethod.PUT]) - fun updateUser(@ApiParam(value = "name that need to be deleted", required=true) @PathVariable("username") username: String,@ApiParam(value = "Updated user object" ,required=true ) @Valid @RequestBody body: User): ResponseEntity { + fun updateUser(@ApiParam(value = "name that need to be deleted", required=true) @PathVariable("username") username: String +,@ApiParam(value = "Updated user object" ,required=true ) @Valid @RequestBody body: User +): ResponseEntity { return ResponseEntity(service.updateUser(username, body), HttpStatus.OK) } }