dongqiancui9194 2016-09-22 05:57
浏览 160
已采纳

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

Hi i am creating a dummy api using swagger-php specifications. i have downloaded the swagger-php package from github. Also i have created a valid json file using php Annotations. Now i am stuck with linking the swagger json operations with controller methods .

My controller file is:

/**
 * @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条回答 默认 最新

  • dsjbest2015 2016-10-18 08:10
    关注

    I have used the framework codeigniter and for that the url is host/controller-name/method-name. So if your controller-name is welcome and method is helloWorld then in swagger file the path: /welcome/helloWord and host:localhost. When try it button is clicked the request url will be localhost/welcome/helloWord.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?