Add mutable model option to kotlin generators (#4115)

* Add mutable model option to kotlin generators

fix #3803

* doc

* Change template name to modelMutable

* Samples
This commit is contained in:
Thibault Duperron
2019-11-27 11:04:43 +01:00
committed by William Cheng
parent 96c1bda608
commit 2dc0220874
53 changed files with 1743 additions and 49 deletions

View File

@@ -0,0 +1,14 @@
package org.openapitools
import org.springframework.boot.runApplication
import org.springframework.context.annotation.ComponentScan
import org.springframework.boot.autoconfigure.SpringBootApplication
@SpringBootApplication
@ComponentScan(basePackages = ["org.openapitools", "org.openapitools.api", "org.openapitools.model"])
class Application
fun main(args: Array<String>) {
runApplication<Application>(*args)
}

View File

@@ -0,0 +1,29 @@
package org.openapitools.api
import org.springframework.http.HttpStatus
import org.springframework.web.bind.annotation.ControllerAdvice
import org.springframework.web.bind.annotation.ExceptionHandler
import javax.servlet.http.HttpServletResponse
import javax.validation.ConstraintViolationException
// TODO Extend ApiException for custom exception handling, e.g. the below NotFound exception
sealed class ApiException(msg: String, val code: Int) : Exception(msg)
class NotFoundException(msg: String, code: Int = HttpStatus.NOT_FOUND.value()) : ApiException(msg, code)
@ControllerAdvice
class DefaultExceptionHandler {
@ExceptionHandler(value = [ApiException::class])
fun onApiException(ex: ApiException, response: HttpServletResponse): Unit =
response.sendError(ex.code, ex.message)
@ExceptionHandler(value = [NotImplementedError::class])
fun onNotImplemented(ex: NotImplementedError, response: HttpServletResponse): Unit =
response.sendError(HttpStatus.NOT_IMPLEMENTED.value())
@ExceptionHandler(value = [ConstraintViolationException::class])
fun onConstraintViolation(ex: ConstraintViolationException, response: HttpServletResponse): Unit =
response.sendError(HttpStatus.BAD_REQUEST.value(), ex.constraintViolations.joinToString(", ") { it.message })
}

View File

@@ -0,0 +1,184 @@
package org.openapitools.api
import org.openapitools.model.ModelApiResponse
import org.openapitools.model.Pet
import io.swagger.annotations.Api
import io.swagger.annotations.ApiOperation
import io.swagger.annotations.ApiParam
import io.swagger.annotations.ApiResponse
import io.swagger.annotations.ApiResponses
import io.swagger.annotations.Authorization
import io.swagger.annotations.AuthorizationScope
import org.springframework.http.HttpStatus
import org.springframework.http.MediaType
import org.springframework.http.ResponseEntity
import org.springframework.web.bind.annotation.RequestBody
import org.springframework.web.bind.annotation.RequestPart
import org.springframework.web.bind.annotation.RequestParam
import org.springframework.web.bind.annotation.PathVariable
import org.springframework.web.bind.annotation.RequestHeader
import org.springframework.web.bind.annotation.RequestMethod
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController
import org.springframework.validation.annotation.Validated
import org.springframework.web.context.request.NativeWebRequest
import org.springframework.beans.factory.annotation.Autowired
import javax.validation.Valid
import javax.validation.constraints.DecimalMax
import javax.validation.constraints.DecimalMin
import javax.validation.constraints.Max
import javax.validation.constraints.Min
import javax.validation.constraints.NotNull
import javax.validation.constraints.Pattern
import javax.validation.constraints.Size
import kotlin.collections.List
import kotlin.collections.Map
@RestController
@Validated
@Api(value = "Pet", description = "The Pet API")
@RequestMapping("\${api.base-path:/v2}")
class PetApiController(@Autowired(required = true) val service: PetApiService) {
@ApiOperation(
value = "Add a new pet to the store",
nickname = "addPet",
notes = "",
authorizations = [Authorization(value = "petstore_auth", scopes = [AuthorizationScope(scope = "write:pets", description = "modify pets in your account"), AuthorizationScope(scope = "read:pets", description = "read your pets")])])
@ApiResponses(
value = [ApiResponse(code = 405, message = "Invalid input")])
@RequestMapping(
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<Unit> {
return ResponseEntity(service.addPet(body), HttpStatus.valueOf(405))
}
@ApiOperation(
value = "Deletes a pet",
nickname = "deletePet",
notes = "",
authorizations = [Authorization(value = "petstore_auth", scopes = [AuthorizationScope(scope = "write:pets", description = "modify pets in your account"), AuthorizationScope(scope = "read:pets", description = "read your pets")])])
@ApiResponses(
value = [ApiResponse(code = 400, message = "Invalid pet value")])
@RequestMapping(
value = ["/pet/{petId}"],
method = [RequestMethod.DELETE])
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.valueOf(400))
}
@ApiOperation(
value = "Finds Pets by status",
nickname = "findPetsByStatus",
notes = "Multiple status values can be provided with comma separated strings",
response = Pet::class,
responseContainer = "List",
authorizations = [Authorization(value = "petstore_auth", scopes = [AuthorizationScope(scope = "write:pets", description = "modify pets in your account"), AuthorizationScope(scope = "read:pets", description = "read your pets")])])
@ApiResponses(
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"],
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: kotlin.collections.List<kotlin.String>
): ResponseEntity<List<Pet>> {
return ResponseEntity(service.findPetsByStatus(status), HttpStatus.valueOf(200))
}
@ApiOperation(
value = "Finds Pets by tags",
nickname = "findPetsByTags",
notes = "Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.",
response = Pet::class,
responseContainer = "List",
authorizations = [Authorization(value = "petstore_auth", scopes = [AuthorizationScope(scope = "write:pets", description = "modify pets in your account"), AuthorizationScope(scope = "read:pets", description = "read your pets")])])
@ApiResponses(
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"],
method = [RequestMethod.GET])
fun findPetsByTags(@NotNull @ApiParam(value = "Tags to filter by", required = true) @Valid @RequestParam(value = "tags", required = true) tags: kotlin.collections.List<kotlin.String>
): ResponseEntity<List<Pet>> {
return ResponseEntity(service.findPetsByTags(tags), HttpStatus.valueOf(200))
}
@ApiOperation(
value = "Find pet by ID",
nickname = "getPetById",
notes = "Returns a single pet",
response = Pet::class,
authorizations = [Authorization(value = "api_key")])
@ApiResponses(
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"],
method = [RequestMethod.GET])
fun getPetById(@ApiParam(value = "ID of pet to return", required=true) @PathVariable("petId") petId: kotlin.Long
): ResponseEntity<Pet> {
return ResponseEntity(service.getPetById(petId), HttpStatus.valueOf(200))
}
@ApiOperation(
value = "Update an existing pet",
nickname = "updatePet",
notes = "",
authorizations = [Authorization(value = "petstore_auth", scopes = [AuthorizationScope(scope = "write:pets", description = "modify pets in your account"), AuthorizationScope(scope = "read:pets", description = "read your pets")])])
@ApiResponses(
value = [ApiResponse(code = 400, message = "Invalid ID supplied"),ApiResponse(code = 404, message = "Pet not found"),ApiResponse(code = 405, message = "Validation exception")])
@RequestMapping(
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<Unit> {
return ResponseEntity(service.updatePet(body), HttpStatus.valueOf(400))
}
@ApiOperation(
value = "Updates a pet in the store with form data",
nickname = "updatePetWithForm",
notes = "",
authorizations = [Authorization(value = "petstore_auth", scopes = [AuthorizationScope(scope = "write:pets", description = "modify pets in your account"), AuthorizationScope(scope = "read:pets", description = "read your pets")])])
@ApiResponses(
value = [ApiResponse(code = 405, message = "Invalid input")])
@RequestMapping(
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: 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.valueOf(405))
}
@ApiOperation(
value = "uploads an image",
nickname = "uploadFile",
notes = "",
response = ModelApiResponse::class,
authorizations = [Authorization(value = "petstore_auth", scopes = [AuthorizationScope(scope = "write:pets", description = "modify pets in your account"), AuthorizationScope(scope = "read:pets", description = "read your pets")])])
@ApiResponses(
value = [ApiResponse(code = 200, message = "successful operation", response = ModelApiResponse::class)])
@RequestMapping(
value = ["/pet/{petId}/uploadImage"],
produces = ["application/json"],
consumes = ["multipart/form-data"],
method = [RequestMethod.POST])
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.valueOf(200))
}
}

View File

@@ -0,0 +1,22 @@
package org.openapitools.api
import org.openapitools.model.ModelApiResponse
import org.openapitools.model.Pet
interface PetApiService {
fun addPet(body: Pet): Unit
fun deletePet(petId: kotlin.Long, apiKey: kotlin.String?): Unit
fun findPetsByStatus(status: kotlin.collections.List<kotlin.String>): List<Pet>
fun findPetsByTags(tags: kotlin.collections.List<kotlin.String>): List<Pet>
fun getPetById(petId: kotlin.Long): Pet
fun updatePet(body: Pet): Unit
fun updatePetWithForm(petId: kotlin.Long, name: kotlin.String?, status: kotlin.String?): Unit
fun uploadFile(petId: kotlin.Long, additionalMetadata: kotlin.String?, file: org.springframework.core.io.Resource?): ModelApiResponse
}

View File

@@ -0,0 +1,40 @@
package org.openapitools.api
import org.openapitools.model.ModelApiResponse
import org.openapitools.model.Pet
import org.springframework.stereotype.Service
@Service
class PetApiServiceImpl : PetApiService {
override fun addPet(body: Pet): Unit {
TODO("Implement me")
}
override fun deletePet(petId: kotlin.Long, apiKey: kotlin.String?): Unit {
TODO("Implement me")
}
override fun findPetsByStatus(status: kotlin.collections.List<kotlin.String>): List<Pet> {
TODO("Implement me")
}
override fun findPetsByTags(tags: kotlin.collections.List<kotlin.String>): List<Pet> {
TODO("Implement me")
}
override fun getPetById(petId: kotlin.Long): Pet {
TODO("Implement me")
}
override fun updatePet(body: Pet): Unit {
TODO("Implement me")
}
override fun updatePetWithForm(petId: kotlin.Long, name: kotlin.String?, status: kotlin.String?): Unit {
TODO("Implement me")
}
override fun uploadFile(petId: kotlin.Long, additionalMetadata: kotlin.String?, file: org.springframework.core.io.Resource?): ModelApiResponse {
TODO("Implement me")
}
}

View File

@@ -0,0 +1,107 @@
package org.openapitools.api
import org.openapitools.model.Order
import io.swagger.annotations.Api
import io.swagger.annotations.ApiOperation
import io.swagger.annotations.ApiParam
import io.swagger.annotations.ApiResponse
import io.swagger.annotations.ApiResponses
import io.swagger.annotations.Authorization
import io.swagger.annotations.AuthorizationScope
import org.springframework.http.HttpStatus
import org.springframework.http.MediaType
import org.springframework.http.ResponseEntity
import org.springframework.web.bind.annotation.RequestBody
import org.springframework.web.bind.annotation.RequestPart
import org.springframework.web.bind.annotation.RequestParam
import org.springframework.web.bind.annotation.PathVariable
import org.springframework.web.bind.annotation.RequestHeader
import org.springframework.web.bind.annotation.RequestMethod
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController
import org.springframework.validation.annotation.Validated
import org.springframework.web.context.request.NativeWebRequest
import org.springframework.beans.factory.annotation.Autowired
import javax.validation.Valid
import javax.validation.constraints.DecimalMax
import javax.validation.constraints.DecimalMin
import javax.validation.constraints.Max
import javax.validation.constraints.Min
import javax.validation.constraints.NotNull
import javax.validation.constraints.Pattern
import javax.validation.constraints.Size
import kotlin.collections.List
import kotlin.collections.Map
@RestController
@Validated
@Api(value = "Store", description = "The Store API")
@RequestMapping("\${api.base-path:/v2}")
class StoreApiController(@Autowired(required = true) val service: StoreApiService) {
@ApiOperation(
value = "Delete purchase order by ID",
nickname = "deleteOrder",
notes = "For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors")
@ApiResponses(
value = [ApiResponse(code = 400, message = "Invalid ID supplied"),ApiResponse(code = 404, message = "Order not found")])
@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: kotlin.String
): ResponseEntity<Unit> {
return ResponseEntity(service.deleteOrder(orderId), HttpStatus.valueOf(400))
}
@ApiOperation(
value = "Returns pet inventories by status",
nickname = "getInventory",
notes = "Returns a map of status codes to quantities",
response = kotlin.Int::class,
responseContainer = "Map",
authorizations = [Authorization(value = "api_key")])
@ApiResponses(
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, kotlin.Int>> {
return ResponseEntity(service.getInventory(), HttpStatus.valueOf(200))
}
@ApiOperation(
value = "Find purchase order by ID",
nickname = "getOrderById",
notes = "For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions",
response = Order::class)
@ApiResponses(
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"],
method = [RequestMethod.GET])
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.valueOf(200))
}
@ApiOperation(
value = "Place an order for a pet",
nickname = "placeOrder",
notes = "",
response = Order::class)
@ApiResponses(
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"],
method = [RequestMethod.POST])
fun placeOrder(@ApiParam(value = "order placed for purchasing the pet" ,required=true ) @Valid @RequestBody body: Order
): ResponseEntity<Order> {
return ResponseEntity(service.placeOrder(body), HttpStatus.valueOf(200))
}
}

View File

@@ -0,0 +1,13 @@
package org.openapitools.api
import org.openapitools.model.Order
interface StoreApiService {
fun deleteOrder(orderId: kotlin.String): Unit
fun getInventory(): Map<String, kotlin.Int>
fun getOrderById(orderId: kotlin.Long): Order
fun placeOrder(body: Order): Order
}

View File

@@ -0,0 +1,23 @@
package org.openapitools.api
import org.openapitools.model.Order
import org.springframework.stereotype.Service
@Service
class StoreApiServiceImpl : StoreApiService {
override fun deleteOrder(orderId: kotlin.String): Unit {
TODO("Implement me")
}
override fun getInventory(): Map<String, kotlin.Int> {
TODO("Implement me")
}
override fun getOrderById(orderId: kotlin.Long): Order {
TODO("Implement me")
}
override fun placeOrder(body: Order): Order {
TODO("Implement me")
}
}

View File

@@ -0,0 +1,161 @@
package org.openapitools.api
import org.openapitools.model.User
import io.swagger.annotations.Api
import io.swagger.annotations.ApiOperation
import io.swagger.annotations.ApiParam
import io.swagger.annotations.ApiResponse
import io.swagger.annotations.ApiResponses
import io.swagger.annotations.Authorization
import io.swagger.annotations.AuthorizationScope
import org.springframework.http.HttpStatus
import org.springframework.http.MediaType
import org.springframework.http.ResponseEntity
import org.springframework.web.bind.annotation.RequestBody
import org.springframework.web.bind.annotation.RequestPart
import org.springframework.web.bind.annotation.RequestParam
import org.springframework.web.bind.annotation.PathVariable
import org.springframework.web.bind.annotation.RequestHeader
import org.springframework.web.bind.annotation.RequestMethod
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController
import org.springframework.validation.annotation.Validated
import org.springframework.web.context.request.NativeWebRequest
import org.springframework.beans.factory.annotation.Autowired
import javax.validation.Valid
import javax.validation.constraints.DecimalMax
import javax.validation.constraints.DecimalMin
import javax.validation.constraints.Max
import javax.validation.constraints.Min
import javax.validation.constraints.NotNull
import javax.validation.constraints.Pattern
import javax.validation.constraints.Size
import kotlin.collections.List
import kotlin.collections.Map
@RestController
@Validated
@Api(value = "User", description = "The User API")
@RequestMapping("\${api.base-path:/v2}")
class UserApiController(@Autowired(required = true) val service: UserApiService) {
@ApiOperation(
value = "Create user",
nickname = "createUser",
notes = "This can only be done by the logged in user.")
@ApiResponses(
value = [ApiResponse(code = 200, message = "successful operation")])
@RequestMapping(
value = ["/user"],
method = [RequestMethod.POST])
fun createUser(@ApiParam(value = "Created user object" ,required=true ) @Valid @RequestBody body: User
): ResponseEntity<Unit> {
return ResponseEntity(service.createUser(body), HttpStatus.valueOf(200))
}
@ApiOperation(
value = "Creates list of users with given input array",
nickname = "createUsersWithArrayInput",
notes = "")
@ApiResponses(
value = [ApiResponse(code = 200, message = "successful operation")])
@RequestMapping(
value = ["/user/createWithArray"],
method = [RequestMethod.POST])
fun createUsersWithArrayInput(@ApiParam(value = "List of user object" ,required=true ) @Valid @RequestBody body: kotlin.collections.List<User>
): ResponseEntity<Unit> {
return ResponseEntity(service.createUsersWithArrayInput(body), HttpStatus.valueOf(200))
}
@ApiOperation(
value = "Creates list of users with given input array",
nickname = "createUsersWithListInput",
notes = "")
@ApiResponses(
value = [ApiResponse(code = 200, message = "successful operation")])
@RequestMapping(
value = ["/user/createWithList"],
method = [RequestMethod.POST])
fun createUsersWithListInput(@ApiParam(value = "List of user object" ,required=true ) @Valid @RequestBody body: kotlin.collections.List<User>
): ResponseEntity<Unit> {
return ResponseEntity(service.createUsersWithListInput(body), HttpStatus.valueOf(200))
}
@ApiOperation(
value = "Delete user",
nickname = "deleteUser",
notes = "This can only be done by the logged in user.")
@ApiResponses(
value = [ApiResponse(code = 400, message = "Invalid username supplied"),ApiResponse(code = 404, message = "User not found")])
@RequestMapping(
value = ["/user/{username}"],
method = [RequestMethod.DELETE])
fun deleteUser(@ApiParam(value = "The name that needs to be deleted", required=true) @PathVariable("username") username: kotlin.String
): ResponseEntity<Unit> {
return ResponseEntity(service.deleteUser(username), HttpStatus.valueOf(400))
}
@ApiOperation(
value = "Get user by user name",
nickname = "getUserByName",
notes = "",
response = User::class)
@ApiResponses(
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"],
method = [RequestMethod.GET])
fun getUserByName(@ApiParam(value = "The name that needs to be fetched. Use user1 for testing.", required=true) @PathVariable("username") username: kotlin.String
): ResponseEntity<User> {
return ResponseEntity(service.getUserByName(username), HttpStatus.valueOf(200))
}
@ApiOperation(
value = "Logs user into the system",
nickname = "loginUser",
notes = "",
response = kotlin.String::class)
@ApiResponses(
value = [ApiResponse(code = 200, message = "successful operation", response = kotlin.String::class),ApiResponse(code = 400, message = "Invalid username/password supplied")])
@RequestMapping(
value = ["/user/login"],
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: kotlin.String
,@NotNull @ApiParam(value = "The password for login in clear text", required = true) @Valid @RequestParam(value = "password", required = true) password: kotlin.String
): ResponseEntity<kotlin.String> {
return ResponseEntity(service.loginUser(username, password), HttpStatus.valueOf(200))
}
@ApiOperation(
value = "Logs out current logged in user session",
nickname = "logoutUser",
notes = "")
@ApiResponses(
value = [ApiResponse(code = 200, message = "successful operation")])
@RequestMapping(
value = ["/user/logout"],
method = [RequestMethod.GET])
fun logoutUser(): ResponseEntity<Unit> {
return ResponseEntity(service.logoutUser(), HttpStatus.valueOf(200))
}
@ApiOperation(
value = "Updated user",
nickname = "updateUser",
notes = "This can only be done by the logged in user.")
@ApiResponses(
value = [ApiResponse(code = 400, message = "Invalid user supplied"),ApiResponse(code = 404, message = "User not found")])
@RequestMapping(
value = ["/user/{username}"],
method = [RequestMethod.PUT])
fun updateUser(@ApiParam(value = "name that need to be deleted", required=true) @PathVariable("username") username: kotlin.String
,@ApiParam(value = "Updated user object" ,required=true ) @Valid @RequestBody body: User
): ResponseEntity<Unit> {
return ResponseEntity(service.updateUser(username, body), HttpStatus.valueOf(400))
}
}

View File

@@ -0,0 +1,21 @@
package org.openapitools.api
import org.openapitools.model.User
interface UserApiService {
fun createUser(body: User): Unit
fun createUsersWithArrayInput(body: kotlin.collections.List<User>): Unit
fun createUsersWithListInput(body: kotlin.collections.List<User>): Unit
fun deleteUser(username: kotlin.String): Unit
fun getUserByName(username: kotlin.String): User
fun loginUser(username: kotlin.String, password: kotlin.String): kotlin.String
fun logoutUser(): Unit
fun updateUser(username: kotlin.String, body: User): Unit
}

View File

@@ -0,0 +1,39 @@
package org.openapitools.api
import org.openapitools.model.User
import org.springframework.stereotype.Service
@Service
class UserApiServiceImpl : UserApiService {
override fun createUser(body: User): Unit {
TODO("Implement me")
}
override fun createUsersWithArrayInput(body: kotlin.collections.List<User>): Unit {
TODO("Implement me")
}
override fun createUsersWithListInput(body: kotlin.collections.List<User>): Unit {
TODO("Implement me")
}
override fun deleteUser(username: kotlin.String): Unit {
TODO("Implement me")
}
override fun getUserByName(username: kotlin.String): User {
TODO("Implement me")
}
override fun loginUser(username: kotlin.String, password: kotlin.String): kotlin.String {
TODO("Implement me")
}
override fun logoutUser(): Unit {
TODO("Implement me")
}
override fun updateUser(username: kotlin.String, body: User): Unit {
TODO("Implement me")
}
}

View File

@@ -0,0 +1,29 @@
package org.openapitools.model
import java.util.Objects
import com.fasterxml.jackson.annotation.JsonProperty
import javax.validation.constraints.DecimalMax
import javax.validation.constraints.DecimalMin
import javax.validation.constraints.Max
import javax.validation.constraints.Min
import javax.validation.constraints.NotNull
import javax.validation.constraints.Pattern
import javax.validation.constraints.Size
import io.swagger.annotations.ApiModelProperty
/**
* A category for a pet
* @param id
* @param name
*/
data class Category (
@ApiModelProperty(example = "null", value = "")
@JsonProperty("id") var id: kotlin.Long? = null,
@ApiModelProperty(example = "null", value = "")
@JsonProperty("name") var name: kotlin.String? = null
) {
}

View File

@@ -0,0 +1,33 @@
package org.openapitools.model
import java.util.Objects
import com.fasterxml.jackson.annotation.JsonProperty
import javax.validation.constraints.DecimalMax
import javax.validation.constraints.DecimalMin
import javax.validation.constraints.Max
import javax.validation.constraints.Min
import javax.validation.constraints.NotNull
import javax.validation.constraints.Pattern
import javax.validation.constraints.Size
import io.swagger.annotations.ApiModelProperty
/**
* Describes the result of uploading an image resource
* @param code
* @param type
* @param message
*/
data class ModelApiResponse (
@ApiModelProperty(example = "null", value = "")
@JsonProperty("code") var code: kotlin.Int? = null,
@ApiModelProperty(example = "null", value = "")
@JsonProperty("type") var type: kotlin.String? = null,
@ApiModelProperty(example = "null", value = "")
@JsonProperty("message") var message: kotlin.String? = null
) {
}

View File

@@ -0,0 +1,60 @@
package org.openapitools.model
import java.util.Objects
import com.fasterxml.jackson.annotation.JsonProperty
import com.fasterxml.jackson.annotation.JsonValue
import javax.validation.constraints.DecimalMax
import javax.validation.constraints.DecimalMin
import javax.validation.constraints.Max
import javax.validation.constraints.Min
import javax.validation.constraints.NotNull
import javax.validation.constraints.Pattern
import javax.validation.constraints.Size
import io.swagger.annotations.ApiModelProperty
/**
* An order for a pets from the pet store
* @param id
* @param petId
* @param quantity
* @param shipDate
* @param status Order Status
* @param complete
*/
data class Order (
@ApiModelProperty(example = "null", value = "")
@JsonProperty("id") var id: kotlin.Long? = null,
@ApiModelProperty(example = "null", value = "")
@JsonProperty("petId") var petId: kotlin.Long? = null,
@ApiModelProperty(example = "null", value = "")
@JsonProperty("quantity") var quantity: kotlin.Int? = null,
@ApiModelProperty(example = "null", value = "")
@JsonProperty("shipDate") var shipDate: java.time.OffsetDateTime? = null,
@ApiModelProperty(example = "null", value = "Order Status")
@JsonProperty("status") var status: Order.Status? = null,
@ApiModelProperty(example = "null", value = "")
@JsonProperty("complete") var complete: kotlin.Boolean? = null
) {
/**
* Order Status
* Values: placed,approved,delivered
*/
enum class Status(val value: kotlin.String) {
@JsonProperty("placed") placed("placed"),
@JsonProperty("approved") approved("approved"),
@JsonProperty("delivered") delivered("delivered");
}
}

View File

@@ -0,0 +1,64 @@
package org.openapitools.model
import java.util.Objects
import com.fasterxml.jackson.annotation.JsonProperty
import com.fasterxml.jackson.annotation.JsonValue
import org.openapitools.model.Category
import org.openapitools.model.Tag
import javax.validation.constraints.DecimalMax
import javax.validation.constraints.DecimalMin
import javax.validation.constraints.Max
import javax.validation.constraints.Min
import javax.validation.constraints.NotNull
import javax.validation.constraints.Pattern
import javax.validation.constraints.Size
import io.swagger.annotations.ApiModelProperty
/**
* A pet for sale in the pet store
* @param id
* @param category
* @param name
* @param photoUrls
* @param tags
* @param status pet status in the store
*/
data class Pet (
@get:NotNull
@ApiModelProperty(example = "doggie", required = true, value = "")
@JsonProperty("name") var name: kotlin.String,
@get:NotNull
@ApiModelProperty(example = "null", required = true, value = "")
@JsonProperty("photoUrls") var photoUrls: kotlin.collections.List<kotlin.String>,
@ApiModelProperty(example = "null", value = "")
@JsonProperty("id") var id: kotlin.Long? = null,
@ApiModelProperty(example = "null", value = "")
@JsonProperty("category") var category: Category? = null,
@ApiModelProperty(example = "null", value = "")
@JsonProperty("tags") var tags: kotlin.collections.List<Tag>? = null,
@ApiModelProperty(example = "null", value = "pet status in the store")
@JsonProperty("status") var status: Pet.Status? = null
) {
/**
* pet status in the store
* Values: available,pending,sold
*/
enum class Status(val value: kotlin.String) {
@JsonProperty("available") available("available"),
@JsonProperty("pending") pending("pending"),
@JsonProperty("sold") sold("sold");
}
}

View File

@@ -0,0 +1,29 @@
package org.openapitools.model
import java.util.Objects
import com.fasterxml.jackson.annotation.JsonProperty
import javax.validation.constraints.DecimalMax
import javax.validation.constraints.DecimalMin
import javax.validation.constraints.Max
import javax.validation.constraints.Min
import javax.validation.constraints.NotNull
import javax.validation.constraints.Pattern
import javax.validation.constraints.Size
import io.swagger.annotations.ApiModelProperty
/**
* A tag for a pet
* @param id
* @param name
*/
data class Tag (
@ApiModelProperty(example = "null", value = "")
@JsonProperty("id") var id: kotlin.Long? = null,
@ApiModelProperty(example = "null", value = "")
@JsonProperty("name") var name: kotlin.String? = null
) {
}

View File

@@ -0,0 +1,53 @@
package org.openapitools.model
import java.util.Objects
import com.fasterxml.jackson.annotation.JsonProperty
import javax.validation.constraints.DecimalMax
import javax.validation.constraints.DecimalMin
import javax.validation.constraints.Max
import javax.validation.constraints.Min
import javax.validation.constraints.NotNull
import javax.validation.constraints.Pattern
import javax.validation.constraints.Size
import io.swagger.annotations.ApiModelProperty
/**
* A User who is purchasing from the pet store
* @param id
* @param username
* @param firstName
* @param lastName
* @param email
* @param password
* @param phone
* @param userStatus User Status
*/
data class User (
@ApiModelProperty(example = "null", value = "")
@JsonProperty("id") var id: kotlin.Long? = null,
@ApiModelProperty(example = "null", value = "")
@JsonProperty("username") var username: kotlin.String? = null,
@ApiModelProperty(example = "null", value = "")
@JsonProperty("firstName") var firstName: kotlin.String? = null,
@ApiModelProperty(example = "null", value = "")
@JsonProperty("lastName") var lastName: kotlin.String? = null,
@ApiModelProperty(example = "null", value = "")
@JsonProperty("email") var email: kotlin.String? = null,
@ApiModelProperty(example = "null", value = "")
@JsonProperty("password") var password: kotlin.String? = null,
@ApiModelProperty(example = "null", value = "")
@JsonProperty("phone") var phone: kotlin.String? = null,
@ApiModelProperty(example = "null", value = "User Status")
@JsonProperty("userStatus") var userStatus: kotlin.Int? = null
) {
}

View File

@@ -0,0 +1,10 @@
spring:
application:
name: openAPIPetstore
jackson:
serialization:
WRITE_DATES_AS_TIMESTAMPS: false
server:
port: 8080

View File

@@ -0,0 +1,148 @@
package org.openapitools.api
import org.openapitools.model.ModelApiResponse
import org.openapitools.model.Pet
import org.junit.jupiter.api.Test
import org.springframework.http.ResponseEntity
class PetApiTest {
private val service: PetApiService = PetApiServiceImpl()
private val api: PetApiController = PetApiController(service)
/**
* Add a new pet to the store
*
*
*
* @throws ApiException
* if the Api call fails
*/
@Test
fun addPetTest() {
val body:Pet? = null
val response: ResponseEntity<Unit> = api.addPet(body!!)
// TODO: test validations
}
/**
* Deletes a pet
*
*
*
* @throws ApiException
* if the Api call fails
*/
@Test
fun deletePetTest() {
val petId:kotlin.Long? = null
val apiKey:kotlin.String? = null
val response: ResponseEntity<Unit> = api.deletePet(petId!!, apiKey!!)
// TODO: test validations
}
/**
* Finds Pets by status
*
* Multiple status values can be provided with comma separated strings
*
* @throws ApiException
* if the Api call fails
*/
@Test
fun findPetsByStatusTest() {
val status:kotlin.collections.List<kotlin.String>? = null
val response: ResponseEntity<List<Pet>> = api.findPetsByStatus(status!!)
// TODO: test validations
}
/**
* Finds Pets by tags
*
* Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
*
* @throws ApiException
* if the Api call fails
*/
@Test
fun findPetsByTagsTest() {
val tags:kotlin.collections.List<kotlin.String>? = null
val response: ResponseEntity<List<Pet>> = api.findPetsByTags(tags!!)
// TODO: test validations
}
/**
* Find pet by ID
*
* Returns a single pet
*
* @throws ApiException
* if the Api call fails
*/
@Test
fun getPetByIdTest() {
val petId:kotlin.Long? = null
val response: ResponseEntity<Pet> = api.getPetById(petId!!)
// TODO: test validations
}
/**
* Update an existing pet
*
*
*
* @throws ApiException
* if the Api call fails
*/
@Test
fun updatePetTest() {
val body:Pet? = null
val response: ResponseEntity<Unit> = api.updatePet(body!!)
// TODO: test validations
}
/**
* Updates a pet in the store with form data
*
*
*
* @throws ApiException
* if the Api call fails
*/
@Test
fun updatePetWithFormTest() {
val petId:kotlin.Long? = null
val name:kotlin.String? = null
val status:kotlin.String? = null
val response: ResponseEntity<Unit> = api.updatePetWithForm(petId!!, name!!, status!!)
// TODO: test validations
}
/**
* uploads an image
*
*
*
* @throws ApiException
* if the Api call fails
*/
@Test
fun uploadFileTest() {
val petId:kotlin.Long? = null
val additionalMetadata:kotlin.String? = null
val file:org.springframework.core.io.Resource? = null
val response: ResponseEntity<ModelApiResponse> = api.uploadFile(petId!!, additionalMetadata!!, file!!)
// TODO: test validations
}
}

View File

@@ -0,0 +1,77 @@
package org.openapitools.api
import org.openapitools.model.Order
import org.junit.jupiter.api.Test
import org.springframework.http.ResponseEntity
class StoreApiTest {
private val service: StoreApiService = StoreApiServiceImpl()
private val api: StoreApiController = StoreApiController(service)
/**
* Delete purchase order by ID
*
* For valid response try integer IDs with value &lt; 1000. Anything above 1000 or nonintegers will generate API errors
*
* @throws ApiException
* if the Api call fails
*/
@Test
fun deleteOrderTest() {
val orderId:kotlin.String? = null
val response: ResponseEntity<Unit> = api.deleteOrder(orderId!!)
// TODO: test validations
}
/**
* Returns pet inventories by status
*
* Returns a map of status codes to quantities
*
* @throws ApiException
* if the Api call fails
*/
@Test
fun getInventoryTest() {
val response: ResponseEntity<Map<String, kotlin.Int>> = api.getInventory()
// TODO: test validations
}
/**
* Find purchase order by ID
*
* For valid response try integer IDs with value &lt;&#x3D; 5 or &gt; 10. Other values will generated exceptions
*
* @throws ApiException
* if the Api call fails
*/
@Test
fun getOrderByIdTest() {
val orderId:kotlin.Long? = null
val response: ResponseEntity<Order> = api.getOrderById(orderId!!)
// TODO: test validations
}
/**
* Place an order for a pet
*
*
*
* @throws ApiException
* if the Api call fails
*/
@Test
fun placeOrderTest() {
val body:Order? = null
val response: ResponseEntity<Order> = api.placeOrder(body!!)
// TODO: test validations
}
}

View File

@@ -0,0 +1,143 @@
package org.openapitools.api
import org.openapitools.model.User
import org.junit.jupiter.api.Test
import org.springframework.http.ResponseEntity
class UserApiTest {
private val service: UserApiService = UserApiServiceImpl()
private val api: UserApiController = UserApiController(service)
/**
* Create user
*
* This can only be done by the logged in user.
*
* @throws ApiException
* if the Api call fails
*/
@Test
fun createUserTest() {
val body:User? = null
val response: ResponseEntity<Unit> = api.createUser(body!!)
// TODO: test validations
}
/**
* Creates list of users with given input array
*
*
*
* @throws ApiException
* if the Api call fails
*/
@Test
fun createUsersWithArrayInputTest() {
val body:kotlin.collections.List<User>? = null
val response: ResponseEntity<Unit> = api.createUsersWithArrayInput(body!!)
// TODO: test validations
}
/**
* Creates list of users with given input array
*
*
*
* @throws ApiException
* if the Api call fails
*/
@Test
fun createUsersWithListInputTest() {
val body:kotlin.collections.List<User>? = null
val response: ResponseEntity<Unit> = api.createUsersWithListInput(body!!)
// TODO: test validations
}
/**
* Delete user
*
* This can only be done by the logged in user.
*
* @throws ApiException
* if the Api call fails
*/
@Test
fun deleteUserTest() {
val username:kotlin.String? = null
val response: ResponseEntity<Unit> = api.deleteUser(username!!)
// TODO: test validations
}
/**
* Get user by user name
*
*
*
* @throws ApiException
* if the Api call fails
*/
@Test
fun getUserByNameTest() {
val username:kotlin.String? = null
val response: ResponseEntity<User> = api.getUserByName(username!!)
// TODO: test validations
}
/**
* Logs user into the system
*
*
*
* @throws ApiException
* if the Api call fails
*/
@Test
fun loginUserTest() {
val username:kotlin.String? = null
val password:kotlin.String? = null
val response: ResponseEntity<kotlin.String> = api.loginUser(username!!, password!!)
// TODO: test validations
}
/**
* Logs out current logged in user session
*
*
*
* @throws ApiException
* if the Api call fails
*/
@Test
fun logoutUserTest() {
val response: ResponseEntity<Unit> = api.logoutUser()
// TODO: test validations
}
/**
* Updated user
*
* This can only be done by the logged in user.
*
* @throws ApiException
* if the Api call fails
*/
@Test
fun updateUserTest() {
val username:kotlin.String? = null
val body:User? = null
val response: ResponseEntity<Unit> = api.updateUser(username!!, body!!)
// TODO: test validations
}
}