在swagger中设置自定义cookie和用户代理值

dev*_*per 5 cookies swagger

我们正在使用swagger进行api文档.

我正在尝试尝试问题.基本上我们缩进从swagger调用的其余端点需要Cookie(例如:cookie:token = xxxxx;)和User-Agent(User-Agent:自定义值;)参数.

但是当我尝试设置此参数时,Cookie不会作为请求的一部分发送.浏览器值正在覆盖User-Agent.我试过firefox和chrome两个.

我确实试过在线搜索,但没有找到合适的答案解决我的问题,有人建议设置useJQuery:true和withCredentials:true设置cookie,但没有工作正常.

有什么建议吗?

小智 0

正如他们的网站上所介绍的:

在 OpenAPI 3.0 术语中,cookie 身份验证是通过以下方式发送的 API 密钥:cookie。例如,通过名为 JSESSIONID 的 cookie 进行身份验证定义如下:

openapi: 3.0.0
...
# 1) Define the cookie name
components:
  securitySchemes:
    cookieAuth:         # arbitrary name for the security scheme; will be used in the "security" key later
      type: apiKey
      in: cookie
      name: JSESSIONID  # cookie name
Run Code Online (Sandbox Code Playgroud)

然后在端点级别:

paths:
     /users:
        get:
          security:
            - cookieAuth: []  # note the arbitrary name defined earlier
          description: Returns a list of users.
          responses: 
            '200':
              description: OK
Run Code Online (Sandbox Code Playgroud)

您可以swagger: "2.0"像这样定义 cookie 身份验证:

securityDefinitions:
  cookieAuth:
    type: apiKey
    name:
      Cookie # this is actually the Cookie header which will be sent by curl -H
    in: cookie
Run Code Online (Sandbox Code Playgroud)

在端点处引用它的方式与 OpenAPI 3 相同。