mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-12-06 12:06:10 +00:00
[KOTLIN] Spring Boot Server Generator (#820)
* Kotlin Spring initial bootstrap * Basic configuration construction for Kotlin Spring * Wired up with comand line client * Initial kotlin spring boot application generated using gradle kotlin-dsl * Added basic support for generating models * Basic controllers generated without endpoints generated * Basic spring boot app generated with models and controllers * Added fix for type mapping in AbstractKotlinCodegen. Originally it was mapping list o kotlin.Array instead of kotlin.collections.List * Fixed return type mapping * Sorted bash springboot petstore generator script * Implemented toVarName in AbstractKotlinCodegen to better handle some edgecases * Checking for reserved words or numerical starting class names in AbstractKotlinCodegen * Implemented toOperationId in AbstractKotlinCodegen * Fixed types that were not correctly being mapped to primitives (byte / arrayOf / mapOf) * Escaping dollar symbols in function names * Added support for outter enum classes * Added basic support for generating services * Removed option for generated config package. Added option to enable/disable generated global exception handler * Added configuration option to generate gradle. Generated maven pom.xml file as default * Fixed up bash scripts for generating test sample code * Added configurable option for Swagger Annotations * Added configurable option for generating service interfaces and service implementations * Added README generation * Enable optional bean validation * Added kotlin spring sample to CircleCI pom.xml * Removed kotlin spring boot from .gitignore * Minor fixes from PR comments for user submission (#1) * Minor fixes from PR comments for user submission * Puts braces around conditional block bodies with one-liner bodies. * Modifies README.mustache to use artifact id and version supplied by user (or default configuration) * Targets templates under resource directory explicitly to prevent the need to rebuild for evaluation of template-only changes. * [kotlin-spring] Remove comments referencing sbt in bash scripts * List of changes based upon code review: * Additional comments around how we set the title based off the open api spec * Fixed missing `beanValidationCore` template * Put the lambdas into the lambda object as other generators do (Ktor, C#, cpp) * Bump swagger-annotations version to latest pre-2.0 version (1.5.21) * Set kotlin version to 1.2.60 * Updated README to set port based on template * Added more additional properties to build bash scripts * Removed `defaultBasePath.mustache` in place of using {{contextPath}} directly * Log warning for when `serviceImplementation` is set t o true * Updated samples * Generating ConstraintViolation Exception Handler, as Springboot doesnt correctly catch the error and return bad request. Handling other exceptions a litle better * Small fix for date time mappings (plus sample re-gen) * Minor fix in README template, where port was using wrong variable * Fix missing jackson-dataformat-xml dependency * Fix build - needed to re-run kotlin-server-petstore.sh * Fixes after merge with master * Revert "Small fix for date time mappings (plus sample re-gen)" This reverts commit 4152dc78b4813da71c675272ca90fb31a333aea1. * Moved type mappings to Kotlin Spring generator * Regenerated samples * Regenerated samples
This commit is contained in:
committed by
William Cheng
parent
5cd5143b80
commit
8689227b3e
@@ -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)
|
||||
}
|
||||
@@ -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 })
|
||||
}
|
||||
@@ -0,0 +1,159 @@
|
||||
package org.openapitools.api
|
||||
|
||||
import org.openapitools.model.ModelApiResponse
|
||||
import org.openapitools.model.Pet
|
||||
import io.swagger.annotations.*
|
||||
import org.springframework.http.HttpStatus
|
||||
import org.springframework.http.MediaType
|
||||
import org.springframework.http.ResponseEntity
|
||||
import org.springframework.stereotype.Controller
|
||||
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.validation.annotation.Validated
|
||||
import org.springframework.web.context.request.NativeWebRequest
|
||||
import org.springframework.web.multipart.MultipartFile
|
||||
import org.springframework.beans.factory.annotation.Autowired
|
||||
|
||||
import javax.validation.Valid
|
||||
import javax.validation.constraints.*
|
||||
|
||||
import kotlin.collections.List
|
||||
import kotlin.collections.Map
|
||||
|
||||
@Controller
|
||||
@Validated
|
||||
@Api(value = "Pet", description = "The Pet API")
|
||||
@RequestMapping("\${openapi.openAPIPetstore.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 pet: Pet): ResponseEntity<Unit> {
|
||||
return ResponseEntity(service.addPet(pet), HttpStatus.OK)
|
||||
}
|
||||
|
||||
@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.OK)
|
||||
}
|
||||
|
||||
@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.Array<kotlin.String>): ResponseEntity<List<Pet>> {
|
||||
return ResponseEntity(service.findPetsByStatus(status), HttpStatus.OK)
|
||||
}
|
||||
|
||||
@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.Array<kotlin.String>): ResponseEntity<List<Pet>> {
|
||||
return ResponseEntity(service.findPetsByTags(tags), HttpStatus.OK)
|
||||
}
|
||||
|
||||
@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.OK)
|
||||
}
|
||||
|
||||
@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 pet: Pet): ResponseEntity<Unit> {
|
||||
return ResponseEntity(service.updatePet(pet), HttpStatus.OK)
|
||||
}
|
||||
|
||||
@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", defaultValue="null") @RequestParam(value="name", required=false) name: kotlin.String ,@ApiParam(value = "Updated status of the pet", defaultValue="null") @RequestParam(value="status", required=false) status: kotlin.String ): ResponseEntity<Unit> {
|
||||
return ResponseEntity(service.updatePetWithForm(petId, name, status), HttpStatus.OK)
|
||||
}
|
||||
|
||||
@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", defaultValue="null") @RequestParam(value="additionalMetadata", required=false) additionalMetadata: kotlin.String ,@ApiParam(value = "file detail") @Valid @RequestPart("file") file: MultipartFile): ResponseEntity<ModelApiResponse> {
|
||||
return ResponseEntity(service.uploadFile(petId, additionalMetadata, file), HttpStatus.OK)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package org.openapitools.api
|
||||
|
||||
import org.openapitools.model.ModelApiResponse
|
||||
import org.openapitools.model.Pet
|
||||
|
||||
interface PetApiService {
|
||||
|
||||
fun addPet(pet: Pet): Unit
|
||||
|
||||
fun deletePet(petId: kotlin.Long,apiKey: kotlin.String): Unit
|
||||
|
||||
fun findPetsByStatus(status: kotlin.Array<kotlin.String>): List<Pet>
|
||||
|
||||
fun findPetsByTags(tags: kotlin.Array<kotlin.String>): List<Pet>
|
||||
|
||||
fun getPetById(petId: kotlin.Long): Pet
|
||||
|
||||
fun updatePet(pet: 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.web.multipart.MultipartFile): ModelApiResponse
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
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(pet: Pet): Unit {
|
||||
TODO("Implement me")
|
||||
}
|
||||
|
||||
override fun deletePet(petId: kotlin.Long,apiKey: kotlin.String): Unit {
|
||||
TODO("Implement me")
|
||||
}
|
||||
|
||||
override fun findPetsByStatus(status: kotlin.Array<kotlin.String>): List<Pet> {
|
||||
TODO("Implement me")
|
||||
}
|
||||
|
||||
override fun findPetsByTags(tags: kotlin.Array<kotlin.String>): List<Pet> {
|
||||
TODO("Implement me")
|
||||
}
|
||||
|
||||
override fun getPetById(petId: kotlin.Long): Pet {
|
||||
TODO("Implement me")
|
||||
}
|
||||
|
||||
override fun updatePet(pet: 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.web.multipart.MultipartFile): ModelApiResponse {
|
||||
TODO("Implement me")
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
package org.openapitools.api
|
||||
|
||||
import org.openapitools.model.Order
|
||||
import io.swagger.annotations.*
|
||||
import org.springframework.http.HttpStatus
|
||||
import org.springframework.http.MediaType
|
||||
import org.springframework.http.ResponseEntity
|
||||
import org.springframework.stereotype.Controller
|
||||
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.validation.annotation.Validated
|
||||
import org.springframework.web.context.request.NativeWebRequest
|
||||
import org.springframework.web.multipart.MultipartFile
|
||||
import org.springframework.beans.factory.annotation.Autowired
|
||||
|
||||
import javax.validation.Valid
|
||||
import javax.validation.constraints.*
|
||||
|
||||
import kotlin.collections.List
|
||||
import kotlin.collections.Map
|
||||
|
||||
@Controller
|
||||
@Validated
|
||||
@Api(value = "Store", description = "The Store API")
|
||||
@RequestMapping("\${openapi.openAPIPetstore.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.OK)
|
||||
}
|
||||
|
||||
@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.OK)
|
||||
}
|
||||
|
||||
@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.OK)
|
||||
}
|
||||
|
||||
@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 order: Order): ResponseEntity<Order> {
|
||||
return ResponseEntity(service.placeOrder(order), HttpStatus.OK)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
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(order: Order): Order
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
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(order: Order): Order {
|
||||
TODO("Implement me")
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,140 @@
|
||||
package org.openapitools.api
|
||||
|
||||
import org.openapitools.model.User
|
||||
import io.swagger.annotations.*
|
||||
import org.springframework.http.HttpStatus
|
||||
import org.springframework.http.MediaType
|
||||
import org.springframework.http.ResponseEntity
|
||||
import org.springframework.stereotype.Controller
|
||||
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.validation.annotation.Validated
|
||||
import org.springframework.web.context.request.NativeWebRequest
|
||||
import org.springframework.web.multipart.MultipartFile
|
||||
import org.springframework.beans.factory.annotation.Autowired
|
||||
|
||||
import javax.validation.Valid
|
||||
import javax.validation.constraints.*
|
||||
|
||||
import kotlin.collections.List
|
||||
import kotlin.collections.Map
|
||||
|
||||
@Controller
|
||||
@Validated
|
||||
@Api(value = "User", description = "The User API")
|
||||
@RequestMapping("\${openapi.openAPIPetstore.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 user: User): ResponseEntity<Unit> {
|
||||
return ResponseEntity(service.createUser(user), HttpStatus.OK)
|
||||
}
|
||||
|
||||
@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 user: kotlin.Array<User>): ResponseEntity<Unit> {
|
||||
return ResponseEntity(service.createUsersWithArrayInput(user), HttpStatus.OK)
|
||||
}
|
||||
|
||||
@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 user: kotlin.Array<User>): ResponseEntity<Unit> {
|
||||
return ResponseEntity(service.createUsersWithListInput(user), HttpStatus.OK)
|
||||
}
|
||||
|
||||
@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.OK)
|
||||
}
|
||||
|
||||
@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.OK)
|
||||
}
|
||||
|
||||
@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.OK)
|
||||
}
|
||||
|
||||
@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.OK)
|
||||
}
|
||||
|
||||
@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 user: User): ResponseEntity<Unit> {
|
||||
return ResponseEntity(service.updateUser(username, user), HttpStatus.OK)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package org.openapitools.api
|
||||
|
||||
import org.openapitools.model.User
|
||||
|
||||
interface UserApiService {
|
||||
|
||||
fun createUser(user: User): Unit
|
||||
|
||||
fun createUsersWithArrayInput(user: kotlin.Array<User>): Unit
|
||||
|
||||
fun createUsersWithListInput(user: kotlin.Array<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,user: User): Unit
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package org.openapitools.api
|
||||
|
||||
import org.openapitools.model.User
|
||||
import org.springframework.stereotype.Service
|
||||
|
||||
@Service
|
||||
class UserApiServiceImpl : UserApiService {
|
||||
|
||||
override fun createUser(user: User): Unit {
|
||||
TODO("Implement me")
|
||||
}
|
||||
|
||||
override fun createUsersWithArrayInput(user: kotlin.Array<User>): Unit {
|
||||
TODO("Implement me")
|
||||
}
|
||||
|
||||
override fun createUsersWithListInput(user: kotlin.Array<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,user: User): Unit {
|
||||
TODO("Implement me")
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package org.openapitools.model
|
||||
|
||||
import java.util.Objects
|
||||
import com.fasterxml.jackson.annotation.JsonProperty
|
||||
import javax.validation.Valid
|
||||
import javax.validation.constraints.*
|
||||
import io.swagger.annotations.ApiModelProperty
|
||||
|
||||
/**
|
||||
* A category for a pet
|
||||
* @param id
|
||||
* @param name
|
||||
*/
|
||||
data class Category (
|
||||
|
||||
@ApiModelProperty(value = "")
|
||||
@JsonProperty("id") val id: kotlin.Long? = null,
|
||||
|
||||
@ApiModelProperty(value = "")
|
||||
@JsonProperty("name") val name: kotlin.String? = null
|
||||
) {
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
package org.openapitools.model
|
||||
|
||||
import java.util.Objects
|
||||
import com.fasterxml.jackson.annotation.JsonProperty
|
||||
import javax.validation.Valid
|
||||
import javax.validation.constraints.*
|
||||
import io.swagger.annotations.ApiModelProperty
|
||||
|
||||
/**
|
||||
* Describes the result of uploading an image resource
|
||||
* @param code
|
||||
* @param type
|
||||
* @param message
|
||||
*/
|
||||
data class ModelApiResponse (
|
||||
|
||||
@ApiModelProperty(value = "")
|
||||
@JsonProperty("code") val code: kotlin.Int? = null,
|
||||
|
||||
@ApiModelProperty(value = "")
|
||||
@JsonProperty("type") val type: kotlin.String? = null,
|
||||
|
||||
@ApiModelProperty(value = "")
|
||||
@JsonProperty("message") val message: kotlin.String? = null
|
||||
) {
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
package org.openapitools.model
|
||||
|
||||
import java.util.Objects
|
||||
import com.fasterxml.jackson.annotation.JsonProperty
|
||||
import com.fasterxml.jackson.annotation.JsonValue
|
||||
import javax.validation.Valid
|
||||
import javax.validation.constraints.*
|
||||
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(value = "")
|
||||
@JsonProperty("id") val id: kotlin.Long? = null,
|
||||
|
||||
@ApiModelProperty(value = "")
|
||||
@JsonProperty("petId") val petId: kotlin.Long? = null,
|
||||
|
||||
@ApiModelProperty(value = "")
|
||||
@JsonProperty("quantity") val quantity: kotlin.Int? = null,
|
||||
|
||||
@ApiModelProperty(value = "")
|
||||
@JsonProperty("shipDate") val shipDate: java.time.OffsetDateTime? = null,
|
||||
|
||||
@ApiModelProperty(value = "Order Status")
|
||||
@JsonProperty("status") val status: Order.Status? = null,
|
||||
|
||||
@ApiModelProperty(value = "")
|
||||
@JsonProperty("complete") val 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");
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
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.Valid
|
||||
import javax.validation.constraints.*
|
||||
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") val name: kotlin.String,
|
||||
|
||||
@get:NotNull
|
||||
@ApiModelProperty(required = true, value = "")
|
||||
@JsonProperty("photoUrls") val photoUrls: kotlin.Array<kotlin.String>,
|
||||
|
||||
@ApiModelProperty(value = "")
|
||||
@JsonProperty("id") val id: kotlin.Long? = null,
|
||||
|
||||
@ApiModelProperty(value = "")
|
||||
@JsonProperty("category") val category: Category? = null,
|
||||
|
||||
@ApiModelProperty(value = "")
|
||||
@JsonProperty("tags") val tags: kotlin.Array<Tag>? = null,
|
||||
|
||||
@ApiModelProperty(value = "pet status in the store")
|
||||
@JsonProperty("status") val 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");
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
package org.openapitools.model
|
||||
|
||||
import java.util.Objects
|
||||
import com.fasterxml.jackson.annotation.JsonProperty
|
||||
import javax.validation.Valid
|
||||
import javax.validation.constraints.*
|
||||
import io.swagger.annotations.ApiModelProperty
|
||||
|
||||
/**
|
||||
* A tag for a pet
|
||||
* @param id
|
||||
* @param name
|
||||
*/
|
||||
data class Tag (
|
||||
|
||||
@ApiModelProperty(value = "")
|
||||
@JsonProperty("id") val id: kotlin.Long? = null,
|
||||
|
||||
@ApiModelProperty(value = "")
|
||||
@JsonProperty("name") val name: kotlin.String? = null
|
||||
) {
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
package org.openapitools.model
|
||||
|
||||
import java.util.Objects
|
||||
import com.fasterxml.jackson.annotation.JsonProperty
|
||||
import javax.validation.Valid
|
||||
import javax.validation.constraints.*
|
||||
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(value = "")
|
||||
@JsonProperty("id") val id: kotlin.Long? = null,
|
||||
|
||||
@ApiModelProperty(value = "")
|
||||
@JsonProperty("username") val username: kotlin.String? = null,
|
||||
|
||||
@ApiModelProperty(value = "")
|
||||
@JsonProperty("firstName") val firstName: kotlin.String? = null,
|
||||
|
||||
@ApiModelProperty(value = "")
|
||||
@JsonProperty("lastName") val lastName: kotlin.String? = null,
|
||||
|
||||
@ApiModelProperty(value = "")
|
||||
@JsonProperty("email") val email: kotlin.String? = null,
|
||||
|
||||
@ApiModelProperty(value = "")
|
||||
@JsonProperty("password") val password: kotlin.String? = null,
|
||||
|
||||
@ApiModelProperty(value = "")
|
||||
@JsonProperty("phone") val phone: kotlin.String? = null,
|
||||
|
||||
@ApiModelProperty(value = "User Status")
|
||||
@JsonProperty("userStatus") val userStatus: kotlin.Int? = null
|
||||
) {
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
spring.application.name=openAPIPetstore
|
||||
server.port=8080
|
||||
spring.jackson.serialization.WRITE_DATES_AS_TIMESTAMPS=false
|
||||
Reference in New Issue
Block a user