0

我可以通过这个配置在我的 API 中显示执行器端点:

springdoc:
  show-actuator: true

我可以使用以下配置管理我的 /health 端点的 http 映射:

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

有了这个配置,Open Api UI 说我的 /health 端点的返回码是 200 和 404。我也希望它说 500。

    <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>
4

1 回答 1

0

您可以使用:此示例仅为您的端点OpenApiCustomiser添加 500 错误。/health

    @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);
                    }));
    }
于 2021-05-23T16:21:36.140 回答