Swagger ui端点是重复的

时间:2018-03-06 08:50:59

标签: swagger symfony4 api-platform.com

我正在使用精彩项目api platform。我创建我的实体和端点工作就像一个魅力。

现在,我想配置文档,因为端点显示重复。例如,我在两个实体之间存在1到N的关系,并且在通过swagger自动生成的文档中,端点是重复的。

例如,在竞争和事件之间的这种关系中,我为每个实体都有相同的端点 [/ competitions / {id} / events]

Duplicated endpoints.

您知道有没有办法一次显示端点?这不是什么大问题,但我希望尽可能保持文档的清洁。

被修改

竞争:

/**
 * 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;

1 个答案:

答案 0 :(得分:0)

您可以禁用某些“操作”:

https://api-platform.com/docs/core/operations

<?php
// api/src/Entity/Book.php

use ApiPlatform\Core\Annotation\ApiResource;

/**
 * ...
 * @ApiResource(
 *     collectionOperations={"get"},
 *     itemOperations={"get"}
 *     )
 */
class Book
{
    // ...
}

隐藏/显示你想要的东西。