all schemes MUST be satisfied for a request to be authorized using annotation

huangapple go评论58阅读模式
英文:

all schemes MUST be satisfied for a request to be authorized using annotation

问题

OpenAPI规范 states 中提到:

> 当在OpenAPI对象或操作对象上定义了安全需求对象列表时,只需满足列表中的一个安全需求对象即可授权请求。

提供的示例是:

security:    # A AND B

- A
  B

如何在Swagger Java注解中实现这一点?

我尝试过:

@SecurityRequirement(name = "A")
@SecurityRequirement(name = "B")

还有:

@SecurityRequirements(value = [SecurityRequirement(name = "A"), SecurityRequirement(name = "B")])

但它们都生成了:

security:    # A OR B

- A
- B
英文:

OpenAPI Specification states:

> When a list of Security Requirement Objects is defined on the OpenAPI Object or Operation Object, only one of the Security Requirement Objects in the list needs to be satisfied to authorize the request.

The example provided is:

security:    # A AND B

- A
  B

How to do this using Swagger Java annotations?

I tried

@SecurityRequirement(name = "A")
@SecurityRequirement(name = "B")

also

@SecurityRequirements(value = [SecurityRequirement(name = "A"),
SecurityRequirement(name = "B")] )

but both of them produce:

security:    # A OR B

- A
- B

答案1

得分: 2

It seems like there's no way to express that using Swagger Java annotations. Here are the related issues/enhancement requests on GitHub:

作为一种解决方法,您可以后处理生成的 OpenAPI 文件 (例如,使用工具如 yqjq) 并根据需要添加/修复 security 部分。

英文:

Looks like there's no way to express that using Swagger Java annotations. Here are the related issues / enhancement requests on GitHub:

As a workaround, you can post-process your generated OpenAPI file (e.g. using tools like yq or jq) and add/fix the security section as needed.

huangapple
  • 本文由 发表于 2023年4月6日 22:02:31
  • 转载请务必保留本文链接:https://go.coder-hub.com/75950415.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定