Skip to content

Wrong "response" description with two controllers having its own ExceptionHandler #1845

Closed
@mlaffargue

Description

@mlaffargue

Describe the bug
I created two tests controllers, each one having an ExceptionHandler for ResponseStatus 500.

Calling them I've 2 different response depending on the controller called. So each @ExceptionHandler is correcly called for the corresponding controller.
However the documentation is only using 1 description for both Reponse.

To Reproduce

GET /example/500

@RestController
@RequestMapping("/example")
public class ExampleController {
  @ExceptionHandler(Exception.class)
  @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
  @ApiResponse(responseCode = "500", description = "ExceptionHandler in example")
  public String customControllerException() {
    return "example";
  }

  @GetMapping("/500")
  @Operation(
      tags = {"example"},
      summary = "Example method",
      description = "This method is an example"
  )
  public void test() {
    throw new RuntimeException();
  }

GET /example2/500

@RestController
@RequestMapping("/example2")
public class Example2Controller {
  @ExceptionHandler(Exception.class)
  @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
  @ApiResponse(responseCode = "500", description = "ExceptionHandler in example2")
  public String customControllerException() {
    return "example2";
  }

  @GetMapping("/500")
  @Operation(
      tags = "example2",
      summary = "Example2 method",
      description = "This method is an example2"
  )
  public void test() {
    throw new RuntimeException();
  }

Steps to reproduce the behavior:

  • What version of spring-boot you are using?
    • 2.6.11
  • What modules and versions of springdoc-openapi are you using?
    • springdoc-openapi-webmvc-core 1.6.11
  • What is the actual and the expected result using OpenAPI Description (yml or json)?

Actual:

       "/example/500": {
            "get": {
                ...
                "responses": {
                    "500": {
                        "description": "ExceptionHandler in example2",
                        "content": {
                ...
        "/example2/500": {
            "get": {
                ...
                "responses": {
                    "500": {
                        "description": "ExceptionHandler in example2",
                        "content": {

Expected:

       "/example/500": {
            "get": {
                ...
                "responses": {
                    "500": {
                        "description": "ExceptionHandler in example",
                        "content": {
                ...
        "/example2/500": {
            "get": {
                ...
                "responses": {
                    "500": {
                        "description": "ExceptionHandler in example2",
                        "content": {

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions