【问题标题】:Spring boot Swagger annotation to link another end-point in swagger ui api docSpring boot Swagger 注释以链接 swagger ui api doc 中的另一个端点
【发布时间】:2022-08-17 05:33:26
【问题描述】:

我有一个使用 Spring Boot 构建的微服务项目,它公开了一个端点,即版本 1。

现在,我需要添加一个指向 v2 端点的链接并弃用 v1,因此在 Swagger UI 中,v1 将链接到弃用部分。

我使用 @Deprecate java 注释弃用了 version1,但不确定是否有一个注释可用于链接 version1 上的新端点,因此 Swagger UI api doc 将显示链接。

说,

# deprecated - refer the new end-point link
my-app/endpoint/v1


# new version of end-point
my-app/endpoint/v2

标签: spring-boot swagger


【解决方案1】:

这可能不是完美的答案,但最接近我的需要。

使用 V1 和 V2 时,最好使用@meridbt 建议的方法

  • 从 Openapi 文档来看,Links 服务器有不同的用途。如果现有端点正在使用另一个端点来获取信息,我们使用链接。

  • 对于我的场景,我在 @Operation 注释中使用了 Links 选项

@Operation(summary = "Wished hello", operationId = "requestMessage", responses = {
            @ApiResponse(responseCode = "200", description = "OK", links = {
                    @Link(name = "hello", operationId = "SayHello", parameters = {
                            @LinkParameter(name = "message", expression = "$request.query.message"),
                    })
            })
    })
    @Deprecated(since = "0.0.1", forRemoval = true)
    @GetMapping("/greet/{message}")
    public String getGreetings(@PathVariable String message) {
        return "hello World";
    }
    
    /**
     * Below is the new endpoint, which needs to be used
     */
    @GetMapping("/hello")
    public String getHello(String message) {
        return "Hello from the serever";
    }

【讨论】:

    猜你喜欢
    • 2019-10-26
    • 2019-03-13
    • 2023-01-04
    • 1970-01-01
    • 1970-01-01
    • 2019-01-22
    • 1970-01-01
    • 2016-08-25
    相关资源
    最近更新 更多