【问题标题】:Setting Custom cookie and user-agent values in swagger在 swagger 中设置自定义 cookie 和用户代理值
【发布时间】:2018-11-17 01:32:07
【问题描述】:

我们将 swagger 用于 api 文档。

我在试用时遇到了问题。基本上,我们缩进从 swagger 调用的其余端点需要 Cookie(ex: cookie : token=xxxxx;) 和 User-Agent(User-Agent:custom values;) 参数。

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

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

对此有何建议?

【问题讨论】:

    标签: cookies swagger


    【解决方案1】:

    在他们的网站上展示:

    在 OpenAPI 3.0 术语中,cookie 身份验证是发送的 API 密钥 在:饼干。例如,通过名为 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 相同。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-05-06
      • 2011-08-13
      • 1970-01-01
      • 2011-04-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-27
      相关资源
      最近更新 更多