Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to tell Symfony 3 to ignore certain annotations?

I'm developing an API with Symfony 3 and I want to use apidoc to create a documentation. Apidoc works with annotations:

/**
 * @api {get} /user/:id Request User information
 * @apiName GetUser
 * @apiGroup User
 *
 * @apiParam {Number} id Users unique ID.
 *
 * @apiSuccess {String} firstname Firstname of the User.
 * @apiSuccess {String} lastname  Lastname of the User.
 */

But Symfony throws an annotation exception:

[Semantical Error] The annotation "@apiName" in method AppBundle\Controller\API\ApiLoginController::loginAction() was never imported. Did you maybe forget to add a "use" statement for this annotation?

500 Internal Server Error - AnnotationException

Is there any way to tell symfony to ignore those annotations? Thanks in advance.

like image 571
DandyCC Avatar asked Jan 05 '17 23:01

DandyCC


2 Answers

There is also a way to ignore an annotation globally. We didn't want to annotate each class, so we added this to our bootstrap file web/app.php.

Doctrine\Common\Annotations\AnnotationReader::addGlobalIgnoredName('your-custom-annotation');
like image 133
winkbrace Avatar answered Sep 20 '22 13:09

winkbrace


There's an @IgnoreAnnotation Doctrine annotation you can use. Try this:

/**
 * @IgnoreAnnotation("api")
 * @IgnoreAnnotation("apiName")
 * @IgnoreAnnotation("apiGroup")
 * @IgnoreAnnotation("apiParam")
 * @IgnoreAnnotation("apiSuccess")
 */
class SomeController extends Controller{
...
    /**
     * @api {get} /user/:id Request User information
     * @apiName GetUser
     * @apiGroup User
     *
     * @apiParam {Number} id Users unique ID.
     *
     * @apiSuccess {String} firstname Firstname of the User.
     * @apiSuccess {String} lastname  Lastname of the User.
     */

The documentation is further down in that link.

like image 36
Alvin Bunk Avatar answered Sep 20 '22 13:09

Alvin Bunk