0

Is it possible to consolidate these two annotations so that I write it in single place?

use Swagger\Annotations as SWG;
use FOS\RestBundle\Controller\Annotations\RequestParam;

/**
 * @SWG\Parameter(
 *     name="user_id",
 *     in="query",
 *     type="string",
 *     description="User Id"
 * )
 * @RequestParam(name="user_id", requirements="\d+", description="User Id")
 */
Roman Newaza
  • 11,405
  • 11
  • 58
  • 89
  • you could write your own custom annotation which will serve the consolidated annotation, a good example how to build it could be e.g. https://www.sitepoint.com/your-own-custom-annotations/ – LBA Mar 01 '18 at 15:17

1 Answers1

0

I'm afraid there's no easy way.

Annotations are read through Doctrine AnnotationReader, which uses directly PHP ReflectionMethod (or alike).

As far I know, there's no way to alter a class/method/property reflection. There only way I see would be to rewrite AnnotationReader to handle some "grouped" annotation definitions, but it sounds like a lot of work.

romaricdrigon
  • 1,497
  • 12
  • 16
  • another way would be to create a custom annotation – LBA Mar 01 '18 at 15:14
  • The issue with creating your own annotation is how to inject the correct configuration into both Swagger and FOS Rest bundle. The FOS Rest bundle directly reads annotation (cf. https://github.com/FriendsOfSymfony/FOSRestBundle/blob/master/Request/ParamReader.php#L41), there's no "intermediate" configuration object you could manipulate. – romaricdrigon Mar 02 '18 at 09:10
  • @Roman Newaza, I realized [Nelmio Api Doc bundle](https://symfony.com/doc/master/bundles/NelmioApiDocBundle/index.html) can read query parameters requirements from FOS Rest bundle annotations. That may help your use case. – romaricdrigon Mar 02 '18 at 09:11