多个 cookie?"/>
如何使用 Swagger UI 在标头中发送多个 cookie?
我正在使用 OpenAPI 和 Swagger UI 在 Node 中编写文档和 API。 API 使用缓存中的 API 密钥进行身份验证。我在我的 OpenAPI 定义中配置了全局 cookie 身份验证。问题是它只发送一个带有请愿书的 cookie,而我需要发送三个。当我使用 Swagger UI 发送请求时,使用以下格式发送 cookie 标头:“cookie1=value;cookie2=value”。
我尝试创建三个全局安全方案,一个用于我需要发送的每个 cookie,我设法做到了,但是 Swagger UI 使用以下格式发送 cookie 标头:“cookie1=value&cookie2=value”并返回身份验证即使使用正确的值也会出错。
这是我swagger.json中的配置:
...
"components": {
"securitySchemes": {
"cookieAuth": {
"name": "user",
"type": "apiKey",
"in": "cookie"
}
}
},
"security": [
{
"cookieAuth": []
}
],
...
这是我尝试的第二种方法:
...
"components": {
"securitySchemes": {
"user": {
"name": "user",
"type": "apiKey",
"in": "cookie"
},
"password": {
"name": "user",
"type": "apiKey",
"in": "cookie"
},
"hashFunc": {
"name": "user",
"type": "apiKey",
"in": "cookie"
}
}
},
"security": [
{
"user": [],
"password": [],
"hashFunc": []
}
],
...
我真正需要的是知道如何配置它,以便 Swagger UI 以与浏览器相同的格式解释它。
回答如下:这是 Swagger UI 的一个已知问题:
https://github/swagger-api/swagger-ui/issues/4218
您可以尝试使用其他文档渲染器,看看它是否可以正确处理 cookie。
更多推荐
如何使用 Swagger UI 在标头中发送多个 cookie?
发布评论