php - Swagger注释和OpenAPI v3.0中 "Produces"的注释是什么?

标签 php swagger swagger-php

在 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" 但它不起作用。

最佳答案

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

关于php - Swagger注释和OpenAPI v3.0中 "Produces"的注释是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55345666/

相关文章:

php - 使用文本/字符串值在 Sphinx 中创建过滤器

Swagger:在响应对象中使用特定值

api - Swagger 集成到 Dropwizard 中

swagger - 如何让 Swagger UI 使用我的标题?

php - 如何在 PayPal 工作时保留 JavaScript 变量?

php - Heroku : FFMpeg installed but php worker can't find it

php - 如何将 HTTP 身份验证添加到基于 PHP 的 Heroku 应用程序?

java - 将 Jackson 注释添加到 swagger 生成的类

php - Swagger 的 laravel 护照不起作用