使用相同代码的多个响应的PHP swagger注解

nbysray5  于 2022-11-06  发布在  PHP
关注(0)|答案(2)|浏览(168)

在我的一个控制器方法中我尝试放置这样的注解:


* @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":

我知道现在swagger里有一个oneOf,似乎正好适合我的用途,但是我不知道怎么用。

vsaztqbk

vsaztqbk1#


* @OA\Response(

     *          response=200,
     *          description="Successful operation",
     *          @OA\JsonContent(
     *              oneOf={
     *              @OA\Schema(ref="#/components/responses/schema1"),
     *              @OA\Schema(ref="#/components/responses/schema2"),
     *     }
     *          ),
     *),
of1yzvn4

of1yzvn42#

下面的代码解决了这个问题,希望对您有所帮助


* @OA\Response(

     *          response="404",
     *          description="Errors",
     *          @OA\JsonContent(
     *              @OA\Schema(type="string"),
     *              @OA\Examples(
     *                  example="string",
     *                  value="Account not exist",
     *                  summary="Account not exist."
     *              ),
     *              @OA\Examples(
     *                  example="string2",
     *                  value="User does not exist",
     *                  summary="User does not exist"
     *              ),
     *          )
     *      ),

相关问题