Closed
Description
Describe the bug
Exception handlers annotated with @ApiResponse
and @ResponseStatus
seem to be applied to all operations, even if the implementing operation method handler does not throw the exception handled by the exception handler.
To Reproduce
Steps to reproduce the behavior:
- spring-boot: 3.2.1
org.springdoc:springdoc-openapi-starter-webmvc-ui:2.3.0
- What is the actual and the expected result using OpenAPI Description (yml or json)?
- Provide with a sample code (HelloController) or Test that reproduces the problem
data class HelloResponse(val value: String)
@RestController
class HelloController {
@GetMapping("/hello")
@Operation(operationId = "hello", summary = "Hello, World!")
fun hello() = HelloResponse("World")
@GetMapping("/greet/{name}")
@Operation(operation = "greet", summary = "Hello someone!")
@Throws(InvalidNameException::class)
fun greet(@PathVariable name: String) = throw InvalidNameException("Name '$name' is invalid!")
}
@ControllerAdvice
class HelloAdvisor {
@ExceptionHandler(InvalidNameException::class)
@ResponseStatus(HttpStatus.BAD_REQUEST)
@ApiResponse(description = "The provided name is invalid", useReturnScheme = true)
fun handleNameException(e: InvalidNameException): MyErrorResponse {
TODO()
}
}
Expected behavior
I would expect only the greeting operation to be documented with the invalid name exception, but the hello exception is also documented with it.
Metadata
Metadata
Assignees
Labels
No labels