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

Response schema for overridden methods of ResponseEntityExceptionHandler is not generated #1208

Closed
Oguzhan1942 opened this issue Jul 6, 2021 · 5 comments
Labels
bug Something isn't working

Comments

@Oguzhan1942
Copy link

Oguzhan1942 commented Jul 6, 2021

Describe the feature
For generating documentation using @ResponseStatus on methods of my @ControllerAdvice class I have overridden a method named handleMethodArgumentNotValid of ResponseEntityExceptionHandler I expect the response code will be generated as it does for @ExceptionHandler methods.

To Reproduce
Steps to reproduce the behavior:

  • What version of spring-boot you are using?
    2.4.2
  • What modules and versions of springdoc-openapi are you using?
    org.springdoc:springdoc-openapi-kotlin:1.5.9
    org.springdoc:springdoc-openapi-ui:1.5.9
  • What is the actual and the expected result using OpenAPI Description (yml or json)?
    json
  • Provide with a sample code (HelloController) or Test that reproduces the problem
@ControllerAdvice
class CustomResponseEntityHandler : ResponseEntityExceptionHandler() {
  @org.springframework.web.bind.annotation.ResponseStatus(HttpStatus.BAD_REQUEST)
   override fun handleMethodArgumentNotValid(.....) : ResponseEntity<Any> -> **NO response code generated**

   @org.springframework.web.bind.annotation.ResponseStatus(HttpStatus.REQUEST_TIMEOUT)
   @ExceptionHandler(TransactionTimedOutException::class)
    fun handleTransactionTimeout(....): ResponseEntity<ResponseStatus> -> **Response code generated**

Expected behavior

  • A clear and concise description of what you expected to happen.
    At least a response code json object 400 Bad Request generated in my api.json file as following.
 "400": {
            "description": "Bad Request",
            "content": {
              "*/*": {
                "schema": {
                  "$ref": "#/components/schemas/ResponseStatus"
                }
              }
            }
          },

If this is not the way it suppose to work, I appreciate any kind of help.

Thanks & Best Regards,
Oguzhan

@bnasslahsen
Copy link
Contributor

@Oguzhan1942,

Not reproducible.
This is the link to a sample working test using @ExceptionHandler.

If you are still having any issue, make sure you provide a complete reproducible sample test...

@fermentfan
Copy link

I think this issue needs to be reopened. I face the same issue as the OP & I think you misunderstood the situation @bnasslahsen.

@Oguzhan1942 doesn't use @ExceptionHandler, because it's not supported for MethodArgumentNotValidException.class. This is due to the fact that spring-boot comes with an ExceptionHandler for this exception by default and if you add the @ExceptionHandler, the application doesn't start. To circumvent this, you need to override the function handleMethodArgumentNotValid, but then the issue stands as described above and it won't end up in the openAPI.

@bnasslahsen
Copy link
Contributor

@dennisvonderbey,

I think that without providing an accurate description, it's just not productive to guess the intent of any comment.
Please make sure, you respect the contribution guide: There is a guidance, on how to report bugs.

If the relevant information are provided, the ticket can be reopened.

@fermentfan
Copy link

I mean OP already put the exact example in the initial post, but I will try to push a complete project this week.

@fermentfan
Copy link

Ok I had some time:

https://github.com/DennisVonDerBey/springdoc-example-issue-1208

The openAPI.json shows the output. As you can see the error description for the 400 BAD REQUEST is missing.

@bnasslahsen bnasslahsen reopened this Sep 12, 2021
@bnasslahsen bnasslahsen added the bug Something isn't working label Jan 10, 2022
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

3 participants