Search code examples
session-cookiesswagger-editor

Swagger editor and session cookies


According to this document, I could use:

components:
  securitySchemes:
    cookieAuth:
      type: apiKey
      in: cookie
      name: JSESSIONID

To define a session cookie. But if you go to the editor to change line 577 from in: "header" to in: "cookie", the editor blames with:

Schema error at securityDefinitions['api_key'].in should be equal to one of the allowed values allowedValues: header, query.

How must I define a session cookie based auth?


Solution

  • Cookie authentication is an OpenAPI 3.0 feature and is not supported in OpenAPI 2.0. Your spec is OpenAPI 2.0, as indicated by securityDefinitions. You can't mix 2.0 and 3.0 syntax. You'll need to rewrite or convert your spec to the OpenAPI 3.0 format.

    That said, cookie authentication is currently not supported in Swagger UI and Swagger Editor - but is supported in SwaggerHub.