Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Include cookie in swagger doc requests

My web service API will check whether a certain cookie is included in the requests, but I couldn't figure out how to include a cookie to my swagger doc api calls.

I've tried two approaches:

  1. Adding cookie as a editable field like this in my .yaml file.

    paths:
      /myApi/create:
        parameters:
          - name: Cookie
            in: header
            description: cookie
            required: true
            type: string
    
  2. In the html file of swagger ui, add

    window.authorizations.add(
        "Cookie",
        new ApiKeyAuthorization("Cookie", 'Name=Val', 'header')
    )
    

But in both of the approach my api doesn't get the cookie, I was wondering how I can do this? Thanks!

like image 506
Li-Fan Yu Avatar asked Aug 16 '16 21:08

Li-Fan Yu


1 Answers

Maybe it is too late, but you should check the following example:

swagger: '2.0'
info:
  version: '1'
  title: With Cookie Authentication
  description: With Cookie Authentication

securityDefinitions:
  myCookie:
    type: apiKey
    name: Cookie
    in: header
paths: 
  /say-hi:
    get:
      summary: Say Hello
      description: Say Hello
      responses:
        200:
          description: OK
      security:
        - myCookie: []
like image 107
jgato Avatar answered Sep 18 '22 13:09

jgato