Spring Boot Swagger注解链接到swagger ui api doc中的另一个端点

h22fl7wq  于 2022-11-06  发布在  Spring
关注(0)|答案(1)|浏览(280)

我有一个使用spring Boot 构建的微服务项目,它公开了一个端点,即版本1。
现在,我需要添加一个指向v2端点的链接,并弃用v1,因此在Swagger UI中,v1将链接到弃用部分。
我使用@Deprecate java注解反对版本1,但不确定是否有注解可用于链接版本1上的新端点,以便Swagger UI api文档显示该链接。
我说,

  1. # deprecated - refer the new end-point link
  2. my-app/endpoint/v1
  3. # new version of end-point
  4. my-app/endpoint/v2
7tofc5zh

7tofc5zh1#

这可能不是完美的答案,但最接近我所需要的。
当使用V1和V2时,最好使用@meridbt建议的方法

  • 在Openapi文档中,链接服务器有不同的用途。如果现有的端点使用另一个端点来获取信息,我们使用链接。
  • 在我的场景中,我使用了@Operation标注中的Links选项
  1. @Operation(summary = "Wished hello", operationId = "requestMessage", responses = {
  2. @ApiResponse(responseCode = "200", description = "OK", links = {
  3. @Link(name = "hello", operationId = "SayHello", parameters = {
  4. @LinkParameter(name = "message", expression = "$request.query.message"),
  5. })
  6. })
  7. })
  8. @Deprecated(since = "0.0.1", forRemoval = true)
  9. @GetMapping("/greet/{message}")
  10. public String getGreetings(@PathVariable String message) {
  11. return "hello World";
  12. }
  13. /**
  14. * Below is the new endpoint, which needs to be used
  15. */
  16. @GetMapping("/hello")
  17. public String getHello(String message) {
  18. return "Hello from the serever";
  19. }

展开查看全部

相关问题