Search code examples
apisymfonyfosrestbundle

Symfony fosrestbundle optional parameter in route


I have an api rest and i try to give an optional paramter in my route like this :

/**
 * @Rest\View
 * @Rest\Get("/dossier/{idDossier}", requirements={"idDossier" = "\d+"}, defaults={"idDossier" = null})
 * @ApiDoc(
 *  description="...",
 *  parameters={
 *      {"name"="idDossier", "dataType"="integer", "required"=false, "description"="Folder Id"}
 *  }
 * )
 */

public function getDossierAction($idDossier = null, Request $request){

But i have an error :

[Semantical Error] The annotation "@Rest\View" in method ...\Controller\DossierAPIController::getDossierAction() was never imported. Did you maybe forget to add a "use" statement for this annotation?

Solution

  • Your are not importing that annotation class. Put something like this after the namespace declaration:

    use FOS\RestBundle\Controller\Annotations as Rest;
    

    so you can use it like what you have:

    @Rest\View()