swagger-ui 你如何隐藏未实现的休息方法
swagger-ui How do you hide rest methods not implemented
也许我只是想念它,我想从控制器中隐藏一些没有实现它们的 rest 方法,比如选项、删除、head
这个有注释吗?我在文档中找不到它
使用 https://github.com/nelmio/NelmioApiDocBundle v3
当前,当我查看 /api/doc 我添加的任何控制器时,即使我只实现了 GET 方法,也会列出所有剩余方法。
<?php
namespace ApiBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\HttpFoundation\JsonResponse;
use Swagger\Annotations as SWG;
class UserController extends Controller
{
/**
* @Security("is_granted('IS_AUTHENTICATED_FULLY')")
* @Route("/api/users", name="get_users", methods={"GET"})
*
* @SWG\Response(
* response=200,
* description="Returns all users"
* )
* @SWG\Tag(name="users")
*
*
* @return \Symfony\Component\HttpFoundation\JsonResponse
*/
public function getUsersAction()
{
$repo = $this->getDoctrine()
->getRepository('AccountBundle:User');
$users = $repo->createQueryBuilder('q')
->getQuery()
->getArrayResult();
return new JsonResponse($users);
}
}
刚刚发现,如果您没有在@Route() 注释中指定控制器中的方法,那么它会显示所有方法,但如果您添加 methods={} 到 Route 注释然后它只会列出定义的方法
* @Route("/api/users", name="get_users", methods={"GET"})
指定 @Value 和 @method 输入 @RequestMapping
@RequestMapping(value="/instances/all",method=RequestMethod.GET)
@JsonFormat
public String showInstances(){
return "instances";
}
也许我只是想念它,我想从控制器中隐藏一些没有实现它们的 rest 方法,比如选项、删除、head
这个有注释吗?我在文档中找不到它 使用 https://github.com/nelmio/NelmioApiDocBundle v3
当前,当我查看 /api/doc 我添加的任何控制器时,即使我只实现了 GET 方法,也会列出所有剩余方法。
<?php
namespace ApiBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\HttpFoundation\JsonResponse;
use Swagger\Annotations as SWG;
class UserController extends Controller
{
/**
* @Security("is_granted('IS_AUTHENTICATED_FULLY')")
* @Route("/api/users", name="get_users", methods={"GET"})
*
* @SWG\Response(
* response=200,
* description="Returns all users"
* )
* @SWG\Tag(name="users")
*
*
* @return \Symfony\Component\HttpFoundation\JsonResponse
*/
public function getUsersAction()
{
$repo = $this->getDoctrine()
->getRepository('AccountBundle:User');
$users = $repo->createQueryBuilder('q')
->getQuery()
->getArrayResult();
return new JsonResponse($users);
}
}
刚刚发现,如果您没有在@Route() 注释中指定控制器中的方法,那么它会显示所有方法,但如果您添加 methods={} 到 Route 注释然后它只会列出定义的方法
* @Route("/api/users", name="get_users", methods={"GET"})
指定 @Value 和 @method 输入 @RequestMapping
@RequestMapping(value="/instances/all",method=RequestMethod.GET)
@JsonFormat
public String showInstances(){
return "instances";
}