【问题标题】:PHP swagger annotation for multiple responses with the same code使用相同代码的多个响应的 PHP swagger 注释
【发布时间】:2020-02-06 17:05:13
【问题描述】:

在我的一种控制器方法中,我尝试添加这样的注释:

 *     @OA\Response(
 *         response="404",
 *         description="Invalid field"
 *     ),
 *     @OA\Response(
 *         response="404",
 *         description="Entity not found"
 *     )

但现在当我尝试构建文档时,我从 openapi 收到一条错误消息:

Warning: Multiple @OA\Response() with the same response="400":

我知道现在有一个oneOf 在招摇,这似乎正是我的目的。但是,我不知道如何使用它。

【问题讨论】:

  • 不,它没有。我需要知道,它应该如何以注释的形式呈现
  • 我有一个 POST 请求,可能会导致不同的响应,我不知道在这种情况下使用注释的正确方法。
  • 这个错误是有道理的,因为对于同一个错误代码,你不能有不同的响应正文定义。你需要为无效字段设置400,为找不到实体设置404。

标签: php swagger openapi


【解决方案1】:
     *@OA\Response(
     *          response=200,
     *          description="Successful operation",
     *          @OA\JsonContent(
     *              oneOf={
     *              @OA\Schema(ref="#/components/responses/schema1"),
     *              @OA\Schema(ref="#/components/responses/schema2"),
     *     }
     *          ),
     *),

【讨论】:

    猜你喜欢
    • 2023-03-21
    • 2020-11-17
    • 1970-01-01
    • 1970-01-01
    • 2012-05-29
    • 2020-11-25
    • 1970-01-01
    • 2016-05-15
    • 2018-05-06
    相关资源
    最近更新 更多