(Swagger 3) @Parameter 添加授权标头

发布于 2025-01-15 04:04:28 字数 883 浏览 0 评论 0原文

我不确定这是一个错误还是我遗漏了一些东西,但 Swagger 在执行请求时没有添加“Authorization: ..”标头

我有这个未经身份验证的端点

public String getUserFromAuth(
            @Parameter(description = "Bearer token", required = true, name = "Authorization", in = ParameterIn.HEADER) @HeaderParam("Authorization") String authHeader
    ) {...}

在 Swagger 上执行此请求时,标头不是额外。

但是,如果我将 name = "Authorization" 更改为 `name = "Authorization2",那么在这种情况下,会添加 Authorization2 标头。

swagger json 配置看起来不错:

"parameters": [
          {
            "name": "Authorization",
            "in": "header",
            "description": "Bearer token",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],

为了简化问题,我已经删除了所有 security 配置,这样就不会有混淆

Swagger-core:2.1.13 Swgger-ui:4.5.0

I'm not sure if this is a bug or I'm missing something but Swagger is not adding the "Authorization: .." header when executing a request

I have this un-authenticated endpoint

public String getUserFromAuth(
            @Parameter(description = "Bearer token", required = true, name = "Authorization", in = ParameterIn.HEADER) @HeaderParam("Authorization") String authHeader
    ) {...}

When executing this request on Swagger the header is not added.

However if I change name = "Authorization" to `name = "Authorization2" then in that case yes the Authorization2 header is added.

the swagger json config looks fine:

"parameters": [
          {
            "name": "Authorization",
            "in": "header",
            "description": "Bearer token",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],

To simplify the issue I have removed all together the security config so there is no confusion

Swagger-core: 2.1.13
Swgger-ui: 4.5.0

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

も让我眼熟你 2025-01-22 04:04:28

仔细阅读文档

注意:不允许名为 Accept、Content-Type 和 Authorization 的标头参数。要描述这些标头,请使用相应的 OpenAPI 关键字:

https://swagger。 io/docs/specification/describing-parameters/#header-parameters

这对我来说没有意义,但好吧..

Reading a little more carefully the doc

Note: Header parameters named Accept, Content-Type and Authorization are not allowed. To describe these headers, use the corresponding OpenAPI keywords:

https://swagger.io/docs/specification/describing-parameters/#header-parameters

This doesn't make sense to me but well..

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文