I'm using symfony 5.4 with php 8.1 and I would like to factor a set of attributes used for Swagger documentation, before each controllers method, I have, at least, these 5 attributes:
#[OA\Response(
response: 400,
description: 'Bad parameters',
content: new OA\JsonContent(example: ['code' => 400, 'message' => 'Bad Request', 'appCode' => 5000])
)]
#[OA\Response(
response: 401,
description: 'JWT Token not found (appCode = 5001) or expired (appCode = 5002)',
content: new OA\JsonContent(example: ['code' => 401, 'message' => 'JWT Token not found', 'appCode' => 5001])
)]
#[OA\Response(
response: 403,
description: 'Insufficient privileges',
content: new OA\JsonContent(example: ['code' => 403, 'message' => 'Forbidden', 'appCode' => 5003])
)]
#[Security(name: 'Bearer')]
#[OA\Tag(name: 'User')]
It takes up a lot of space and is duplicated, so I would like to create an attribute that I could use as :
#[SwaggerUtils(tag: 'User')]
which will do the same job as writing the previous 5 attributes, like the decorator composition in Nestjs (https://docs.nestjs.com/custom-decorators#decorator-composition).
Is it possible in PHP?
The best post I've found on PHP attributes is https://www.amitmerchant.com/how-to-use-php-80-attributes/. But I have no clue how I can achieve what I want.