0

I am able to display the actuator endpoints in my API through this config:

springdoc:
  show-actuator: true

I am able to manage the http mappings of my /health endpoint with this config:

management:
  endpoint:
    health:
      status:
        http-mapping:
          down: 500
          fatal: 500
          out-of-service: 500

With this config, Open Api UI says the return codes of my /health endpoint is 200 and 404. I would like it to say 500 too.

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.3.1.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
        <dependency>
            <groupId>org.springdoc</groupId>
            <artifactId>springdoc-openapi-ui</artifactId>
            <version>1.5.3</version>
        </dependency>

1 Answers1

1

You can use OpenApiCustomiser: This sample add a 500 error for only your /health endpoint.

    @Bean
    public OpenApiCustomiser healthOpenApiCustomiser() {
        return openApi -> openApi.getPaths().entrySet().stream().filter(stringPathItemEntry ->  stringPathItemEntry.getKey().equals("/health"))
                    .forEach(stringPathItemEntry -> stringPathItemEntry.getValue().readOperations().forEach(operation -> {
                        ApiResponses apiResponses = operation.getResponses();

                        ApiResponse apiResponse = new ApiResponse().description("Custom Error")
                                .content(new Content()
                                        .addMediaType(org.springframework.http.MediaType.APPLICATION_JSON_VALUE, new MediaType()));
                        apiResponses.addApiResponse("500", apiResponse);
                    }));
    }
brianbro
  • 4,141
  • 2
  • 24
  • 37