0

I have a problem with a springdoc-openapi and swagger. In api.yml file I defined some responses for endpoint, for example:

responses:
  200:
     desription: example response
     content:
     ......
  404:
     description: example response 

And before that the behavior was expected to me. In swagger I saw an example value for 200 and I didn't see an example value for 404, only description. When I started to use springdoc-openapi, when I didn't provided content for example for 404, the content from 200 is applied to 404. Is there a option how to hide it? For example in api.yml or any config property?

I tried to search config properties but I din't find anything. Moreover I tried with content: {} but It didn't work too.

jqakubx
  • 1
  • 1

1 Answers1

0

It is be possible to handle as return an empty content as response using, one of the following syntaxes:

  • content = @Content
  • content = @Content(schema = @Schema(hidden = true))

For example:

  @GetMapping
  @ApiResponses(value = {
    @ApiResponse(responseCode = "200", description = "example response"),
    @ApiResponse(responseCode = "404", description = "example response", content = @Content)
  })
  public String index() {
    return "Hello";
  }

For RestControllerAdvice

  @ResponseStatus(HttpStatus.NOT_FOUND)
  @ExceptionHandler({ RuntimeException.class })
  @ApiResponse(responseCode = "404", description = "example response", content = @Content)
  @ResponseBody
  public String handleError() {
    return "NotFound";
  }

Please see: https://springdoc.org/#how-can-i-return-an-empty-content-as-response

YutaSaito
  • 387
  • 6