[Java] [Spring] Spring new mapping annotations (#7189)

* Spring new mapping annotations

* update other spring mvc templates
This commit is contained in:
Oleh Kurpiak
2020-08-24 12:03:21 +03:00
committed by GitHub
parent 19140dc00d
commit 8bd2dd4c9d
85 changed files with 2026 additions and 2150 deletions

View File

@@ -13,14 +13,7 @@ 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.web.bind.annotation.*
import org.springframework.validation.annotation.Validated
import org.springframework.web.context.request.NativeWebRequest
import org.springframework.beans.factory.annotation.Autowired
@@ -50,10 +43,10 @@ class PetApiController(@Autowired(required = true) val service: PetApiService) {
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(
@PostMapping(
value = ["/pet"],
consumes = ["application/json", "application/xml"],
method = [RequestMethod.POST])
consumes = ["application/json", "application/xml"]
)
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))
@@ -66,9 +59,9 @@ class PetApiController(@Autowired(required = true) val service: PetApiService) {
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])
@DeleteMapping(
value = ["/pet/{petId}"]
)
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> {
@@ -84,10 +77,10 @@ class PetApiController(@Autowired(required = true) val service: PetApiService) {
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(
@GetMapping(
value = ["/pet/findByStatus"],
produces = ["application/xml", "application/json"],
method = [RequestMethod.GET])
produces = ["application/xml", "application/json"]
)
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))
@@ -102,10 +95,10 @@ class PetApiController(@Autowired(required = true) val service: PetApiService) {
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(
@GetMapping(
value = ["/pet/findByTags"],
produces = ["application/xml", "application/json"],
method = [RequestMethod.GET])
produces = ["application/xml", "application/json"]
)
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))
@@ -119,10 +112,10 @@ class PetApiController(@Autowired(required = true) val service: PetApiService) {
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(
@GetMapping(
value = ["/pet/{petId}"],
produces = ["application/xml", "application/json"],
method = [RequestMethod.GET])
produces = ["application/xml", "application/json"]
)
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))
@@ -135,10 +128,10 @@ class PetApiController(@Autowired(required = true) val service: PetApiService) {
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(
@PutMapping(
value = ["/pet"],
consumes = ["application/json", "application/xml"],
method = [RequestMethod.PUT])
consumes = ["application/json", "application/xml"]
)
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))
@@ -151,10 +144,10 @@ class PetApiController(@Autowired(required = true) val service: PetApiService) {
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(
@PostMapping(
value = ["/pet/{petId}"],
consumes = ["application/x-www-form-urlencoded"],
method = [RequestMethod.POST])
consumes = ["application/x-www-form-urlencoded"]
)
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?
@@ -170,11 +163,11 @@ class PetApiController(@Autowired(required = true) val service: PetApiService) {
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(
@PostMapping(
value = ["/pet/{petId}/uploadImage"],
produces = ["application/json"],
consumes = ["multipart/form-data"],
method = [RequestMethod.POST])
produces = ["application/json"],
consumes = ["multipart/form-data"]
)
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?

View File

@@ -12,14 +12,7 @@ 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.web.bind.annotation.*
import org.springframework.validation.annotation.Validated
import org.springframework.web.context.request.NativeWebRequest
import org.springframework.beans.factory.annotation.Autowired
@@ -48,9 +41,9 @@ class StoreApiController(@Autowired(required = true) val service: StoreApiServic
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])
@DeleteMapping(
value = ["/store/order/{orderId}"]
)
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))
@@ -65,10 +58,10 @@ class StoreApiController(@Autowired(required = true) val service: StoreApiServic
authorizations = [Authorization(value = "api_key")])
@ApiResponses(
value = [ApiResponse(code = 200, message = "successful operation", response = kotlin.collections.Map::class, responseContainer = "Map")])
@RequestMapping(
@GetMapping(
value = ["/store/inventory"],
produces = ["application/json"],
method = [RequestMethod.GET])
produces = ["application/json"]
)
fun getInventory(): ResponseEntity<Map<String, kotlin.Int>> {
return ResponseEntity(service.getInventory(), HttpStatus.valueOf(200))
}
@@ -80,10 +73,10 @@ class StoreApiController(@Autowired(required = true) val service: StoreApiServic
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(
@GetMapping(
value = ["/store/order/{orderId}"],
produces = ["application/xml", "application/json"],
method = [RequestMethod.GET])
produces = ["application/xml", "application/json"]
)
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))
@@ -96,10 +89,10 @@ class StoreApiController(@Autowired(required = true) val service: StoreApiServic
response = Order::class)
@ApiResponses(
value = [ApiResponse(code = 200, message = "successful operation", response = Order::class),ApiResponse(code = 400, message = "Invalid Order")])
@RequestMapping(
@PostMapping(
value = ["/store/order"],
produces = ["application/xml", "application/json"],
method = [RequestMethod.POST])
produces = ["application/xml", "application/json"]
)
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

@@ -12,14 +12,7 @@ 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.web.bind.annotation.*
import org.springframework.validation.annotation.Validated
import org.springframework.web.context.request.NativeWebRequest
import org.springframework.beans.factory.annotation.Autowired
@@ -48,9 +41,9 @@ class UserApiController(@Autowired(required = true) val service: UserApiService)
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])
@PostMapping(
value = ["/user"]
)
fun createUser(@ApiParam(value = "Created user object" ,required=true ) @Valid @RequestBody body: User
): ResponseEntity<Unit> {
return ResponseEntity(service.createUser(body), HttpStatus.valueOf(200))
@@ -62,9 +55,9 @@ class UserApiController(@Autowired(required = true) val service: UserApiService)
notes = "")
@ApiResponses(
value = [ApiResponse(code = 200, message = "successful operation")])
@RequestMapping(
value = ["/user/createWithArray"],
method = [RequestMethod.POST])
@PostMapping(
value = ["/user/createWithArray"]
)
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))
@@ -76,9 +69,9 @@ class UserApiController(@Autowired(required = true) val service: UserApiService)
notes = "")
@ApiResponses(
value = [ApiResponse(code = 200, message = "successful operation")])
@RequestMapping(
value = ["/user/createWithList"],
method = [RequestMethod.POST])
@PostMapping(
value = ["/user/createWithList"]
)
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))
@@ -90,9 +83,9 @@ class UserApiController(@Autowired(required = true) val service: UserApiService)
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])
@DeleteMapping(
value = ["/user/{username}"]
)
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))
@@ -105,10 +98,10 @@ class UserApiController(@Autowired(required = true) val service: UserApiService)
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(
@GetMapping(
value = ["/user/{username}"],
produces = ["application/xml", "application/json"],
method = [RequestMethod.GET])
produces = ["application/xml", "application/json"]
)
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))
@@ -121,10 +114,10 @@ class UserApiController(@Autowired(required = true) val service: UserApiService)
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(
@GetMapping(
value = ["/user/login"],
produces = ["application/xml", "application/json"],
method = [RequestMethod.GET])
produces = ["application/xml", "application/json"]
)
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> {
@@ -137,9 +130,9 @@ class UserApiController(@Autowired(required = true) val service: UserApiService)
notes = "")
@ApiResponses(
value = [ApiResponse(code = 200, message = "successful operation")])
@RequestMapping(
value = ["/user/logout"],
method = [RequestMethod.GET])
@GetMapping(
value = ["/user/logout"]
)
fun logoutUser(): ResponseEntity<Unit> {
return ResponseEntity(service.logoutUser(), HttpStatus.valueOf(200))
}
@@ -150,9 +143,9 @@ class UserApiController(@Autowired(required = true) val service: UserApiService)
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])
@PutMapping(
value = ["/user/{username}"]
)
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> {