Swagger 注释和 OpenAPI v3.0 中 "Produces" 的注释是什么?
What's the annotation for "Produces" in Swagger annotations and OpenAPI v3.0?
在 OpenAPI v2.0 和 Swagger PHP 上,Produces 的注释是:
/**
* @SWG\Get(
* path="/posts",
* operationId="getPosts",
* tags={"Authentication"},
* produces="application/json"
* summary="Returns the posts",
* description="Returns the posts",
* @SWG\Response(
* response=200,
* description="Successful operation"
* ),
* )
*/
但是在 OpenAPI v3.0 和 Swagger PHP 上,我找不到关于如何注释 produces 的文档,它声明它现在是响应 @OA\Response
但我找不到示例 我已经尝试只输入 "content" = "application/json"
但它不起作用。
您为每个 @OA\Response
.
定义所有可能的响应内容类型
例如:
* @OA\Response(
* response=200,
* description="successful operation",
* @OA\JsonContent(
* type="array",
* @OA\Items(ref="#/components/schemas/Pet")
* ),
* @OA\XmlContent(
* type="array",
* @OA\Items(ref="#/components/schemas/Pet")
* )
* ),
如果您的端点仅生成 JSON 内容,则仅定义 @OA\JsonContent
的条目。
查看完整示例 here。
在 OpenAPI v2.0 和 Swagger PHP 上,Produces 的注释是:
/**
* @SWG\Get(
* path="/posts",
* operationId="getPosts",
* tags={"Authentication"},
* produces="application/json"
* summary="Returns the posts",
* description="Returns the posts",
* @SWG\Response(
* response=200,
* description="Successful operation"
* ),
* )
*/
但是在 OpenAPI v3.0 和 Swagger PHP 上,我找不到关于如何注释 produces 的文档,它声明它现在是响应 @OA\Response
但我找不到示例 我已经尝试只输入 "content" = "application/json"
但它不起作用。
您为每个 @OA\Response
.
例如:
* @OA\Response(
* response=200,
* description="successful operation",
* @OA\JsonContent(
* type="array",
* @OA\Items(ref="#/components/schemas/Pet")
* ),
* @OA\XmlContent(
* type="array",
* @OA\Items(ref="#/components/schemas/Pet")
* )
* ),
如果您的端点仅生成 JSON 内容,则仅定义 @OA\JsonContent
的条目。
查看完整示例 here。