[Kotlin][Spring] use flag delegatePattern together with skipDefaultInterface (#19212)

* fix #19211 kotlin-spring flag delegatePattern together with skipDefaultInterface generates broken code

* add kotlin-springboot-delegate-nodefaults to the workflow

* fix Platform declaration clash

* move kotlin-springboot-delegate-nodefaults to the kotlin-server-jdk17 file

* fixed empty line
This commit is contained in:
Peter Storch
2024-07-23 12:41:14 +02:00
committed by GitHub
parent 6ad5864d28
commit 0e70d1f068
36 changed files with 1418 additions and 11 deletions

View File

@@ -0,0 +1,13 @@
package org.openapitools
import org.springframework.boot.runApplication
import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.context.annotation.ComponentScan
@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,19 @@
package org.openapitools.api
import org.springframework.web.context.request.NativeWebRequest
import jakarta.servlet.http.HttpServletResponse
import java.io.IOException
object ApiUtil {
fun setExampleResponse(req: NativeWebRequest, contentType: String, example: String) {
try {
val res = req.getNativeResponse(HttpServletResponse::class.java)
res?.characterEncoding = "UTF-8"
res?.addHeader("Content-Type", contentType)
res?.writer?.print(example)
} catch (e: IOException) {
throw RuntimeException(e)
}
}
}

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 jakarta.servlet.http.HttpServletResponse
import jakarta.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,205 @@
/**
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech) (7.8.0-SNAPSHOT).
* https://openapi-generator.tech
* Do not edit the class manually.
*/
package org.openapitools.api
import org.openapitools.model.ModelApiResponse
import org.openapitools.model.Pet
import io.swagger.v3.oas.annotations.*
import io.swagger.v3.oas.annotations.enums.*
import io.swagger.v3.oas.annotations.media.*
import io.swagger.v3.oas.annotations.responses.*
import io.swagger.v3.oas.annotations.security.*
import org.springframework.http.HttpStatus
import org.springframework.http.MediaType
import org.springframework.http.ResponseEntity
import org.springframework.web.bind.annotation.*
import org.springframework.validation.annotation.Validated
import org.springframework.web.context.request.NativeWebRequest
import org.springframework.beans.factory.annotation.Autowired
import jakarta.validation.constraints.DecimalMax
import jakarta.validation.constraints.DecimalMin
import jakarta.validation.constraints.Email
import jakarta.validation.constraints.Max
import jakarta.validation.constraints.Min
import jakarta.validation.constraints.NotNull
import jakarta.validation.constraints.Pattern
import jakarta.validation.constraints.Size
import jakarta.validation.Valid
import kotlin.collections.List
import kotlin.collections.Map
@RestController
@Validated
@RequestMapping("\${api.base-path:/v2}")
interface PetApi {
fun getDelegate(): PetApiDelegate
@Operation(
tags = ["pet",],
summary = "Add a new pet to the store",
operationId = "addPet",
description = """""",
responses = [
ApiResponse(responseCode = "200", description = "successful operation", content = [Content(schema = Schema(implementation = Pet::class))]),
ApiResponse(responseCode = "405", description = "Invalid input")
],
security = [ SecurityRequirement(name = "petstore_auth", scopes = [ "write:pets", "read:pets" ]) ]
)
@RequestMapping(
method = [RequestMethod.POST],
value = ["/pet"],
produces = ["application/xml", "application/json"],
consumes = ["application/json", "application/xml"]
)
fun addPet(@Parameter(description = "Pet object that needs to be added to the store", required = true) @Valid @RequestBody pet: Pet): ResponseEntity<Pet> {
return getDelegate().addPet(pet)
}
@Operation(
tags = ["pet",],
summary = "Deletes a pet",
operationId = "deletePet",
description = """""",
responses = [
ApiResponse(responseCode = "400", description = "Invalid pet value")
],
security = [ SecurityRequirement(name = "petstore_auth", scopes = [ "write:pets", "read:pets" ]) ]
)
@RequestMapping(
method = [RequestMethod.DELETE],
value = ["/pet/{petId}"]
)
fun deletePet(@Parameter(description = "Pet id to delete", required = true) @PathVariable("petId") petId: kotlin.Long,@Parameter(description = "", `in` = ParameterIn.HEADER) @RequestHeader(value = "api_key", required = false) apiKey: kotlin.String?): ResponseEntity<Unit> {
return getDelegate().deletePet(petId, apiKey)
}
@Operation(
tags = ["pet",],
summary = "Finds Pets by status",
operationId = "findPetsByStatus",
description = """Multiple status values can be provided with comma separated strings""",
responses = [
ApiResponse(responseCode = "200", description = "successful operation", content = [Content(array = ArraySchema(schema = Schema(implementation = Pet::class)))]),
ApiResponse(responseCode = "400", description = "Invalid status value")
],
security = [ SecurityRequirement(name = "petstore_auth", scopes = [ "read:pets" ]) ]
)
@RequestMapping(
method = [RequestMethod.GET],
value = ["/pet/findByStatus"],
produces = ["application/xml", "application/json"]
)
fun findPetsByStatus(@NotNull @Parameter(description = "Status values that need to be considered for filter", required = true, schema = Schema(allowableValues = ["available", "pending", "sold"])) @Valid @RequestParam(value = "status", required = true) status: kotlin.collections.List<kotlin.String>): ResponseEntity<List<Pet>> {
return getDelegate().findPetsByStatus(status)
}
@Operation(
tags = ["pet",],
summary = "Finds Pets by tags",
operationId = "findPetsByTags",
description = """Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.""",
responses = [
ApiResponse(responseCode = "200", description = "successful operation", content = [Content(array = ArraySchema(schema = Schema(implementation = Pet::class)))]),
ApiResponse(responseCode = "400", description = "Invalid tag value")
],
security = [ SecurityRequirement(name = "petstore_auth", scopes = [ "read:pets" ]) ]
)
@RequestMapping(
method = [RequestMethod.GET],
value = ["/pet/findByTags"],
produces = ["application/xml", "application/json"]
)
fun findPetsByTags(@NotNull @Parameter(description = "Tags to filter by", required = true) @Valid @RequestParam(value = "tags", required = true) tags: kotlin.collections.List<kotlin.String>): ResponseEntity<List<Pet>> {
return getDelegate().findPetsByTags(tags)
}
@Operation(
tags = ["pet",],
summary = "Find pet by ID",
operationId = "getPetById",
description = """Returns a single pet""",
responses = [
ApiResponse(responseCode = "200", description = "successful operation", content = [Content(schema = Schema(implementation = Pet::class))]),
ApiResponse(responseCode = "400", description = "Invalid ID supplied"),
ApiResponse(responseCode = "404", description = "Pet not found")
],
security = [ SecurityRequirement(name = "api_key") ]
)
@RequestMapping(
method = [RequestMethod.GET],
value = ["/pet/{petId}"],
produces = ["application/xml", "application/json"]
)
fun getPetById(@Parameter(description = "ID of pet to return", required = true) @PathVariable("petId") petId: kotlin.Long): ResponseEntity<Pet> {
return getDelegate().getPetById(petId)
}
@Operation(
tags = ["pet",],
summary = "Update an existing pet",
operationId = "updatePet",
description = """""",
responses = [
ApiResponse(responseCode = "200", description = "successful operation", content = [Content(schema = Schema(implementation = Pet::class))]),
ApiResponse(responseCode = "400", description = "Invalid ID supplied"),
ApiResponse(responseCode = "404", description = "Pet not found"),
ApiResponse(responseCode = "405", description = "Validation exception")
],
security = [ SecurityRequirement(name = "petstore_auth", scopes = [ "write:pets", "read:pets" ]) ]
)
@RequestMapping(
method = [RequestMethod.PUT],
value = ["/pet"],
produces = ["application/xml", "application/json"],
consumes = ["application/json", "application/xml"]
)
fun updatePet(@Parameter(description = "Pet object that needs to be added to the store", required = true) @Valid @RequestBody pet: Pet): ResponseEntity<Pet> {
return getDelegate().updatePet(pet)
}
@Operation(
tags = ["pet",],
summary = "Updates a pet in the store with form data",
operationId = "updatePetWithForm",
description = """""",
responses = [
ApiResponse(responseCode = "405", description = "Invalid input")
],
security = [ SecurityRequirement(name = "petstore_auth", scopes = [ "write:pets", "read:pets" ]) ]
)
@RequestMapping(
method = [RequestMethod.POST],
value = ["/pet/{petId}"],
consumes = ["application/x-www-form-urlencoded"]
)
fun updatePetWithForm(@Parameter(description = "ID of pet that needs to be updated", required = true) @PathVariable("petId") petId: kotlin.Long,@Parameter(description = "Updated name of the pet") @RequestParam(value = "name", required = false) name: kotlin.String? ,@Parameter(description = "Updated status of the pet") @RequestParam(value = "status", required = false) status: kotlin.String? ): ResponseEntity<Unit> {
return getDelegate().updatePetWithForm(petId, name, status)
}
@Operation(
tags = ["pet",],
summary = "uploads an image",
operationId = "uploadFile",
description = """""",
responses = [
ApiResponse(responseCode = "200", description = "successful operation", content = [Content(schema = Schema(implementation = ModelApiResponse::class))])
],
security = [ SecurityRequirement(name = "petstore_auth", scopes = [ "write:pets", "read:pets" ]) ]
)
@RequestMapping(
method = [RequestMethod.POST],
value = ["/pet/{petId}/uploadImage"],
produces = ["application/json"],
consumes = ["multipart/form-data"]
)
fun uploadFile(@Parameter(description = "ID of pet to update", required = true) @PathVariable("petId") petId: kotlin.Long,@Parameter(description = "Additional data to pass to server") @RequestParam(value = "additionalMetadata", required = false) additionalMetadata: kotlin.String? ,@Parameter(description = "file to upload") @Valid @RequestPart("file", required = false) file: org.springframework.core.io.Resource?): ResponseEntity<ModelApiResponse> {
return getDelegate().uploadFile(petId, additionalMetadata, file)
}
}

View File

@@ -0,0 +1,14 @@
package org.openapitools.api
import org.springframework.stereotype.Controller
import org.springframework.web.bind.annotation.RequestMapping
import java.util.Optional
@jakarta.annotation.Generated(value = ["org.openapitools.codegen.languages.KotlinSpringServerCodegen"], comments = "Generator version: 7.8.0-SNAPSHOT")
@Controller
class PetApiController(
private val delegate: PetApiDelegate
) : PetApi {
override fun getDelegate(): PetApiDelegate = delegate
}

View File

@@ -0,0 +1,74 @@
package org.openapitools.api
import org.openapitools.model.ModelApiResponse
import org.openapitools.model.Pet
import org.springframework.http.HttpStatus
import org.springframework.http.MediaType
import org.springframework.http.ResponseEntity
import org.springframework.web.context.request.NativeWebRequest
import org.springframework.core.io.Resource
import java.util.Optional
/**
* A delegate to be called by the {@link PetApiController}}.
* Implement this interface with a {@link org.springframework.stereotype.Service} annotated class.
*/
@jakarta.annotation.Generated(value = ["org.openapitools.codegen.languages.KotlinSpringServerCodegen"], comments = "Generator version: 7.8.0-SNAPSHOT")
interface PetApiDelegate {
fun getRequest(): Optional<NativeWebRequest> = Optional.empty()
/**
* @see PetApi#addPet
*/
fun addPet(pet: Pet): ResponseEntity<Pet>
/**
* @see PetApi#deletePet
*/
fun deletePet(petId: kotlin.Long,
apiKey: kotlin.String?): ResponseEntity<Unit>
/**
* @see PetApi#findPetsByStatus
*/
fun findPetsByStatus(status: kotlin.collections.List<kotlin.String>): ResponseEntity<List<Pet>>
/**
* @see PetApi#findPetsByTags
*/
fun findPetsByTags(tags: kotlin.collections.List<kotlin.String>): ResponseEntity<List<Pet>>
/**
* @see PetApi#getPetById
*/
fun getPetById(petId: kotlin.Long): ResponseEntity<Pet>
/**
* @see PetApi#updatePet
*/
fun updatePet(pet: Pet): ResponseEntity<Pet>
/**
* @see PetApi#updatePetWithForm
*/
fun updatePetWithForm(petId: kotlin.Long,
name: kotlin.String?,
status: kotlin.String?): ResponseEntity<Unit>
/**
* @see PetApi#uploadFile
*/
fun uploadFile(petId: kotlin.Long,
additionalMetadata: kotlin.String?,
file: Resource?): ResponseEntity<ModelApiResponse>
}

View File

@@ -0,0 +1,119 @@
/**
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech) (7.8.0-SNAPSHOT).
* https://openapi-generator.tech
* Do not edit the class manually.
*/
package org.openapitools.api
import org.openapitools.model.Order
import io.swagger.v3.oas.annotations.*
import io.swagger.v3.oas.annotations.enums.*
import io.swagger.v3.oas.annotations.media.*
import io.swagger.v3.oas.annotations.responses.*
import io.swagger.v3.oas.annotations.security.*
import org.springframework.http.HttpStatus
import org.springframework.http.MediaType
import org.springframework.http.ResponseEntity
import org.springframework.web.bind.annotation.*
import org.springframework.validation.annotation.Validated
import org.springframework.web.context.request.NativeWebRequest
import org.springframework.beans.factory.annotation.Autowired
import jakarta.validation.constraints.DecimalMax
import jakarta.validation.constraints.DecimalMin
import jakarta.validation.constraints.Email
import jakarta.validation.constraints.Max
import jakarta.validation.constraints.Min
import jakarta.validation.constraints.NotNull
import jakarta.validation.constraints.Pattern
import jakarta.validation.constraints.Size
import jakarta.validation.Valid
import kotlin.collections.List
import kotlin.collections.Map
@RestController
@Validated
@RequestMapping("\${api.base-path:/v2}")
interface StoreApi {
fun getDelegate(): StoreApiDelegate
@Operation(
tags = ["store",],
summary = "Delete purchase order by ID",
operationId = "deleteOrder",
description = """For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors""",
responses = [
ApiResponse(responseCode = "400", description = "Invalid ID supplied"),
ApiResponse(responseCode = "404", description = "Order not found")
]
)
@RequestMapping(
method = [RequestMethod.DELETE],
value = ["/store/order/{orderId}"]
)
fun deleteOrder(@Parameter(description = "ID of the order that needs to be deleted", required = true) @PathVariable("orderId") orderId: kotlin.String): ResponseEntity<Unit> {
return getDelegate().deleteOrder(orderId)
}
@Operation(
tags = ["store",],
summary = "Returns pet inventories by status",
operationId = "getInventory",
description = """Returns a map of status codes to quantities""",
responses = [
ApiResponse(responseCode = "200", description = "successful operation", content = [Content(schema = Schema(implementation = kotlin.collections.Map::class))])
],
security = [ SecurityRequirement(name = "api_key") ]
)
@RequestMapping(
method = [RequestMethod.GET],
value = ["/store/inventory"],
produces = ["application/json"]
)
fun getInventory(): ResponseEntity<Map<String, kotlin.Int>> {
return getDelegate().getInventory()
}
@Operation(
tags = ["store",],
summary = "Find purchase order by ID",
operationId = "getOrderById",
description = """For valid response try integer IDs with value <= 5 or > 10. Other values will generate exceptions""",
responses = [
ApiResponse(responseCode = "200", description = "successful operation", content = [Content(schema = Schema(implementation = Order::class))]),
ApiResponse(responseCode = "400", description = "Invalid ID supplied"),
ApiResponse(responseCode = "404", description = "Order not found")
]
)
@RequestMapping(
method = [RequestMethod.GET],
value = ["/store/order/{orderId}"],
produces = ["application/xml", "application/json"]
)
fun getOrderById(@Min(1L) @Max(5L) @Parameter(description = "ID of pet that needs to be fetched", required = true) @PathVariable("orderId") orderId: kotlin.Long): ResponseEntity<Order> {
return getDelegate().getOrderById(orderId)
}
@Operation(
tags = ["store",],
summary = "Place an order for a pet",
operationId = "placeOrder",
description = """""",
responses = [
ApiResponse(responseCode = "200", description = "successful operation", content = [Content(schema = Schema(implementation = Order::class))]),
ApiResponse(responseCode = "400", description = "Invalid Order")
]
)
@RequestMapping(
method = [RequestMethod.POST],
value = ["/store/order"],
produces = ["application/xml", "application/json"],
consumes = ["application/json"]
)
fun placeOrder(@Parameter(description = "order placed for purchasing the pet", required = true) @Valid @RequestBody order: Order): ResponseEntity<Order> {
return getDelegate().placeOrder(order)
}
}

View File

@@ -0,0 +1,14 @@
package org.openapitools.api
import org.springframework.stereotype.Controller
import org.springframework.web.bind.annotation.RequestMapping
import java.util.Optional
@jakarta.annotation.Generated(value = ["org.openapitools.codegen.languages.KotlinSpringServerCodegen"], comments = "Generator version: 7.8.0-SNAPSHOT")
@Controller
class StoreApiController(
private val delegate: StoreApiDelegate
) : StoreApi {
override fun getDelegate(): StoreApiDelegate = delegate
}

View File

@@ -0,0 +1,44 @@
package org.openapitools.api
import org.openapitools.model.Order
import org.springframework.http.HttpStatus
import org.springframework.http.MediaType
import org.springframework.http.ResponseEntity
import org.springframework.web.context.request.NativeWebRequest
import org.springframework.core.io.Resource
import java.util.Optional
/**
* A delegate to be called by the {@link StoreApiController}}.
* Implement this interface with a {@link org.springframework.stereotype.Service} annotated class.
*/
@jakarta.annotation.Generated(value = ["org.openapitools.codegen.languages.KotlinSpringServerCodegen"], comments = "Generator version: 7.8.0-SNAPSHOT")
interface StoreApiDelegate {
fun getRequest(): Optional<NativeWebRequest> = Optional.empty()
/**
* @see StoreApi#deleteOrder
*/
fun deleteOrder(orderId: kotlin.String): ResponseEntity<Unit>
/**
* @see StoreApi#getInventory
*/
fun getInventory(): ResponseEntity<Map<String, kotlin.Int>>
/**
* @see StoreApi#getOrderById
*/
fun getOrderById(orderId: kotlin.Long): ResponseEntity<Order>
/**
* @see StoreApi#placeOrder
*/
fun placeOrder(order: Order): ResponseEntity<Order>
}

View File

@@ -0,0 +1,195 @@
/**
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech) (7.8.0-SNAPSHOT).
* https://openapi-generator.tech
* Do not edit the class manually.
*/
package org.openapitools.api
import org.openapitools.model.User
import io.swagger.v3.oas.annotations.*
import io.swagger.v3.oas.annotations.enums.*
import io.swagger.v3.oas.annotations.media.*
import io.swagger.v3.oas.annotations.responses.*
import io.swagger.v3.oas.annotations.security.*
import org.springframework.http.HttpStatus
import org.springframework.http.MediaType
import org.springframework.http.ResponseEntity
import org.springframework.web.bind.annotation.*
import org.springframework.validation.annotation.Validated
import org.springframework.web.context.request.NativeWebRequest
import org.springframework.beans.factory.annotation.Autowired
import jakarta.validation.constraints.DecimalMax
import jakarta.validation.constraints.DecimalMin
import jakarta.validation.constraints.Email
import jakarta.validation.constraints.Max
import jakarta.validation.constraints.Min
import jakarta.validation.constraints.NotNull
import jakarta.validation.constraints.Pattern
import jakarta.validation.constraints.Size
import jakarta.validation.Valid
import kotlin.collections.List
import kotlin.collections.Map
@RestController
@Validated
@RequestMapping("\${api.base-path:/v2}")
interface UserApi {
fun getDelegate(): UserApiDelegate
@Operation(
tags = ["user",],
summary = "Create user",
operationId = "createUser",
description = """This can only be done by the logged in user.""",
responses = [
ApiResponse(responseCode = "200", description = "successful operation")
],
security = [ SecurityRequirement(name = "api_key") ]
)
@RequestMapping(
method = [RequestMethod.POST],
value = ["/user"],
consumes = ["application/json"]
)
fun createUser(@Parameter(description = "Created user object", required = true) @Valid @RequestBody user: User): ResponseEntity<Unit> {
return getDelegate().createUser(user)
}
@Operation(
tags = ["user",],
summary = "Creates list of users with given input array",
operationId = "createUsersWithArrayInput",
description = """""",
responses = [
ApiResponse(responseCode = "200", description = "successful operation")
],
security = [ SecurityRequirement(name = "api_key") ]
)
@RequestMapping(
method = [RequestMethod.POST],
value = ["/user/createWithArray"],
consumes = ["application/json"]
)
fun createUsersWithArrayInput(@Parameter(description = "List of user object", required = true) @Valid @RequestBody user: kotlin.collections.List<User>): ResponseEntity<Unit> {
return getDelegate().createUsersWithArrayInput(user)
}
@Operation(
tags = ["user",],
summary = "Creates list of users with given input array",
operationId = "createUsersWithListInput",
description = """""",
responses = [
ApiResponse(responseCode = "200", description = "successful operation")
],
security = [ SecurityRequirement(name = "api_key") ]
)
@RequestMapping(
method = [RequestMethod.POST],
value = ["/user/createWithList"],
consumes = ["application/json"]
)
fun createUsersWithListInput(@Parameter(description = "List of user object", required = true) @Valid @RequestBody user: kotlin.collections.List<User>): ResponseEntity<Unit> {
return getDelegate().createUsersWithListInput(user)
}
@Operation(
tags = ["user",],
summary = "Delete user",
operationId = "deleteUser",
description = """This can only be done by the logged in user.""",
responses = [
ApiResponse(responseCode = "400", description = "Invalid username supplied"),
ApiResponse(responseCode = "404", description = "User not found")
],
security = [ SecurityRequirement(name = "api_key") ]
)
@RequestMapping(
method = [RequestMethod.DELETE],
value = ["/user/{username}"]
)
fun deleteUser(@Parameter(description = "The name that needs to be deleted", required = true) @PathVariable("username") username: kotlin.String): ResponseEntity<Unit> {
return getDelegate().deleteUser(username)
}
@Operation(
tags = ["user",],
summary = "Get user by user name",
operationId = "getUserByName",
description = """""",
responses = [
ApiResponse(responseCode = "200", description = "successful operation", content = [Content(schema = Schema(implementation = User::class))]),
ApiResponse(responseCode = "400", description = "Invalid username supplied"),
ApiResponse(responseCode = "404", description = "User not found")
]
)
@RequestMapping(
method = [RequestMethod.GET],
value = ["/user/{username}"],
produces = ["application/xml", "application/json"]
)
fun getUserByName(@Parameter(description = "The name that needs to be fetched. Use user1 for testing.", required = true) @PathVariable("username") username: kotlin.String): ResponseEntity<User> {
return getDelegate().getUserByName(username)
}
@Operation(
tags = ["user",],
summary = "Logs user into the system",
operationId = "loginUser",
description = """""",
responses = [
ApiResponse(responseCode = "200", description = "successful operation", content = [Content(schema = Schema(implementation = kotlin.String::class))]),
ApiResponse(responseCode = "400", description = "Invalid username/password supplied")
]
)
@RequestMapping(
method = [RequestMethod.GET],
value = ["/user/login"],
produces = ["application/xml", "application/json"]
)
fun loginUser(@NotNull @Pattern(regexp="^[a-zA-Z0-9]+[a-zA-Z0-9\\.\\-_]*[a-zA-Z0-9]+$") @Parameter(description = "The user name for login", required = true) @Valid @RequestParam(value = "username", required = true) username: kotlin.String,@NotNull @Parameter(description = "The password for login in clear text", required = true) @Valid @RequestParam(value = "password", required = true) password: kotlin.String): ResponseEntity<kotlin.String> {
return getDelegate().loginUser(username, password)
}
@Operation(
tags = ["user",],
summary = "Logs out current logged in user session",
operationId = "logoutUser",
description = """""",
responses = [
ApiResponse(responseCode = "200", description = "successful operation")
],
security = [ SecurityRequirement(name = "api_key") ]
)
@RequestMapping(
method = [RequestMethod.GET],
value = ["/user/logout"]
)
fun logoutUser(): ResponseEntity<Unit> {
return getDelegate().logoutUser()
}
@Operation(
tags = ["user",],
summary = "Updated user",
operationId = "updateUser",
description = """This can only be done by the logged in user.""",
responses = [
ApiResponse(responseCode = "400", description = "Invalid user supplied"),
ApiResponse(responseCode = "404", description = "User not found")
],
security = [ SecurityRequirement(name = "api_key") ]
)
@RequestMapping(
method = [RequestMethod.PUT],
value = ["/user/{username}"],
consumes = ["application/json"]
)
fun updateUser(@Parameter(description = "name that need to be deleted", required = true) @PathVariable("username") username: kotlin.String,@Parameter(description = "Updated user object", required = true) @Valid @RequestBody user: User): ResponseEntity<Unit> {
return getDelegate().updateUser(username, user)
}
}

View File

@@ -0,0 +1,14 @@
package org.openapitools.api
import org.springframework.stereotype.Controller
import org.springframework.web.bind.annotation.RequestMapping
import java.util.Optional
@jakarta.annotation.Generated(value = ["org.openapitools.codegen.languages.KotlinSpringServerCodegen"], comments = "Generator version: 7.8.0-SNAPSHOT")
@Controller
class UserApiController(
private val delegate: UserApiDelegate
) : UserApi {
override fun getDelegate(): UserApiDelegate = delegate
}

View File

@@ -0,0 +1,70 @@
package org.openapitools.api
import org.openapitools.model.User
import org.springframework.http.HttpStatus
import org.springframework.http.MediaType
import org.springframework.http.ResponseEntity
import org.springframework.web.context.request.NativeWebRequest
import org.springframework.core.io.Resource
import java.util.Optional
/**
* A delegate to be called by the {@link UserApiController}}.
* Implement this interface with a {@link org.springframework.stereotype.Service} annotated class.
*/
@jakarta.annotation.Generated(value = ["org.openapitools.codegen.languages.KotlinSpringServerCodegen"], comments = "Generator version: 7.8.0-SNAPSHOT")
interface UserApiDelegate {
fun getRequest(): Optional<NativeWebRequest> = Optional.empty()
/**
* @see UserApi#createUser
*/
fun createUser(user: User): ResponseEntity<Unit>
/**
* @see UserApi#createUsersWithArrayInput
*/
fun createUsersWithArrayInput(user: kotlin.collections.List<User>): ResponseEntity<Unit>
/**
* @see UserApi#createUsersWithListInput
*/
fun createUsersWithListInput(user: kotlin.collections.List<User>): ResponseEntity<Unit>
/**
* @see UserApi#deleteUser
*/
fun deleteUser(username: kotlin.String): ResponseEntity<Unit>
/**
* @see UserApi#getUserByName
*/
fun getUserByName(username: kotlin.String): ResponseEntity<User>
/**
* @see UserApi#loginUser
*/
fun loginUser(username: kotlin.String,
password: kotlin.String): ResponseEntity<kotlin.String>
/**
* @see UserApi#logoutUser
*/
fun logoutUser(): ResponseEntity<Unit>
/**
* @see UserApi#updateUser
*/
fun updateUser(username: kotlin.String,
user: User): ResponseEntity<Unit>
}

View File

@@ -0,0 +1,32 @@
package org.openapitools.model
import java.util.Objects
import com.fasterxml.jackson.annotation.JsonProperty
import jakarta.validation.constraints.DecimalMax
import jakarta.validation.constraints.DecimalMin
import jakarta.validation.constraints.Email
import jakarta.validation.constraints.Max
import jakarta.validation.constraints.Min
import jakarta.validation.constraints.NotNull
import jakarta.validation.constraints.Pattern
import jakarta.validation.constraints.Size
import jakarta.validation.Valid
import io.swagger.v3.oas.annotations.media.Schema
/**
* A category for a pet
* @param id
* @param name
*/
data class Category(
@Schema(example = "null", description = "")
@get:JsonProperty("id") val id: kotlin.Long? = null,
@get:Pattern(regexp="^[a-zA-Z0-9]+[a-zA-Z0-9\\.\\-_]*[a-zA-Z0-9]+$")
@Schema(example = "null", description = "")
@get:JsonProperty("name") val name: kotlin.String? = null
) {
}

View File

@@ -0,0 +1,35 @@
package org.openapitools.model
import java.util.Objects
import com.fasterxml.jackson.annotation.JsonProperty
import jakarta.validation.constraints.DecimalMax
import jakarta.validation.constraints.DecimalMin
import jakarta.validation.constraints.Email
import jakarta.validation.constraints.Max
import jakarta.validation.constraints.Min
import jakarta.validation.constraints.NotNull
import jakarta.validation.constraints.Pattern
import jakarta.validation.constraints.Size
import jakarta.validation.Valid
import io.swagger.v3.oas.annotations.media.Schema
/**
* Describes the result of uploading an image resource
* @param code
* @param type
* @param message
*/
data class ModelApiResponse(
@Schema(example = "null", description = "")
@get:JsonProperty("code") val code: kotlin.Int? = null,
@Schema(example = "null", description = "")
@get:JsonProperty("type") val type: kotlin.String? = null,
@Schema(example = "null", description = "")
@get:JsonProperty("message") val message: kotlin.String? = null
) {
}

View File

@@ -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 jakarta.validation.constraints.DecimalMax
import jakarta.validation.constraints.DecimalMin
import jakarta.validation.constraints.Email
import jakarta.validation.constraints.Max
import jakarta.validation.constraints.Min
import jakarta.validation.constraints.NotNull
import jakarta.validation.constraints.Pattern
import jakarta.validation.constraints.Size
import jakarta.validation.Valid
import io.swagger.v3.oas.annotations.media.Schema
/**
* 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(
@Schema(example = "null", description = "")
@get:JsonProperty("id") val id: kotlin.Long? = null,
@Schema(example = "null", description = "")
@get:JsonProperty("petId") val petId: kotlin.Long? = null,
@Schema(example = "null", description = "")
@get:JsonProperty("quantity") val quantity: kotlin.Int? = null,
@Schema(example = "null", description = "")
@get:JsonProperty("shipDate") val shipDate: java.time.OffsetDateTime? = null,
@Schema(example = "null", description = "Order Status")
@get:JsonProperty("status") val status: Order.Status? = null,
@Schema(example = "null", description = "")
@get:JsonProperty("complete") val complete: kotlin.Boolean? = false
) {
/**
* 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 jakarta.validation.constraints.DecimalMax
import jakarta.validation.constraints.DecimalMin
import jakarta.validation.constraints.Email
import jakarta.validation.constraints.Max
import jakarta.validation.constraints.Min
import jakarta.validation.constraints.NotNull
import jakarta.validation.constraints.Pattern
import jakarta.validation.constraints.Size
import jakarta.validation.Valid
import io.swagger.v3.oas.annotations.media.Schema
/**
* A pet for sale in the pet store
* @param name
* @param photoUrls
* @param id
* @param category
* @param tags
* @param status pet status in the store
*/
data class Pet(
@Schema(example = "doggie", required = true, description = "")
@get:JsonProperty("name", required = true) val name: kotlin.String,
@Schema(example = "null", required = true, description = "")
@get:JsonProperty("photoUrls", required = true) val photoUrls: kotlin.collections.List<kotlin.String>,
@Schema(example = "null", description = "")
@get:JsonProperty("id") val id: kotlin.Long? = null,
@field:Valid
@Schema(example = "null", description = "")
@get:JsonProperty("category") val category: Category? = null,
@field:Valid
@Schema(example = "null", description = "")
@get:JsonProperty("tags") val tags: kotlin.collections.List<Tag>? = null,
@Schema(example = "null", description = "pet status in the store")
@Deprecated(message = "")
@get: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")
}
}

View File

@@ -0,0 +1,31 @@
package org.openapitools.model
import java.util.Objects
import com.fasterxml.jackson.annotation.JsonProperty
import jakarta.validation.constraints.DecimalMax
import jakarta.validation.constraints.DecimalMin
import jakarta.validation.constraints.Email
import jakarta.validation.constraints.Max
import jakarta.validation.constraints.Min
import jakarta.validation.constraints.NotNull
import jakarta.validation.constraints.Pattern
import jakarta.validation.constraints.Size
import jakarta.validation.Valid
import io.swagger.v3.oas.annotations.media.Schema
/**
* A tag for a pet
* @param id
* @param name
*/
data class Tag(
@Schema(example = "null", description = "")
@get:JsonProperty("id") val id: kotlin.Long? = null,
@Schema(example = "null", description = "")
@get:JsonProperty("name") val name: kotlin.String? = null
) {
}

View File

@@ -0,0 +1,55 @@
package org.openapitools.model
import java.util.Objects
import com.fasterxml.jackson.annotation.JsonProperty
import jakarta.validation.constraints.DecimalMax
import jakarta.validation.constraints.DecimalMin
import jakarta.validation.constraints.Email
import jakarta.validation.constraints.Max
import jakarta.validation.constraints.Min
import jakarta.validation.constraints.NotNull
import jakarta.validation.constraints.Pattern
import jakarta.validation.constraints.Size
import jakarta.validation.Valid
import io.swagger.v3.oas.annotations.media.Schema
/**
* 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(
@Schema(example = "null", description = "")
@get:JsonProperty("id") val id: kotlin.Long? = null,
@Schema(example = "null", description = "")
@get:JsonProperty("username") val username: kotlin.String? = null,
@Schema(example = "null", description = "")
@get:JsonProperty("firstName") val firstName: kotlin.String? = null,
@Schema(example = "null", description = "")
@get:JsonProperty("lastName") val lastName: kotlin.String? = null,
@Schema(example = "null", description = "")
@get:JsonProperty("email") val email: kotlin.String? = null,
@Schema(example = "null", description = "")
@get:JsonProperty("password") val password: kotlin.String? = null,
@Schema(example = "null", description = "")
@get:JsonProperty("phone") val phone: kotlin.String? = null,
@Schema(example = "null", description = "User Status")
@get:JsonProperty("userStatus") val userStatus: kotlin.Int? = null
) {
}

View File

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