How do I add a cookie in flasgger for a flask restfull API

37 Views Asked by At
{
    "parameters": [

        {
            "name": "slug",
            "in": "query",
            "type": "string",
            "required": "true",
            "description": "Slug of the post where the comment will be added."
        },
        {
            "name": "body",
            "in": "body",
            "schema": {
                "type": "object",
                "properties": {
                    "title": {
                        "type": "string"
                    },
                    "body": {
                        "type": "string"
                    },
                    "rating": {
                        "type": "integer"
                    },
                    "media": {
                        "type": "string"
                    }
                }
            },
            "required": "true",
            "description": "JSON body containing comment data"
        },
        {
            "name": "cookie",
            "in": "cookie",
            "type": "string",
            "description": "Your custom cookie parameter here"
        }
    ],
    "responses": {
        201: {"description": "Comment added successfully"},
        400: {"description": "Bad Request"},
        404: {"description": "Post not found"},
        500: {"description": "Database error"},
    },
}

Screenshot

This is what my cookie for authentication looks like:

session=e7b02b79-f2b5-4927-9533-00871c630131; Path=/; HttpOnly; Expires=Fri, 10 Nov 2023 06:26:11 GMT;

This is an example with a valid request body:

Image

But for some reason when I execute it I get unauthorized error even though I provided the cookie in that field.

curl -X POST "http://127.0.0.1:5000/comment/add?slug=Orhei-Manstire-4" -H  "accept: application/json" -H  "Content-Type: application/json" -d "{  \"body\": \"string\",  \"media\": \"string\",  \"rating\": 0,  \"title\": \"string\"}"

It seems to me that it did not add the cookie to the request. My question is how do I add a cookie to the request in flasgger?

0

There are 0 best solutions below