使用swagger-php中的控制器方法链接Swagger operationId

时间:2016-09-22 05:57:48

标签: php swagger swagger-php

您好我正在使用swagger-php规范创建一个虚拟api。我从github下载了swagger-php软件包。我还使用php Annotations创建了一个有效的json文件。现在我坚持将swagger json操作与控制器方法联系起来。

我的控制器文件是:

/**
 * @SWG\Get(
 *     path="/user",
 *     operationId = "findUser",
 *     description = "finds user in the system",
 *     tags={"user"},
 *     @SWG\Response(
 *         response=200,
 *         description="user response",
 *         @SWG\Schema(
 *             type="array",
 *             @SWG\Items(ref="#/definitions/User")
 *         )
 *     ),
 *     @SWG\Response(
 *         response="default",
 *         description="unexpected error",
 *         @SWG\Schema(
 *             ref="#/definitions/errorModel"
 *         )
 *     )
 * )
 */
public function findUser()
{
}

/**
 * @SWG\Get(
 *     path="/user/{id}",
 *     description="Returns a user based on a single ID",
 *     tags={"user"},
 *     operationId="findUserById",
 *     @SWG\Parameter(
 *         description="ID of pet to fetch",
 *         format="int64",
 *         in="path",
 *         name="id",
 *         required=true,
 *         type="integer"
 *     ),
 *     @SWG\Response(
 *         response=200,
 *         description="user response",
 *         @SWG\Schema(ref="#/definitions/User")
 *     ),
 *     @SWG\Response(
 *         response="default",
 *         description="unexpected error",
 *         @SWG\Schema(ref="#/definitions/errorModel")
 *     )
 * )
 */
public function findUserById()
{
}

/**
 * @SWG\Post(
 *     path="/user",
 *     operationId="addUser",
 *     tags={"user"},
 *     description="Add a new User ",
 *     @SWG\Parameter(
 *         name="id",
 *         in="formData",
 *         description="Unique id",
 *         required=true,
 *         type = "string"
 *     ),
 *    @SWG\Parameter(
 *         name="firstName",
 *         in="formData",
 *         description="first name",
 *         required=true,
 *         type = "string"
 *     ),
 *    @SWG\Parameter(
 *         name="lastName",
 *         in="formData",
 *         description="last name",
 *         required=true,
 *         type = "string"
 *     ),
 *    @SWG\Parameter(
 *         name="email",
 *         in="formData",
 *         description="email",
 *         required=true,
 *         type = "string"
 *     ),
 *   @SWG\Parameter(
 *         name="password",
 *         in="formData",
 *         description="password",
 *         required=true,
 *         type = "string",
 *         format = "password"
 *     ),
 *     @SWG\Response(
 *         response=200,
 *         description="user response",
 *         @SWG\Schema(ref="#/definitions/User")
 *     ),
 *     @SWG\Response(
 *         response="default",
 *         description="unexpected error",
 *         @SWG\Schema(ref="#/definitions/errorModel")
 *     )
 * )
 */
public function addUser()
{

}

/**
 * @SWG\Delete(
 *     path="/user/{id}",
 *     tags={"user"},
 *     description="deletes a single user based on the ID supplied",
 *     operationId="deleteUser",
 *     @SWG\Parameter(
 *         description="ID of user to delete",
 *         format="int64",
 *         in="path",
 *         name="id",
 *         required=true,
 *         type="integer"
 *     ),
 *     @SWG\Response(
 *         response=200,
 *         description="user deleted"
 *     ),
 *     @SWG\Response(
 *         response="default",
 *         description="unexpected error",
 *         @SWG\Schema(ref="#/definitions/errorModel")
 *     )
 * )
 */
public function deleteUser()
{
}

1 个答案:

答案 0 :(得分:0)

我使用了框架codeigniter,因为网址是 host / controller-name / method-name 。 因此,如果您的控制器名称是欢迎的,方法是helloWorld,那么在swagger文件中路径:/ welcome / helloWord host:localhost 。当点击尝试按钮时,请求网址将被点击 的本地主机/欢迎/ HELLOWORD