Add proper length constraint validations to all string mapped ORM fields, so they show a nice validation error, instead of a 500 error

Fixes issue #544
This commit is contained in:
Jan Böhmer 2024-03-06 19:46:11 +01:00
parent 113e5b3bcd
commit dc7c13479c
17 changed files with 43 additions and 0 deletions

View file

@ -36,6 +36,7 @@ use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Validator\Constraints\Length;
use Symfony\Component\Validator\Constraints\NotBlank;
#[ORM\Entity(repositoryClass: ApiTokenRepository::class)]
@ -64,6 +65,7 @@ class ApiToken implements TimeStampableInterface
protected int $id;
#[ORM\Column(type: Types::STRING)]
#[Length(max: 255)]
#[NotBlank]
#[Groups('token:read')]
protected string $name = '';