我正在使用精彩的项目api 平台。我创建了我的实体,端点就像一个魅力一样工作。
现在,我想配置文档,因为端点显示重复。例如,我在两个实体之间有 1 到 N 的关系,并且在通过 swagger 自动生成的文档中,端点是重复的。
例如,在比赛和事件之间的这种关系中,我对每个实体都有相同的端点[/competitions/{id}/events]。
您知道是否有任何方法可以显示一次端点?这没什么大不了的,但我想保持文档尽可能干净。
已编辑
竞赛:
/**
* Competitions able to request.
*
* @ApiResource(
* attributes={
* "normalization_context"={"groups"={"read"}}
* },
* collectionOperations={"get", "post"},
* itemOperations={"get"}
* )
* @ORM\Entity
*/
class Competition
{
/**
* @var int The competition Id
*
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
* @Groups({"read","write"})
*/
private $id;
/**
* @var string Name of the competition
*
* @ORM\Column
* @Assert\NotBlank
* @Groups({"read","write"})
*
*/
public $name = '';
/**
* @ORM\OneToMany(targetEntity="Event", mappedBy="competitions", cascade={"persist"})
* @ApiSubresource(maxDepth=1)
* @Groups("write")
*/
public $events;
事件:
/**
* Available event
*
* @ApiResource(
* attributes={
* "normalization_context"={"groups"={"read"}},
* "denormalization_context"={"groups"={"write"}}
* },
* collectionOperations={"get", "post"},
* itemOperations={
* "get"}
* )
* @ORM\Entity
*/
class Event
{
/**
* @var int The entity Id
*
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
* @Groups({"read", "write"})
*/
private $id;
/**
* @var string The name of the event available.
*
* @ORM\Column(type="text")
* @Assert\NotBlank
* @Groups({"read","write"})
*/
public $name = '';
/**
* @var string Start date
*
* @ORM\Column(type="datetime")
* @Assert\NotBlank
* @Groups({"read","write"})
*/
public $start;
/**
* @ORM\ManyToOne(targetEntity="Competition", inversedBy="events")
* @Groups({"write"})
*/
public $competitions;