英文:
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"
* )
* )
*/
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论