Swagger注释和OpenAPI v3.0中“Produces”的注释是什么?

问题描述 投票:2回答:1

在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上,我找不到如何在文档上注释产品,它说它现在是响应@OA\Response的一个属性,但我找不到一个例子我已经尝试过只放"content" = "application/json"但它没有'工作。

php swagger swagger-php
1个回答
3
投票

您可以为每个@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

© www.soinside.com 2019 - 2024. All rights reserved.