【问题标题】:Swagger ui endpoints are duplicatedSwagger ui 端点重复
【发布时间】:2018-03-06 08:50:58
【问题描述】:

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

现在,我想配置文档,因为端点显示重复。例如,我在两个实体之间有 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;

【问题讨论】:

    标签: swagger symfony4 api-platform.com


    【解决方案1】:

    你可以禁用一些“操作”:

    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
    {
        // ...
    }
    

    隐藏/显示你想要的。

    【讨论】:

    • 是的,我做到了,但没有成功。我需要在一个端点上显示操作。我的意思是,应该启用该操作,但我不想在文档中显示两次。只是要有一个清晰的API。
    • 请问您可以复制/粘贴您的注释吗?
    猜你喜欢
    • 2020-04-25
    • 2021-03-05
    • 2021-08-15
    • 1970-01-01
    • 1970-01-01
    • 2019-05-18
    • 2014-11-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多