Skip to content

default response is not overload #354

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

Closed
bisegni opened this issue Jan 20, 2020 · 4 comments
Closed

default response is not overload #354

bisegni opened this issue Jan 20, 2020 · 4 comments
Assignees
Labels
enhancement New feature or request

Comments

@bisegni
Copy link

bisegni commented Jan 20, 2020

In my code if I have method with the following annotation:

@Operation(summary = "Example api that realize an ECHO operation",
               description = "The result of the echo is the input value of the api",
               parameters = {@Parameter(in = ParameterIn.PATH,
                                        name = "uuid",
                                        required = true,
                                        description = "Is the identification of the document",
                                        schema = @Schema(type = "string",
                                                         example = "uuid"))},
               responses = {
                       @ApiResponse(description = "Successful Operation",
                                    responseCode = "200",
                                    content = @Content(mediaType = "application/json",
                                                       schema = @Schema(implementation = EchoResponse.class))),
                       @ApiResponse(responseCode = "201",
                                    description = "other possible response")
               }
    )

But when I get the json created I notice that the response code 200 is not defined as I wan't but I have always the "default response " and not what I have set with upper annotations...

@bnasslahsen
Copy link
Collaborator

Can you please add more details about your request :

  • What modules of springdoc-openapi are you using?
  • Provide with a sample code of HelloController to reproduce it?
  • What is the actual result using OpenAPI Description (yml or json)?
  • What is the expected result using OpenAPI Description (yml or json)?

Thank you in advance.

@bisegni
Copy link
Author

bisegni commented Jan 21, 2020

Hi, I have found the problem. IN my code i used a general handler to manage the exception output to client. I had added this class:

@ControllerAdvice
public class RestResponseEntityExceptionHandler 
  extends ResponseEntityExceptionHandler {
@ResponseStatus(value = HttpStatus.OK)
    @ExceptionHandler({ControllerLogicException.class})
    public ResponseEntity<ApiResultResponse<Object>> badRequest(HttpServletRequest req, Exception exception) {
        ApiResultResponse<Object> result = ((ControllerLogicException)exception).toApiResultResponse();
        log.error("{}-{}-{}",result.getErrorCode(), result.getErrorMessage(), result.getErrorDomain());
        return ResponseEntity.ok(result);
    }
}

Springdoc as default repose got the response type on the handler ApiResultResponse<Object>
I need to remove the advice class and mange all in another way. Before springbok I used spring fox and this issue neve happen, so I think that it is a bug. If in @Opeartion I put other result it are show well. Only the default one is effected.

I hope this can help

@bnasslahsen
Copy link
Collaborator

Hi @bisegni ,

An enhancement will be available on the next release v1.2.28 to handle this case.

@bisegni
Copy link
Author

bisegni commented Jan 21, 2020

thanks you

@bnasslahsen bnasslahsen added the enhancement New feature or request label Jan 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants