0

我正在使用带有 PHP Annotations 的 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 示例说明。我从这个链接得到了这个想法。

但是,这不起作用,我得到The annotation "@Swagger\Annotations\Example" doesn't exist错误。如果有人知道应该如何使用注释修复它,我们将不胜感激。

谢谢

4

1 回答 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": "joe@doe.com",
     *            "first_name": "Joe",
     *            "last_name": "Doe"
     *            }
     *        }
     *   )
于 2018-03-03T06:07:59.677 回答