在swagger

时间:2015-10-04 09:55:28

标签: cookies swagger

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

我在试用时面临一个问题。基本上我们缩进从swagger调用的其余端点需要 Cookie(例如:cookie:token = xxxxx;)和User-Agent(用户代理:自定义值;)参数。

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

我确实尝试过在线搜索,但找不到合适的答案来解决我的问题,有建议设置 useJQuery:true和withCredentials:如果设置了cookie,则为true,但不能正常工作。

对此有何建议?

1 个答案:

答案 0 :(得分: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

然后在端点级别:

paths:
     /users:
        get:
          security:
            - cookieAuth: []  # note the arbitrary name defined earlier
          description: Returns a list of users.
          responses: 
            '200':
              description: OK

对于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

在端点上引用它的方法与OpenAPI 3相同。

相关问题