Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
mlaffargue opened this issue Sep 14, 2022 · 2 comments
Labels
bug Something isn't working

Comments

@mlaffargue
Copy link

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": {
@tristanradams
Copy link

We are seeing a similar issue, is there a workaround to not share these specific exceptionHandlers?

@mkopylec
Copy link

Any update here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants