openapiswagger-php

How to use Swagger/OpenAPI annotations in PHP to describe a Cookie?


When using the block below to generate swagger documentation:

/**
 * @OA\Get(
 *     path="/api/users",
 *     summary="...",
 *     @OA\Response(
 *         response="200",
 *         description="...",
 *         @OA\Cookie(
 *             name="my_cookie",
 *             description="...",
 *             @OA\Schema(
 *                 type="string"
 *             )
 *         )
 *     )
 * )
 */

I get an error message similar to:

[Syntax Error] Expected Doctrine\Common\Annotations\DocLexer::T_CLOSE_PARENTHESIS, got '@' in...

What could be wrong?


Solution

  • According to the OpenAPI documentation, when you want to describe the cookie sent with the response, you should describe it through the Set-Cookie header.

    You could then implement it like this with OA Annotations :

        /**
         * @OA\Get(
         *     path="/api/users",
         *     summary="...",
         *     @OA\Response(
         *        response="200",
         *        description="...",
         *        @OA\Header(
         *            header="Set-Cookie",
         *            @OA\Schema(
         *                  type="string",
         *                  example="Some value"
         *            )
         *        )
         *    )
         * )
         */