約束的此注釋有效:
use App\Api\Dto\DtoInterface;
use Nelmio\ApiDocBundle\Annotation\Model;
use OpenApi\Annotations as OA;
use Symfony\Component\Serializer\Annotation\Groups as SerializerGroups;
use Symfony\Component\Validator\Constraints as Assert;
class Report implements DtoInterface
{
/**
* @OA\Property(description="visited house id SAP format 4 character string", type="string")
*
* @SerializerGroups({"create", "update", "view", "collection"})
*
* @Assert\NotBlank
* @Assert\Length(4)
*/
public string $house = '';
而這并沒有
use App\Api\Dto\DtoInterface;
use Nelmio\ApiDocBundle\Annotation\Model;
use OpenApi\Annotations as OA;
use Symfony\Component\Serializer\Annotation\Groups as SerializerGroups;
use Symfony\Component\Validator\Constraints as Assert;
class Report implements DtoInterface
{
/**
* @OA\Property(description="visited house id SAP format 4 character string", type="string")
*
* @SerializerGroups({"create", "update", "view", "collection"})
*
* @Assert\NotBlank(groups={"create", "update"})
* @Assert\Length(min=4, groups={"create", "update"})
*/
public string $house = '';
幸運的是,在這種情況下,忽略組對我來說仍然有效,但在其他情況下可能不會。
Symfony 檔案說它應該是這樣作業的。
我的第二個例子有什么問題?為什么這些驗證器會被忽略?
uj5u.com熱心網友回復:
請注意,在第二個檢測中,@Assert\NotBlank(groups={"create", "update"})在驗證器中檢測到滅菌組,與第一個示例相反,這意味著它們僅呈現給給定的組,而所有其他未指定負載的請求都將被忽略。
換句話說,第二個示例中的限制僅適用于createand update,對于viewandcollection組,它們將被忽略,因為它們沒有在注釋中指定。
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/448598.html
上一篇:SonataAdminBundle和OneToOne的關系
下一篇:教義中的多對多關系
