如何使用 Swagger UI 在标头中发送多个 cookie?

编程入门 行业动态 更新时间:2024-10-10 15:23:32

如何使用 Swagger UI 在标头中发送<a href=https://www.elefans.com/category/jswz/34/1771377.html style=多个 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?

本文发布于:2024-05-13 14:26:49,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1759668.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:多个   如何使用   Swagger   UI   标头中

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!