(Swagger 3) @Parameter 添加授权标头
我不确定这是一个错误还是我遗漏了一些东西,但 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
仔细阅读文档
注意:不允许名为 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..