[kotlin-spring] Generate @Valid annotation on all RequestParts/Params for Multipart requests when useBeanValidation=true (#20864)

* [kotlin-spring] Generate @Valid annotation on all RequestParts/Params for Multipart requests when useBeanValidation=true

* [kotlin-spring] Fix failing test

The test was failing because of the newly added @Valid and an assert which is not correct anymore.
This commit is contained in:
Dimitar Tomov
2025-03-23 12:31:18 +02:00
committed by GitHub
parent 73b6b7084f
commit 08ec37cc10
16 changed files with 29 additions and 29 deletions

View File

@@ -156,7 +156,7 @@ class PetApiController(@Autowired(required = true) val service: PetApiService) {
value = ["/pet/{petId}"],
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? ): ResponseEntity<Unit> {
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") @Valid @RequestParam(value = "name", required = false) name: kotlin.String? ,@ApiParam(value = "Updated status of the pet") @Valid @RequestParam(value = "status", required = false) status: kotlin.String? ): ResponseEntity<Unit> {
return ResponseEntity(service.updatePetWithForm(petId, name, status), HttpStatus.valueOf(405))
}
@@ -175,7 +175,7 @@ class PetApiController(@Autowired(required = true) val service: PetApiService) {
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", required = false) file: org.springframework.web.multipart.MultipartFile?): ResponseEntity<ModelApiResponse> {
fun uploadFile(@ApiParam(value = "ID of pet to update", required = true) @PathVariable("petId") petId: kotlin.Long,@ApiParam(value = "Additional data to pass to server") @Valid @RequestParam(value = "additionalMetadata", required = false) additionalMetadata: kotlin.String? ,@ApiParam(value = "file detail") @Valid @RequestPart("file", required = false) file: org.springframework.web.multipart.MultipartFile?): ResponseEntity<ModelApiResponse> {
return ResponseEntity(service.uploadFile(petId, additionalMetadata, file), HttpStatus.valueOf(200))
}
}