user1930591
user1930591

Reputation: 307

swagger-ui How do you hide rest methods not implemented

Maybe im just missing it, I would like to hide some rest methods from controllers that do not implement them like options , delete, head

Is there an annotation for this? I could not find it in the documentation using https://github.com/nelmio/NelmioApiDocBundle v3

currently when i view /api/doc any controllers I add list all rest methods even if I only have a GET method implemented.

enter image description here

<?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);

    }

}

Upvotes: 3

Views: 6646

Answers (2)

Ajay V
Ajay V

Reputation: 563

Specify @Value and @method type in the @RequestMapping

@RequestMapping(value="/instances/all",method=RequestMethod.GET)
@JsonFormat
public String showInstances(){
   return "instances";  
}

Upvotes: 2

user1930591
user1930591

Reputation: 307

Just figured it out if you do not specify the methods in the controller in the @Route() annotation then it will show all of them but if you add methods={} to the Route annotation then it will only list the defined methods

 * @Route("/api/users", name="get_users", methods={"GET"})

enter image description here

Upvotes: 2

Related Questions