|
| 1 | +package org.openapitools.api |
| 2 | + |
| 3 | +import org.openapitools.model.ModelApiResponse |
| 4 | +import org.openapitools.model.Pet |
| 5 | +import org.springframework.http.HttpStatus |
| 6 | +import org.springframework.http.MediaType |
| 7 | +import org.springframework.http.ResponseEntity |
| 8 | + |
| 9 | +import org.springframework.web.bind.annotation.* |
| 10 | +import org.springframework.validation.annotation.Validated |
| 11 | +import org.springframework.web.context.request.NativeWebRequest |
| 12 | +import org.springframework.beans.factory.annotation.Autowired |
| 13 | + |
| 14 | +import jakarta.validation.Valid |
| 15 | +import jakarta.validation.constraints.DecimalMax |
| 16 | +import jakarta.validation.constraints.DecimalMin |
| 17 | +import jakarta.validation.constraints.Email |
| 18 | +import jakarta.validation.constraints.Max |
| 19 | +import jakarta.validation.constraints.Min |
| 20 | +import jakarta.validation.constraints.NotNull |
| 21 | +import jakarta.validation.constraints.Pattern |
| 22 | +import jakarta.validation.constraints.Size |
| 23 | + |
| 24 | +import kotlin.collections.List |
| 25 | +import kotlin.collections.Map |
| 26 | + |
| 27 | +@RestController |
| 28 | +@Validated |
| 29 | +class PetApiController(@Autowired(required = true) val service: PetApiService) { |
| 30 | + |
| 31 | + |
| 32 | + @RequestMapping( |
| 33 | + method = [RequestMethod.POST], |
| 34 | + // "/pet" |
| 35 | + value = [PATH_ADD_PET], |
| 36 | + produces = ["application/xml", "application/json"], |
| 37 | + consumes = ["application/json", "application/xml"] |
| 38 | + ) |
| 39 | + fun addPet( |
| 40 | + @Valid @RequestBody pet: Pet |
| 41 | + ): ResponseEntity<Pet> { |
| 42 | + return ResponseEntity(service.addPet(pet), HttpStatus.valueOf(200)) |
| 43 | + } |
| 44 | + |
| 45 | + |
| 46 | + @RequestMapping( |
| 47 | + method = [RequestMethod.DELETE], |
| 48 | + // "/pet/{petId}" |
| 49 | + value = [PATH_DELETE_PET] |
| 50 | + ) |
| 51 | + fun deletePet( |
| 52 | + @PathVariable("petId") petId: kotlin.Long, |
| 53 | + @RequestHeader(value = "api_key", required = false) apiKey: kotlin.String? |
| 54 | + ): ResponseEntity<Unit> { |
| 55 | + return ResponseEntity(service.deletePet(petId, apiKey), HttpStatus.valueOf(400)) |
| 56 | + } |
| 57 | + |
| 58 | + |
| 59 | + @RequestMapping( |
| 60 | + method = [RequestMethod.GET], |
| 61 | + // "/pet/findByStatus" |
| 62 | + value = [PATH_FIND_PETS_BY_STATUS], |
| 63 | + produces = ["application/xml", "application/json"] |
| 64 | + ) |
| 65 | + fun findPetsByStatus( |
| 66 | + @NotNull @Valid @RequestParam(value = "status", required = true) status: kotlin.collections.List<kotlin.String> |
| 67 | + ): ResponseEntity<List<Pet>> { |
| 68 | + return ResponseEntity(service.findPetsByStatus(status), HttpStatus.valueOf(200)) |
| 69 | + } |
| 70 | + |
| 71 | + |
| 72 | + @Deprecated(message="Operation is deprecated") |
| 73 | + @RequestMapping( |
| 74 | + method = [RequestMethod.GET], |
| 75 | + // "/pet/findByTags" |
| 76 | + value = [PATH_FIND_PETS_BY_TAGS], |
| 77 | + produces = ["application/xml", "application/json"] |
| 78 | + ) |
| 79 | + fun findPetsByTags( |
| 80 | + @NotNull @Valid @RequestParam(value = "tags", required = true) tags: kotlin.collections.List<kotlin.String> |
| 81 | + ): ResponseEntity<List<Pet>> { |
| 82 | + return ResponseEntity(service.findPetsByTags(tags), HttpStatus.valueOf(200)) |
| 83 | + } |
| 84 | + |
| 85 | + |
| 86 | + @RequestMapping( |
| 87 | + method = [RequestMethod.GET], |
| 88 | + // "/pet/{petId}" |
| 89 | + value = [PATH_GET_PET_BY_ID], |
| 90 | + produces = ["application/xml", "application/json"] |
| 91 | + ) |
| 92 | + fun getPetById( |
| 93 | + @PathVariable("petId") petId: kotlin.Long |
| 94 | + ): ResponseEntity<Pet> { |
| 95 | + return ResponseEntity(service.getPetById(petId), HttpStatus.valueOf(200)) |
| 96 | + } |
| 97 | + |
| 98 | + |
| 99 | + @RequestMapping( |
| 100 | + method = [RequestMethod.PUT], |
| 101 | + // "/pet" |
| 102 | + value = [PATH_UPDATE_PET], |
| 103 | + produces = ["application/xml", "application/json"], |
| 104 | + consumes = ["application/json", "application/xml"] |
| 105 | + ) |
| 106 | + fun updatePet( |
| 107 | + @Valid @RequestBody pet: Pet |
| 108 | + ): ResponseEntity<Pet> { |
| 109 | + return ResponseEntity(service.updatePet(pet), HttpStatus.valueOf(200)) |
| 110 | + } |
| 111 | + |
| 112 | + |
| 113 | + @RequestMapping( |
| 114 | + method = [RequestMethod.POST], |
| 115 | + // "/pet/{petId}" |
| 116 | + value = [PATH_UPDATE_PET_WITH_FORM], |
| 117 | + consumes = ["application/x-www-form-urlencoded"] |
| 118 | + ) |
| 119 | + fun updatePetWithForm( |
| 120 | + @PathVariable("petId") petId: kotlin.Long, |
| 121 | + @Valid @RequestParam(value = "name", required = false) name: kotlin.String?, |
| 122 | + @Valid @RequestParam(value = "status", required = false) status: kotlin.String? |
| 123 | + ): ResponseEntity<Unit> { |
| 124 | + return ResponseEntity(service.updatePetWithForm(petId, name, status), HttpStatus.valueOf(405)) |
| 125 | + } |
| 126 | + |
| 127 | + |
| 128 | + @RequestMapping( |
| 129 | + method = [RequestMethod.POST], |
| 130 | + // "/pet/{petId}/uploadImage" |
| 131 | + value = [PATH_UPLOAD_FILE], |
| 132 | + produces = ["application/json"], |
| 133 | + consumes = ["multipart/form-data"] |
| 134 | + ) |
| 135 | + fun uploadFile( |
| 136 | + @PathVariable("petId") petId: kotlin.Long, |
| 137 | + @Valid @RequestParam(value = "additionalMetadata", required = false) additionalMetadata: kotlin.String?, |
| 138 | + @Valid @RequestPart("file", required = false) file: org.springframework.web.multipart.MultipartFile |
| 139 | + ): ResponseEntity<ModelApiResponse> { |
| 140 | + return ResponseEntity(service.uploadFile(petId, additionalMetadata, file), HttpStatus.valueOf(200)) |
| 141 | + } |
| 142 | + |
| 143 | + companion object { |
| 144 | + //for your own safety never directly reuse these path definitions in tests |
| 145 | + const val PATH_ADD_PET: String = "/pet" |
| 146 | + const val PATH_DELETE_PET: String = "/pet/{petId}" |
| 147 | + const val PATH_FIND_PETS_BY_STATUS: String = "/pet/findByStatus" |
| 148 | + const val PATH_FIND_PETS_BY_TAGS: String = "/pet/findByTags" |
| 149 | + const val PATH_GET_PET_BY_ID: String = "/pet/{petId}" |
| 150 | + const val PATH_UPDATE_PET: String = "/pet" |
| 151 | + const val PATH_UPDATE_PET_WITH_FORM: String = "/pet/{petId}" |
| 152 | + const val PATH_UPLOAD_FILE: String = "/pet/{petId}/uploadImage" |
| 153 | + } |
| 154 | +} |
0 commit comments