@Swagger \ Annotations \ Example“不存在错误

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

我正在使用带有PHP注释的Swagger v.2,现在我在请求体中面临一个小问题“示例”。

在我的控制器中它看起来像这样:

/**
     * @SWG\Post(
     *   tags={"pet"},
     *   path="/pet",
     *   summary="Create a pet",
     *   description="Create a pet",
     *   operationId="CreatePet",
     *   consumes={"application/json"},
     *   produces={"application/json"},
     *   @SWG\Parameter(
     *       name="pet",
     *           required=true,
     *           in="body",
     *           description="Pet object to be created",
     *       @SWG\Schema(
     *           @SWG\Property(property="pet",ref="#/definitions/Pet")
     *       ),
     *        @SWG\Example(
     *          ref="somepath/pet.json"
     *      )
     *   )

我需要有不同的Schema示例,具体取决于某些条件,这就是为什么我希望在单独的json文件中声明Schema示例,这将以这种方式引用。我从this link得到了这个想法。

但是,这不起作用,我得到The annotation "@Swagger\Annotations\Example" doesn't exist错误。如果有人知道应如何使用Annotations进行修复,那么任何帮助都将受到赞赏。

谢谢

php swagger swagger-2.0 swagger-php
1个回答
0
投票

你可以试试这个。

    /**
     * @SWG\Post(
     *   tags={"pet"},
     *   path="/pet",
     *   summary="Create a pet",
     *   description="Create a pet",
     *   operationId="CreatePet",
     *   consumes={"application/json"},
     *   produces={"application/json"},
     *   @SWG\Parameter(
     *       name="pet",
     *           required=true,
     *           in="body",
     *           description="Pet object to be created",
     *       @SWG\Schema(
     *           @SWG\Property(property="pet",ref="#/definitions/Pet")
     *       ),
     *        example={
     *            "data": {
     *            "api_token": "ffdca087b7f97117330824ceea948a99",
     *            "id": "1",
     *            "email": "[email protected]",
     *            "first_name": "Joe",
     *            "last_name": "Doe"
     *            }
     *        }
     *   )
© www.soinside.com 2019 - 2024. All rights reserved.