Skip to content

Openapi generator: Central defintion of error response description and content #44113

Answered by MikeEdgar
PhilippKemkes asked this question in Q&A
Discussion options

You must be logged in to vote

@PhilippKemkes you can use the @OpenAPIDefinition annotation, which has a components.responses array to define your @APIResponses. @OpenAPIDefinition should be placed in a package-info.java or on a JAX-RS Application class in order to be found by the scanner. Each @APIResponse should have a name that will be its key within components in the resulting OpenAPI.

@OpenAPIDefinition(
  components = @Components(
    responses = {
      @APIResponse(
        name = "BadRequest",
        description = "a description",
        content = @Content(mediaType = MediaType.APPLICATION_JSON, schema = @Schema(implementation = ErrorMessage.class))),
      @APIResponse(
        name = "Unauthorized", 
        

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@phillip-kruger
Comment options

Answer selected by PhilippKemkes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment