symfony7给swagger字段添加描述信息:
use OpenApi\Attributes as OA;
class AffiliationDto implements ResponsibleInterface
{
#[OA\Property(description: "The unique identifier of the affiliation", example: 123)]
private int $id;
#[OA\Property(description: "The name of the affiliation", example: "hh")]
private string $department;
#[OA\Property(description: "The description of the affiliation", example: "gg")]
private string $institution;
}
再补充一下信息,在控制器下直接使用DTO自动生成
use OpenApi\Attributes as OA;
#[Route('/submissions/summary', name: 'submissions_summary', methods: ['GET'])]
#[OA\Get(
description: "返回事件的提交统计数据摘要",
summary: "获取提交统计摘要"
)]
#[OA\Response(
response: 200,
description: 'Return submissions summary',
content: new Model(type: Dto\Query\Submission\Statistic\SubmissionSummaryStatisticsDataDto::class)
)]
#[OA\Response(
response: 404,
description: 'Event not found'
)]
public function getSubmissionSummary(
Sciforum\Event $event,
Statistic\SubmissionSessionDistributionService $submissionSessionDistributionService,
): JsonResponse {
return $this->apiResponse->response($submissionSessionDistributionService->getSubmissionSummary($event));
}
可以通过 OA\Get 对这个Get方法进行说明,通过 OA\Response 定义多个 response code 下的信息
