NelmioApiDocBundle icon indicating copy to clipboard operation
NelmioApiDocBundle copied to clipboard

[RFC] [3.x] Allow `FosRestDescriber` to extract the serialization groups from `FOS\RestBundle\Controller\Annotations\View` annotation

Open phansys opened this issue 4 years ago • 0 comments

The @View annotation from FOSRestBundle allows to define the serialization groups in its serializerGroups attribute. It controls how the returned response will be serialized based on the configured groups. This proposal is to leverage that definition for the API documentation, in order to avoid writing twice the same groups in the groups attribute at Nelmio\ApiDocBundle\Annotation\Model.

Before:

use FOS\RestBundle\Controller\Annotations\View;
use Nelmio\ApiDocBundle\Annotation\Model;
use Nelmio\ApiDocBundle\Annotation\Operation;
use Swagger\Annotations as SWG;

/**
 * @View(
 *     serializerGroups={"internal"}
 * )
 *
 * @Operation(
 *     @SWG\Response(
 *         response="200",
 *         @SWG\Schema(ref=@Model(type=MyModel::class, groups={"internal"}))
 *     )
 * )
 */

After:

use FOS\RestBundle\Controller\Annotations\View;
use Nelmio\ApiDocBundle\Annotation\Model;
use Nelmio\ApiDocBundle\Annotation\Operation;
use Swagger\Annotations as SWG;

/**
 * @View(
 *     serializerGroups={"internal"}
 * )
 *
 * @Operation(
 *     @SWG\Response(
 *         response="200",
 *         @SWG\Schema(ref=@Model(type=MyModel::class))
 *     )
 * )
 */

phansys avatar Sep 28 '21 14:09 phansys