在doc api平台中隐藏路线 [英] Hide a route in the doc api platform

查看:63
本文介绍了在doc api平台中隐藏路线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Symfony4下使用API​​平台实现了一个API,我试图在文档中隐藏一个实体,该实体只能由打击的ROLE_ADMIN访问,而在文档中看不到任何兴趣.这是我要隐藏的实体:

I realize an API with API Platform under Symfony4 and I try to hide an entity in the doc which is accessible only to the ROLE_ADMIN of the blow no interest to be visible in the doc. Here is the entity I want to hide:

<?php

namespace App\Entity;

use ApiPlatform\Core\Annotation\ApiResource;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation\Groups;

/**
 * @ApiResource(
 *     attributes={"access_control"="is_granted('ROLE_ADMIN')"}
 * )
 * @ORM\Entity(repositoryClass="App\Repository\OrderStatusRepository")
 */
class OrderStatus
{
    /**
     * @ORM\Id()
     * @ORM\GeneratedValue()
     * @ORM\Column(type="integer")
     */
    private $id;

    /**
     * @ORM\Column(type="string", length=255)
     * @Groups("orderGET")
     */
    private $label;

    /**
     * @return int|null
     */
    public function getId(): ?int
    {
        return $this->id;
    }

    /**
     * @return null|string
     */
    public function getLabel(): ?string
    {
        return $this->label;
    }

    /**
     * @param string $label
     * @return OrderStatus
     */
    public function setLabel(string $label): self
    {
        $this->label = $label;

        return $this;
    }
}

谢谢您的帮助

推荐答案

开箱即用不支持此功能(但这将是一个不错的贡献).您可以做的是将 DocumentationNormalizer 装饰为 unset()您不想在OpenAPI文档中出现的路径.

This isn't supported out of the box (but it would be a nice contribution). What you can do is to decorate the DocumentationNormalizer to unset() the paths you don't want to appear in the OpenAPI documentation.

更多信息: https://api-platform.com/docs/core/swagger/#overriding-the-openapi-specification

这篇关于在doc api平台中隐藏路线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆