如何在PHP中使用Swagger/OpenAPI注解来描述Cookie?

huangapple go评论62阅读模式
英文:

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?

英文:

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?

答案1

得分: 1

根据OpenAPI文档,当您想描述响应中发送的cookie时,应通过Set-Cookie头来描述它。

您可以像这样使用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"
 *            )
 *        )
 *    )
 * )
英文:

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"
     *            )
     *        )
     *    )
     * )
     */

答案2

得分: 0

You should move the @OA\Cookie annotation to the top level of your documentation block.

英文:

You should move the @OA\Cookie annotation to the top level of your documentation block.

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

huangapple
  • 本文由 发表于 2023年5月14日 23:38:17
  • 转载请务必保留本文链接:https://go.coder-hub.com/76248322.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定