如何使用 Springdoc 从 OpenAPI 文档中隐藏端点 [英] How to hide endpoints from OpenAPI documentation with Springdoc

查看:145
本文介绍了如何使用 Springdoc 从 OpenAPI 文档中隐藏端点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Springdoc 自动为所有处理程序方法生成 API 文档.即使没有 OpenAPI 注释.

Springdoc automatically generates a API documentation for all handler methods. Even if there are no OpenAPI annotations.

如何在 API 文档中隐藏端点?

How can I hide endpoints from the API documentation?

推荐答案

@io.swagger.v3.oas.annotations.Hidden 注释可用于控制器的方法或类级别隐藏一个或所有端点.

The @io.swagger.v3.oas.annotations.Hidden annotation can be used at the method or class level of a controller to hide one or all endpoints.

(参见:https://springdoc.org/faq.html#how-can-i-hide-an-operation-or-a-controller-from-documentation)

示例:

@Hidden // Hide all endpoints
@RestController
@RequestMapping(path = "/test")
public class TestController {

    private String test = "Test";

    @Operation(summary = "Get test string", description = "Returns a test string", tags = { "test" })
    @ApiResponses(value = { @ApiResponse(responseCode = "200", description = "Success" ) })
    @GetMapping(value = "", produces = MediaType.TEXT_PLAIN_VALUE)
    public @ResponseBody String getTest() {
        return test;
    }

    @Hidden // Hide this endpoint
    @PutMapping(value = "", consumes = MediaType.TEXT_PLAIN_VALUE)
    @ResponseStatus(HttpStatus.OK)
    public void setTest(@RequestBody String test) {
        this.test = test;
    }

}

也可以只为特定包的控制器生成 API 文档.

Its also possible to generate the API documentation only for controllers of specific packages.

将以下内容添加到您的 application.properties 文件中:

Add following to your application.properties file:

springdoc.packagesToScan=package1, package2

(参见:https://springdoc.org/faq.html#how-can-i-explicitly-set-which-packages-to-scan)

这篇关于如何使用 Springdoc 从 OpenAPI 文档中隐藏端点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆